tags:

views:

222

answers:

1

Im trying to run a model with a response variable p and 3 fixed factors to get ANOVA. this is how my code looks like :

#run it as 3 fixed factor model 
p1=c(37,38,37,41,41,40,41,42,41)
p2=c(42,41,43,42,42,42,43,42,43)
p3=c(30,31,31,31,31,31,29,30,28)
p4=c(42,43,42,43,43,43,42,42,42)
p5=c(28,30,29,29,30,29,31,29,29)
p6=c(42,42,43,45,45,45,44,46,45)
p7=c(25,26,27,28,28,30,29,27,27)
p8=c(40,40,40,43,42,42,43,43,41)
p9=c(37,38,37,41,41,40,41,42,41)
p10=c(35,34,34,35,35,34,35,34,35)
p = cbind(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10)
partnumber=c(rep(1,9),rep(2,9),rep(3,9),rep(4,9),rep(5,9),rep(6,9),rep(7,9),rep(8,9),rep(9,9),rep(10,9))
test=c(rep(c(rep(1:3,3)),10))
inspector = rep(c(rep(1,3),rep(2,3),rep(3,3)),10)
fpartnumber = factor(partnumber)
ftest = factor(test)
finspector = factor(inspector)
model=lm(p~fpartnumber*ftest*finspector)
summary(model)
anova(model)

but when I run it I get this error : it says my variable length for fpartnumber is different , but when I checked the length of each variable and is 90. What is going on ?

model=lm(y~fpartnumber*ftest*finspector) Error in model.frame.default(formula = yang ~ fpartnumber * ftest * finspector, : variable lengths differ (found for 'fpartnumber')

+1  A: 

My guess is that you don't want to cbind p1...p10.

Have a look at

data.frame(p, fpartnumber, ftest, finspector)

and

str(p)

Using p = c(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) instead gives the results that (I think) you are looking for (although with a warning).

Kevin
Yea thanks Kevin , I fixed that but now I getting a warning when I check summary(model)> summary(model)Call:lm(formula = yang ~ fpartnumber * ftest * finspector)Residuals:ALL 90 residuals are 0: no residual degrees of freedom!and this when I type anova(model) Warning message: In anova.lm(model) : ANOVA F-tests on an essentially perfect fit are unreliable
TKBell
You get those warnings because the model does provide a "perfect" fit: you have so many parameters that each value is fitted perfectly. You need some replication within part/test/inspector triples, or remove some of the interaction terms (e.g. fit `p~(fpartnumber + ftest + finspector)^2` will treat the 3-way interaction as the error term.
Aniko