为什么我的因素不会成功?

时间:2017-11-06 17:46:49

标签: r nested anova

我正在尝试在R中运行嵌套的ANOVA,但是R保持返回的结果比我的模型应该具有更多的df。似乎没有像我指定的那样嵌套我的因素。

我的模特是:

 mod1<-(lm(response ~ factor3/factor2/factor1, data=data))

其中factor3嵌套在factor2中,factor2嵌套在factor1中。我也尝试过:

mod2<- (lm(response ~ factor1/factor2/factor3, data=data))

可重复的例子:

dput(data)
structure(list(factor2 = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 
23L, 24L, 25L, 26L, 27L, 28L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 
22L, 23L, 24L, 25L, 26L, 27L, 28L, 1L, 2L, 3L, 4L, 5L, 6L, 8L, 
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 
23L, 24L, 25L, 25L, 26L, 27L, 28L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 
21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L), factor3 = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label =     c("flower", 
"leaf", "pollen", "stem"), class = "factor"), factor1 = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,      
3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label =     c("BDY", 
"ELK", "FOO", "GTH"), class = "factor"), response = c(6681.23, 
14244.08, 12968.21, 12010.11, 23068.28, 9814.8, 7330.3, 8668.38, 
11268.32, 15847.31, 14477.16, 11777.99, 18114.18, 7243.96, 15818.11, 
14688.62, 16494.26, 20607.73, 12091.07, 16520.8, 23774.68, 18982.81, 
28254.47, 22195.51, 15789.27, 18935.79, 25432.66, 26710.84, 8251.26, 
21494.77, 4156.25, 9034.05, 14997.58, 9326.1, 7107.22, 7242.1, 
5918.55, 13406.13, 10943.45, 14467.25, 5537.86, 3633.19, 15885.53, 
15347.71, 17762.4, 19459.68, 11572.8, 12734.17, 14007.17, 12903.34, 
20022.23, 22562.52, 24866.6, 17669.95, 23224.24, 24176.56, 504.47, 
1091, 5536.14, 2013.21, 4784.39, 3467.77, 1891.02, 3648.9, 1781.21, 
1738.36, 1136, 999.91, 8317.76, 1316.81, 2247.32, 11255.5, 3226.06, 
2934.25, 1431.31, 5799.91, 1977.36, 2284.3, 1358.63, 275.32, 
1676.3, 1367.51, 1642.89, 3845.59, 13514.46, 8301.19, 11401.89, 
12266.25, 5522.93, 6129.18, 5214.82, 3267.63, 6775.97, 7890.34, 
5551.34, 2895.41, 4856.73, 6811.57, 8068.19, 6628.74, 5960.92, 
7924.07, 5158.48, 4689.99, 9125.87, 9459.41, 12376.81, 9544.07, 
9357.06, 12328.59, 21184.79)), .Names = c("factor2", "factor3", 
"factor1", "response"), class = "data.frame", row.names = c(NA, 
-111L))

如您所见,只有28个重复,从中进行了4次测量。但是,当我跑:

mod1<-(lm(response ~ factor1/factor2/factor3, data=data))
anova(mod1)   

> anova(mod1)
Analysis of Variance Table

Response: response
                        Df     Sum Sq   Mean Sq F value    Pr(>F)    
factor1                  3  724275464 241425155 16.2257 1.577e-08 ***
factor1:factor2          4   24834710   6208678  0.4173    0.7958    
factor1:factor2:factor3 12 3434955912 286246326 19.2381 < 2.2e-16 ***
Residuals               91 1354003526  14879160                      
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

mod2<-(lm(response ~ factor3/factor2/factor1, data=data))
anova(mod2)

> anova(mod2)
Analysis of Variance Table

Response: response
                        Df     Sum Sq   Mean Sq F value    Pr(>F)    
factor3                  3 2938598064 979532688 71.5319 < 2.2e-16 ***
factor3:factor2          4  926343993 231585998 16.9119  2.12e-10 ***
factor3:factor2:factor1 12  427005751  35583813  2.5986  0.005113 ** 
Residuals               91 1246121804  13693646                      
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

我得到91残余df。

我的问题是:我的数据组织和/或我的模型规范有什么问题,我该如何修复它/它?

0 个答案:

没有答案