我有两个变量:decsorgs2
和regionfactor
(这是一个因素“区域”)
freq(decsorgs2)
decsorgs2
Frequency Percent
0 Disagree 365 53.76
1 Agree 314 46.24
Total 679 100.00
freq(regionfactor)
regionfactor
Frequency Percent
1 12 1.767
2 82 12.077
3 128 18.851
4 64 9.426
5 138 20.324
6 43 6.333
7 53 7.806
8 57 8.395
9 102 15.022
Total 679 100.000
我正在尝试用aov()
做一个anova。
aov(decsorgs2~regionfactor)
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
NA/NaN/Inf in 'y'
In addition: Warning message:
In model.response(mf, "numeric") : NAs introduced by coercion
这些错误是什么?我不明白这些术语
编辑:好的,我做了一次冰雹随机尝试并重新编码了decsorgs2。
最初我有:
decsorgs2 = recode(DECSORGS,“4:5 ='0不同意'; 1:2 ='1同意'”)
现在我用过:
decsorgs2 = recode(DECSORGS,“4:5 = 0; 1:2 = 1”)
似乎有效。但为什么?为什么decsorgs2
必须是数字,如果将变量区域分解的目的是使其被视为分类?我怎么知道哪一个必须是数字和哪个分类?
答案 0 :(得分:1)
aov
需要一个连续的响应变量。您正在传递character
变量,并且它被强制转换为numeric
:
y <- c("0 Disagree", "1 Agree")
as.numeric(y)
#[1] NA NA
#Warning message:
#NAs introduced by coercion
y <- c("0", "1")
as.numeric(y)
#[1] 0 1
您需要重新考虑统计方法。