开发者

ANOVA with 3 fixed factors in R

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 :

开发者_如何学Python
#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~fpartnumberftestfinspector) Error in model.frame.default(formula = yang ~ fpartnumber * ftest * finspector, : variable lengths differ (found for 'fpartnumber')


If you don't want to cbind p1...p10.

Then try:

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

and:

str(p)

Using:

p = c(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) 

instead

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜