方差分析 (rstatix) 中 'mutate()' 输入 'data' 的问题
Problem with 'mutate()' input 'data' in ANOVA (rstatix)
这让我发疯。我正在使用 rstatix 的 anova_test,它告诉我我的列不存在,而它们显然存在。
这是我的数据框的样子:
ID = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3)
Form = c("A", "A", "A", "B", "B", "B", "A", "A", "A", "B", "B", "B", "A", "A", "A", "B", "B", "B")
Pen = c("Red", "Blue", "Green", "Red", "Blue", "Green", "Red", "Blue", "Green","Red", "Blue", "Green","Red", "Blue", "Green","Red", "Blue", "Green")
Time = c(20, 4, 6, 2, 76, 3, 86, 35, 74, 94, 14, 35, 63, 12, 15, 73, 87, 33)
df <- data.frame(ID, Form, Pen, Time)
ID, Form, Pen 是因素,Time 是数字。所以每个受试者用红色、蓝色和绿色的笔完成表格 A 和 B,我测量了每个人完成表格所用的时间。
这是我特意想出的一个假数据集来问这个问题。实际上,这个数据框是从一个更大的数据集派生出来的,这个数据集有更多的变量。每个变量都有更多的观察结果(因此不仅仅是主题 1 和表格 A 和红笔的一个数据点,如本例所示,而是多个),所以我总结了平均时间。
df <- original.df %>% dplyr::select(ID, Form, Pen, Time)
df <- df %>% dplyr::group_by(ID, Form, Pen) %>% dplyr::summarise(Time = mean(Time))
df <- df %>% convert_as_factor(ID, Form, Pen)
df$Time <- as.numeric(df$Time)
我想测试主要效果和交互效果,所以我正在做一个 2 x 3 重复测量方差分析(双向方差分析,因为表格和笔是两个独立变量)。
aov <- rstatix::anova_test(data = df, dv = Time, wid = ID, within = c(Form, Pen))
我一直收到这个错误:
Error: Problem with `mutate()` input `data`.
x Can't subset columns that don't exist.
x Columns `ID` and `Form` don't exist.
ℹ Input `data` is `map(.data$data, .f, ...)`.
为什么?!任何帮助将不胜感激。我一直在寻找 HOURS 的解决方案,但我感到非常沮丧。
感谢您向 post 添加额外的详细信息 - 根据您提供的内容,看起来您需要在将 df 传递给 anova_test()
之前取消分组,例如
#install.packages("rstatix")
library(rstatix)
library(tidyverse)
ID = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3)
Form = c("A", "A", "A", "B", "B", "B", "A", "A", "A", "B", "B", "B", "A", "A", "A", "B", "B", "B")
Pen = c("Red", "Blue", "Green", "Red", "Blue", "Green", "Red", "Blue", "Green","Red", "Blue", "Green","Red", "Blue", "Green","Red", "Blue", "Green")
Time = c(20, 4, 6, 2, 76, 3, 86, 35, 74, 94, 14, 35, 63, 12, 15, 73, 87, 33)
original.df <- data.frame(ID, Form, Pen, Time)
df <- original.df %>%
dplyr::select(ID, Form, Pen, Time)
df <- df %>%
dplyr::group_by(ID, Form, Pen) %>%
dplyr::summarise(Time = mean(Time))
df <- df %>%
convert_as_factor(ID, Form, Pen)
df$Time <- as.numeric(df$Time)
df <- ungroup(df)
aov <- rstatix::anova_test(data = df, dv = Time, wid = ID, within = c(Form, Pen))
您可以查看数据框是否使用 str()
分组,例如str(df)
之前和之后 ungrouped()
向您展示了差异。如果您在进行此更改后仍然遇到错误,请告诉我
这让我发疯。我正在使用 rstatix 的 anova_test,它告诉我我的列不存在,而它们显然存在。
这是我的数据框的样子:
ID = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3)
Form = c("A", "A", "A", "B", "B", "B", "A", "A", "A", "B", "B", "B", "A", "A", "A", "B", "B", "B")
Pen = c("Red", "Blue", "Green", "Red", "Blue", "Green", "Red", "Blue", "Green","Red", "Blue", "Green","Red", "Blue", "Green","Red", "Blue", "Green")
Time = c(20, 4, 6, 2, 76, 3, 86, 35, 74, 94, 14, 35, 63, 12, 15, 73, 87, 33)
df <- data.frame(ID, Form, Pen, Time)
ID, Form, Pen 是因素,Time 是数字。所以每个受试者用红色、蓝色和绿色的笔完成表格 A 和 B,我测量了每个人完成表格所用的时间。
这是我特意想出的一个假数据集来问这个问题。实际上,这个数据框是从一个更大的数据集派生出来的,这个数据集有更多的变量。每个变量都有更多的观察结果(因此不仅仅是主题 1 和表格 A 和红笔的一个数据点,如本例所示,而是多个),所以我总结了平均时间。
df <- original.df %>% dplyr::select(ID, Form, Pen, Time)
df <- df %>% dplyr::group_by(ID, Form, Pen) %>% dplyr::summarise(Time = mean(Time))
df <- df %>% convert_as_factor(ID, Form, Pen)
df$Time <- as.numeric(df$Time)
我想测试主要效果和交互效果,所以我正在做一个 2 x 3 重复测量方差分析(双向方差分析,因为表格和笔是两个独立变量)。
aov <- rstatix::anova_test(data = df, dv = Time, wid = ID, within = c(Form, Pen))
我一直收到这个错误:
Error: Problem with `mutate()` input `data`.
x Can't subset columns that don't exist.
x Columns `ID` and `Form` don't exist.
ℹ Input `data` is `map(.data$data, .f, ...)`.
为什么?!任何帮助将不胜感激。我一直在寻找 HOURS 的解决方案,但我感到非常沮丧。
感谢您向 post 添加额外的详细信息 - 根据您提供的内容,看起来您需要在将 df 传递给 anova_test()
之前取消分组,例如
#install.packages("rstatix")
library(rstatix)
library(tidyverse)
ID = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3)
Form = c("A", "A", "A", "B", "B", "B", "A", "A", "A", "B", "B", "B", "A", "A", "A", "B", "B", "B")
Pen = c("Red", "Blue", "Green", "Red", "Blue", "Green", "Red", "Blue", "Green","Red", "Blue", "Green","Red", "Blue", "Green","Red", "Blue", "Green")
Time = c(20, 4, 6, 2, 76, 3, 86, 35, 74, 94, 14, 35, 63, 12, 15, 73, 87, 33)
original.df <- data.frame(ID, Form, Pen, Time)
df <- original.df %>%
dplyr::select(ID, Form, Pen, Time)
df <- df %>%
dplyr::group_by(ID, Form, Pen) %>%
dplyr::summarise(Time = mean(Time))
df <- df %>%
convert_as_factor(ID, Form, Pen)
df$Time <- as.numeric(df$Time)
df <- ungroup(df)
aov <- rstatix::anova_test(data = df, dv = Time, wid = ID, within = c(Form, Pen))
您可以查看数据框是否使用 str()
分组,例如str(df)
之前和之后 ungrouped()
向您展示了差异。如果您在进行此更改后仍然遇到错误,请告诉我