R:在 anova.lm(g) 中:对基本完美拟合的 ANOVA F 检验是不可靠的 [英] R: In anova.lm(g) : ANOVA F-tests on an essentially perfect fit are unreliable
问题描述
我正在将在线指南与旧文本配对以学习 R(第 182 页 - http://cran.r-project.org/doc/contrib/Faraway-PRA.pdf).当我使用 R 包中的数据时(如教程示例中所示),没有问题.但是,当我使用文本中的数据时,我总是以没有 F 值和警告结束.
I am pairing up online guides with an old text to learn R (page 182 - http://cran.r-project.org/doc/contrib/Faraway-PRA.pdf). When I use data from a package from R (as in the tutorial examples) there is no problem. However, when I use data from my text, I always end with no F-value and the warning.
看看:
将数据转换为 data.frame:
data into a data.frame:
car.noise <- data.frame( speed = c("idle", "0-60mph", "over 60"), chrysler = c(41,65,76),
bmw = c(45,67,72), ford = c(44,66,76), chevy = c(45,66,77), subaru = c(46,76,64))
检查数据框:
car.noise
speed chrysler bmw ford chevy subaru
1 idle 41 45 44 45 46
2 0-60mph 65 67 66 66 76
3 over 60 76 72 76 77 64
熔化数据框:
mcar.noise<- melt(car.noise, id.var="speed")
检查融化的data.frame
check melted data.frame
> mcar.noise
speed variable value
1 idle chrysler 41
2 0-60mph chrysler 65
3 over 60 chrysler 76
4 idle bmw 45
5 0-60mph bmw 67
6 over 60 bmw 72
7 idle ford 44
8 0-60mph ford 66
9 over 60 ford 76
10 idle chevy 45
11 0-60mph chevy 66
12 over 60 chevy 77
13 idle subaru 46
14 0-60mph subaru 76
15 over 60 subaru 64
执行方差分析并得到警告:
perform anova and get warning:
> anova(lm(value ~ variable * speed, mcar.noise))
Analysis of Variance Table
Response: value
Df Sum Sq Mean Sq F value Pr(>F)
variable 4 6.93 1.73
speed 2 2368.13 1184.07
variable:speed 8 205.87 25.73
Residuals 0 0.00
Warning message:
In anova.lm(lm(value ~ variable * speed, mcar.noise)) :
ANOVA F-tests on an essentially perfect fit are unreliable
我能想到的唯一两种解释:
The only 2 explanations I can come up with:
1:我编码不正确2:文本示例太完美"了,因为它们试图显示清晰的示例
1: I am coding incorrectly 2: Text examples are too 'perfect' of a fit since they are trying to show clear example
推荐答案
您正在尝试拟合一个模型,该模型为每个可变*速度组合提供单独的均值.有了您拥有的数据,这意味着您根本没有任何复制.当每个组中只有一个值时,这就像尝试比较两个组一样.
You are trying to fit a model that gives a separate mean to every combination of variable*speed. With the data you have that means you don't have any replication at all. It would be like trying to compare two groups when you only have a single value from each group.
如果您查看方差分析表中的残差"行,您应该注意到那里没有任何自由度,并且平方和也为 0.如果您认为合适,但您没有足够的数据来拟合具有交互作用的模型,您可以尝试在没有交互的情况下拟合模型.
If you look at the line for "Residuals" in your anova table you should notice that you don't have any degrees of freedom there and your sums of squares are 0 as well. You could try to fit a model without an interaction if you feel it is appropriate but you don't have enough data to fit a model with an interaction.
这篇关于R:在 anova.lm(g) 中:对基本完美拟合的 ANOVA F 检验是不可靠的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!