【问题标题】:Restriction method for producing ANOVA - set-to-zero vs. sum-to-zero产生方差分析的限制方法 - 设置为零与总和为零
【发布时间】:2021-04-20 19:20:35
【问题描述】:

所以我有一个关于该方法用于获得正规方程解的限制类型的问题。我想知道设置为零和和为零的限制如何从 anova 和 lsmeans 以及标准误差中产生相同的平方和、均方和 F 值。下面的示例显示了我如何更改限制。谁能解释为什么会出现这种等效性以及为什么它很重要?

library(car); library(emmeans); library(multcomp);
y <- c(20,25,26,22,25,25,26,27,22,31)
Y <- matrix(y, nrow = 10)
t <- factor(c(rep(1,6), rep(2,4)))
b <- factor(c(1,2,2,3,3,3,1,1,2,3))
Trt <- interaction(t,b)
data <- data.frame(Y, t, b, Trt)

options(contrasts=c("contr.sum", "contr.poly"))
fit.sum <- lm(Y ~ t + b + t*b, data = data)
summary(fit.sum)

options(contrasts=c("contr.treatment", "contr.poly"))
fit.set <- lm(Y ~ t + b + t*b, data = data)
summary(fit.set)

#produced statement from both#

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   20.000      1.323  15.119 0.000112 ***
t2             6.500      1.620   4.012 0.015972 *  
b2             5.500      1.620   3.395 0.027412 *  
b3             4.000      1.528   2.619 0.058885 .  
t2:b2        -10.000      2.291  -4.364 0.012021 *  
t2:b3          0.500      2.227   0.225 0.833338    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.323 on 4 degrees of freedom
Multiple R-squared:  0.9176,    Adjusted R-squared:  0.8145 
F-statistic: 8.903 on 5 and 4 DF,  p-value: 0.0273


Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  24.8333     0.4590  54.107 6.98e-07 ***
t1           -1.6667     0.4590  -3.631  0.02213 *  
b1           -1.5833     0.6553  -2.416  0.07306 .  
b2           -1.0833     0.6553  -1.653  0.17363    
t1:b1        -1.5833     0.6553  -2.416  0.07306 .  
t1:b2         3.4167     0.6553   5.214  0.00645 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.323 on 4 degrees of freedom
Multiple R-squared:  0.9176,    Adjusted R-squared:  0.8145 
F-statistic: 8.903 on 5 and 4 DF,  p-value: 0.02733

【问题讨论】:

    标签: r statistics lm anova restriction


    【解决方案1】:

    对于总和和设置为零的对比度,下面的每一行都是相同的,因为在每种情况下,它们都是 Y 在与右侧关联的模型矩阵的列所跨越的空间上的投影。两组对比只是改变了坐标,并没有改变跨越的空间。

    fit1 <- fitted(lm(Y ~ 1, data))
    fit2 <- fitted(lm(Y ~ t, data))
    fit3 <- fitted(lm(Y ~ t + b, data))
    fit4 <- fitted(lm(Y ~ t + b + t*b, data))
    

    现在平方和仅取决于上述拟合值。例如 b 的平方和是

    crossprod(fit3 - fit2)
    

    因此平方和不能不同。

    此外,空间的尺寸不受对比度的影响,因此均方也必须相同,因为均方只是平方和除以所跨越的空间的尺寸。

    F 比仅取决于上述数量,因此也不可能不同。

    【讨论】:

      【解决方案2】:

      考虑这一点的一种简单方法是,无论使用何种参数化,拟合值都是相同的。并且平方和可以用拟合值来表示。

      关于估计的边际均值 (lsmeans),它们可能因参数化不同而不同。但是,emmeans 包会执行可估计性检查(至少对于大多数模型而言),并且不会显示不可唯一估计的 emmeans。 (并且,为了将这些想法联系在一起,唯一可估计参数被精确定义为可以根据拟合值表达的参数。)

      【讨论】:

        猜你喜欢
        • 2021-11-12
        • 1970-01-01
        • 2014-09-02
        • 1970-01-01
        • 2022-06-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多