【最新】R语言ANOVA 课件教案讲义(附代码数据)

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

To compare two models using the F-test(Theorem4),we can use the anova command (not to be confused on the ANOVA test)

>mylm2<-lm(Carbohydrate~Age,data=dat)

>anova(mylm2,mylm1)

Analysis of Variance Table

Model1:Carbohydrate~Age

Model2:Carbohydrate~Age+Weight+Protein

Res.Df RSS Df Sum of Sq F Pr(>F)

1181088.98

216567.662521.327.34690.005452**

---

Signif.codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1

Double-check the F-statistic agrees

>RSS0<-sum(mylm2$residuals^2)

>F<-((RSS0-RSS)*16)/(RSS*2)

>F

[,1]

[1,]7.346886

and also check the corresponding p-values

>pf(F,df1=2,df2=16,lower.tail=FALSE)

[,1]

[1,]0.005452024

Conclusion:Since the corresponding p-values is less than0.01we make the following conclusion:There is sufficient evidence to reject the null hypothesis at the1%level (corresponding to the smaller model),and therefore accept the alternative.This means we should proceed to use the larger model.

35

相关文档
最新文档