介绍
我不久前遵循了本指南并返回以进行我自己的重复测量方差分析: https ://www.datanovia.com/en/lessons/repeated-measures-anova-in-r/
脚本
到目前为止,我有这个脚本并且没有任何直接的问题:
#### Local R data ####
hwk1 <- structure(list(group = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), format.spss = "F8.2", class = c("haven_labelled",
"vctrs_vctr", "double"), labels = c(`stress management` = 1,
control = 2)), time1 = structure(c(39, 46, 32, 29, 24, 35, 42,
51, 44, 32, 31, 48, 46, 47, 39, 30, 35, 40, 46, 58, 47, 39, 36,
54), format.spss = "F8.2"), time2 = structure(c(37, 42, 32, 33,
22, 32, 33, 47, 41, 37, 38, 44, 48, 45, 35, 31, 33, 38, 46, 52,
44, 41, 39, 55), format.spss = "F8.2"), time3 = structure(c(36,
38, 34, 31, 18, 29, 43, 50, 36, 38, 39, 39, 47, 41, 38, 33, 37,
38, 51, 55, 46, 43, 41, 48), format.spss = "F8.2")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -24L))
#### Load libraries ####
library(tidyverse)
library(correlation)
library(rstatix)
library(ggpubr)
#### Pivot data ####
pivo_hwk1 <- hwk1 %>%
gather(key = "time",
value = "stress",
time1,
time2,
time3) %>%
convert_as_factor(group,
time)
#### Descriptives ####
pivo_hwk1 %>%
group_by(group,
time) %>%
get_summary_stats(stress,
type = "mean_sd")
#### Simple boxplot of means ####
bxp <- ggboxplot(pivo_hwk1,
x="time",
y="stress",
color = "group",
add = "point",
palette = "lancet")
bxp
#### Check outliers ####
pivo_hwk1 %>%
group_by(group,
time) %>%
identify_outliers()
#### Normality: Shapiro ####
pivo_hwk1 %>%
group_by(group,
time) %>%
shapiro_test(stress)
#### Normality: QQ ####
ggqqplot(pivo_hwk1,
x="stress",
color = "group",
palette = "lancet",
title = "QQ Plot of Group x Time",
subtitle = "Group 1 = Treatment, Group 2 = Control")+
facet_wrap(~time)+
theme_bw()+
theme(plot.title = element_text(face = "bold"),
plot.background = element_rect(fill = "steelblue"),
axis.text = element_text(color = "black"))
问题
好吧,我尝试运行实际的重复测量方差分析,但我对如何将其输入 anova_test 命令感到困惑:
#### RMANOVA ####
res.aov <- anova_test(
data = pivo_hwk1,
dv = stress,
wid = group,
within = c(treatment,
time))
get_anova_table(res.aov)
该res.aov
位不起作用,很明显原因是wid
部分。但是,我不确定我应该怎么做才能修改它,因为我从数据集中尝试的变量的每个组合似乎都不起作用。任何建议都会很棒!
编辑:
看起来我能够使用此代码运行 ANOVA:
# Read the data:
hwk1_raw <- read_csv("C:/Users/DELL/Dropbox/My PC (DESKTOP-SUOCLVS)/Desktop/RM II ASSIGN I/hwk1_raw.csv")
# Create ID values:
hwk1_raw$id <- c(1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,
18,19,20,21,22,23,24)
# Add ID value as character:
hwk1_raw$id <- as.character(hwk1_raw$id)
# Pivot data:
pivo_raw <- hwk1_raw %>%
pivot_longer(
cols = 2:4,
names_to = "time",
values_to = "stress"
)
# Running ANOVA:
res.aov <- anova_test(
data = pivo_raw,
wid = id,
dv = stress,
within = time,
between = group
)
res.aov
但是,我认为我仍然无法确定如何进行成对比较。据我所知,应该只有一对,所以应该是这样的:
pivo_raw %>%
pairwise_t_test(
data = pivo_raw,
formula = stress ~ group,
paired = T,
p.adjust.method = "bonferroni")
但它只是吐出这个:
Error in t.test.default(x = numeric(0), y = numeric(0), paired = TRUE) : not enough 'x' observations
有人可以建议从这里做什么吗?