R car package - 为重复因子的2路anova提取残差

时间:2017-06-21 12:36:23

标签: r anova r-car

我正在使用汽车套件在R中重复测量双向anova。更具体地说,我使用Anova()功能(注意大写字母A)。这似乎工作正常,但我想测试残差是否正常。但是,我找不到从输出中提取残差和系数的方法。对于R中的正常线性模型,您可以使用残差(mod)或plot(mod),但这在此处不起作用。

非常感谢任何帮助!

创建数据的代码:

d=as.data.frame(t(matrix(c("AA","A",231,249,247,260,242,247,"BB","A",266,246,248,261,261,272,"CC","A",270,268,228,289,274,288,"DD","A",291,292,245,267,281,280,"AA","A",265,281,244,254,254,261,"BB","A",368,283,229,250,250,246,"CC","A",247,267,232,282,242,245,"DD","A",283,269,232,278,254,256,"AA","A",250,242,240,238,253,246,"BB","A",260,231,228,241,263,251,"CC","A",276,272,236,282,253,268,"DD","B",291,261,226,268,265,259,"AA","B",221,200,219,230,230,254,"BB","B",250,212,212,234,224,248,"CC","B",250,212,217,220,245,261,"DD","B",216,198,199,207,235,251,"AA","B",189,195,199,252,217,258,"BB","B",202,202,202,216,226,263,"CC","B",219,238,178,231,194,247,"DD","B",237,234,201,261,226,265,"AA","B",237,231,223,257,228,260,"BB","B",234,222,197,213,222,240,"CC","B",181,196,186,204,210,236,"DD","B",215,220,202,231,229,273),nrow = 8, ncol=24)));

colnames(d)<-c("Factor1", "Factor2", "a2011", "a2012",  "a2013", "a2014", "a2015",  "a2016");

d[,1]<-as.factor(d[,1]);
d[,2]<-as.factor(d[,2])

ANOVA的代码:

require(car);
options(contrasts=c('contr.sum','contr.poly'));
m=lm(cbind(a2011,a2012,a2013,a2014,a2015, a2016)~Factor1+Factor2,data=d);
niveauAnnee=factor(1:6);
niveauAnnee=as.factor(c("a2011","a2012", "a2013","a2014","a2015","a2016"));
idata=data.frame(niveauAnnee);
anov<-Anova(m,idata=idata,idesign=~niveauAnnee,type=3);
summary(anov);

0 个答案:

没有答案