本文介绍了如何从 R 中的重复测量方差分析模型中获取残差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常从 aov() 使用 summary() 函数可以得到残差.

Normally from aov() you can get residuals after using summary() function on it.

但是当我使用重复测量方差分析并且公式不同时,我如何获得残差?

But how can I get residuals when I use Repeated measures ANOVA and formula is different?

## as a test, not particularly sensible statistically
npk.aovE <- aov(yield ~  N*P*K + Error(block), npk)
npk.aovE
summary(npk.aovE)
Error: block
          Df Sum Sq Mean Sq F value Pr(>F)
N:P:K      1   37.0   37.00   0.483  0.525
Residuals  4  306.3   76.57

Error: Within
          Df Sum Sq Mean Sq F value  Pr(>F)
N          1 189.28  189.28  12.259 0.00437 **
P          1   8.40    8.40   0.544 0.47490
K          1  95.20   95.20   6.166 0.02880 *
N:P        1  21.28   21.28   1.378 0.26317
N:K        1  33.14   33.14   2.146 0.16865
P:K        1   0.48    0.48   0.031 0.86275
Residuals 12 185.29   15.44
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

直观的 summary(npk.aovE)$residuals 返回 NULL..任何人都可以帮我解决这个问题吗?

Intuitial summary(npk.aovE)$residuals return NULL..Can anyone can help me with this?

推荐答案

我很抱歉我读你的例子太快了.我的建议对于带有 aov() 的多级模型是不可能的.请尝试以下操作:

I apologize I read your example way too quickly. What I suggested is not possible with multilevel models with aov(). Try the following:

> npk.pr <- proj(npk.aovE)
> npk.pr[[3]][, "Residuals"]

这里有一个更简单的可重现方法,如果遇到相同的问题,任何人都可以解决:

Here's a simpler reproducible anyone can mess around with if they run into the same issue:

x1 <- gl(8, 4)
block <- gl(2, 16)
y <- as.numeric(x1) + rnorm(length(x1))
d <- data.frame(block, x1, y)

m <- aov(y ~ x1 + Error(block), d)
m.pr <- proj(m)
m.pr[[3]][, "Residuals"]

这篇关于如何从 R 中的重复测量方差分析模型中获取残差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-09 23:53