我有一个数据集,如下所示
Id age memory_score
1 young 71.11172
2 old 67.65542
3 young 65.34716
4 young 81.21345
5 old 80.72106
6 old 73.01981
I want to do an independent T-test to test the hypothesis that younger people have a higher memory score than middle-aged or older people.这是我尝试过的代码,但不幸的是,它给出了一个错误:分组因子必须恰好有2个级别。我想知道我如何解决这个问题。
t.test(PU6_exercise_data1$age ~ PU6_exercise_data1$memory_score, var.equal = TRUE)发布于 2021-11-16 14:06:37
这可以通过更改公式的顺序来解决。
下面是一些重新创建数据的代码。
id <- 1:6
age <- c("young", "old", "young", "young", "old", "old")
memory_score <- c(71.11172, 67.65542, 65.34716, 81.21345, 80.72106, 73.0198)
df <- data.frame(id = id, age = age, memory_score = memory_score)然后,我们可以执行t-test:
t.test(df$memory_score ~ df$age, var.equal = TRUE)您可以在t.test文档中的公式接口示例中看到这一点。
https://stackoverflow.com/questions/69990349
复制相似问题