#creat chart
thickness<-matrix(c(14.037,14.165,13.972,13.907,14.821,14.757,14.843,14.878,13.880,13.860,14.032,13.914,14.888,14.921,14.415,14.932),byrow = T,ncol = 4)
dimnames(thickness)<- list(c("(1)","a","b","ab"),c("Rep1","Rep2","Rep3","Rep4"))
A<- rep(c(-1,1),2)
B<- c(rep(-1,2),rep(1,2))
AB <- A*B
Total<- apply(thickness,1,sum)
Average<- apply(thickness,1,mean)
Variance<- apply(thickness,1,var)
table<-cbind(A,B,AB,thickness,Total,Average,Variance)
table
#Effect estimate(1)
n<-4
Aeff <-(Total %*% A)/(2*n)
Aeff
Beff <-(Total %*% B)/(2*n)
Beff
ABeff <-(Total %*% AB)/(2*n)
ABeff
#Effect estimate(2)
n<-4
Aeff<-{sum(Total[A==+1])/(2*n)}-{sum(Total[A==-1])/(2*n)}
Aeff
Beff<-{sum(Total[B==+1])/(2*n)}-{sum(Total[B==-1])/(2*n)}
Beff
ABeff<-{sum(Total[AB==+1])/(2*n)}-{sum(Total[AB==-1])/(2*n)}
ABeff
#summary
thickness.vec<- c(t(thickness))
XA <- rep(as.factor(A),rep(2,4))
XB <- rep(as.factor(B),rep(2,4))
XAB <- rep(as.factor(AB),rep(2,4))
options(contrasts=c("contr.sum","contr.poly"))
thickness.lm<- lm(thickness.vec ~ XA+XB+XAB)
Error in model.frame.default(formula = thickness.vec ~ XA + XB + XAB, : variable lengths differ (found for 'XA')
It is factorial design in r.
I cannot get lm
to work because of different lengths of the regressors and response.
length(thickness.vec)
#[1] 16
length(XA)
#[1] 8
length(XB)
#[1] 8
length(XAB)
#[1] 8
I don't know how to fix it.
What should I do to solve this?