我的数据帧如下:
Df <- structure(list(SES = c("High", "High", "High", "Low", "High",
"Low", "High", "High", "High", "Low", "Low", "Low", "High", "High",
"Low", "High", "High", "Low", "High", "High", "Low", "High",
"Low", "Low", "Low", "Low", "High", "Low", "High", "Low", "High",
"High", "Low", "High", "Low", "High", "High", "High", "Low",
"High", "High", "Low", "Low", "High", "Low", "Low", "Low", "Low",
"High", "High", "Low", "High"), entry_age = c(12, 2.5, 7, 2.5,
2.5, 12, 9, 2.5, 3, 8, 12, 2.5, 5.5, 6, 2.5, 2.5, 2.5, 16, 12,
5, 7, 2.5, 12, 2.5, 2.5, 12, 12, 12, 6, 24, 2.5, 2.5, 2, 3.5,
2.5, 2.5, 2.5, 4, 7, 12, 7, 9, 12, 6, 18, 15, 8, 12, 2.5, 6,
10, 5)), row.names = c(NA, -52L), class = c("tbl_df", "tbl",
"data.frame"))
我在均值上有一个很好的差异,我想用t检验检验它的显著性,使用t.test函数,如下所示:
t.test(Df$SES, Df$entry_age)
非常简单,一点也不复杂。然而,我得到的是以下错误代码,我不理解:
Error in if (stderr < 10 * .Machine$double.eps * max(abs(mx), abs(my))) stop("data are essentially constant") :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In mean.default(x) :
l'argument n'est ni numérique, ni logique : renvoi de NA
2: In var(x) : NAs introduced by coercion
我做了NA测试,没有。
你能帮我吗?对于这个低级别的问题,我很抱歉,但我在谷歌上没有找到这个错误信息的含义。
你将得到我无尽的感激
看help('t.test')
了解用法;您调用它的方式是,它期望测试组x=Df$SE(这不是您想要的)和y=Df$entry_age之间的值。然后试试这个:
Df <- structure(list(SES = c("High", "High", "High", "Low", "High",
"Low", "High", "High", "High", "Low", "Low", "Low", "High", "High",
"Low", "High", "High", "Low", "High", "High", "Low", "High",
"Low", "Low", "Low", "Low", "High", "Low", "High", "Low", "High",
"High", "Low", "High", "Low", "High", "High", "High", "Low",
"High", "High", "Low", "Low", "High", "Low", "Low", "Low", "Low",
"High", "High", "Low", "High"), entry_age = c(12, 2.5, 7, 2.5,
2.5, 12, 9, 2.5, 3, 8, 12, 2.5, 5.5, 6, 2.5, 2.5, 2.5, 16, 12,
5, 7, 2.5, 12, 2.5, 2.5, 12, 12, 12, 6, 24, 2.5, 2.5, 2, 3.5,
2.5, 2.5, 2.5, 4, 7, 12, 7, 9, 12, 6, 18, 15, 8, 12, 2.5, 6,
10, 5)), row.names = c(NA, -52L), class = c("tbl_df", "tbl",
"data.frame"))
t.test(entry_age~SES, data=Df)
#>
#> Welch Two Sample t-test
#>
#> data: entry_age by SES
#> t = -2.9888, df = 35.479, p-value = 0.005059
#> alternative hypothesis: true difference in means between group High and group Low is not equal to 0
#> 95 percent confidence interval:
#> -6.695627 -1.280563
#> sample estimates:
#> mean in group High mean in group Low
#> 5.303571 9.291667
在2022-05-17由reprex包(v2.0.1)创建