纵向研究中的重复测量方差分析
repeated measure anova in longitudinal study
我有如下数据集:
Groups Score1 Score2 Score3
G1 12 19 11
G1 8 2 12
G1 5 4 17
G1 20 17 5
G1 15 3 18
G1 5 9 6
G1 14 13 16
G1 2 7 2
G1 14 1 0
G1 9 19 11
G2 8 11 9
G2 14 7 17
G2 16 10 18
G2 13 9 14
G2 10 15 15
G2 5 1 11
G2 4 16 19
G2 17 14 16
G2 14 13 16
G2 2 0 13
G3 16 13 19
G3 3 12 10
G3 9 4 16
G3 17 3 12
G3 18 4 6
G3 20 1 18
G3 15 17 7
G3 10 16 12
G3 3 12 2
G3 8 2 2
我的目标是比较每个组内的三个分数,看看 group1 的 score1 的平均值是否与 score2 和 score3 有显着差异。并且还要比较每组之间 score1 的均值。
并将分组因子的横轴上的所有三个分数(三条线)映射到一个漂亮的图表上。
我坚持我应该做哪个 R 包。
有人可以让我知道哪个包和函数最能做到这一点吗?
谢谢
是这样的吗?
library(reshape2) # for melt(...)
library(ggplot2)
df.melt <- melt(df, id="Groups", variable.name="Score")
ggplot(df.melt, aes(x=Groups, y=value, color=Score))+
stat_summary(geom="point", fun.y=mean, position=position_dodge(width=0.5))+
stat_summary(geom="errorbar", fun.data=mean_cl_normal, width=0.1, position=position_dodge(width=0.5))+
labs(x="", y="Score")
所以在这里,我们首先将您的数据集从 "wide" 格式(不同列中的分数)转换为 "long" 格式(一列中的所有分数,第二列,Score
,表示每一行属于哪个集合)。我们使用 ggplot
绘制平均分数(使用 stat_summary(fun.y=mean,...)
和 +/- 95% CL(使用 stat_summary(fun.data=mean_cl_normal,...)
。其余只是格式化。
你会由此认为,由于每个组和每个分数的 95% CL 重叠,所以没有 score/group 与任何其他 score/group 不同。但这是误导。例如,如果我们 运行 比较第 2 组中的分数 2 和 3 的 t 检验,
with(df[df$Groups=="G2",],t.test(Score2,Score3))
# Welch Two Sample t-test
#
# data: Score2 and Score3
# t = -2.5857, df = 14.184, p-value = 0.0214
# alternative hypothesis: true difference in means is not equal to 0
# 95 percent confidence interval:
# -9.5080934 -0.8919066
# sample estimates:
# mean of x mean of y
# 9.6 14.8
我们可以看到这两个分数在大约 98% 的水平上是不同的。
我有如下数据集:
Groups Score1 Score2 Score3
G1 12 19 11
G1 8 2 12
G1 5 4 17
G1 20 17 5
G1 15 3 18
G1 5 9 6
G1 14 13 16
G1 2 7 2
G1 14 1 0
G1 9 19 11
G2 8 11 9
G2 14 7 17
G2 16 10 18
G2 13 9 14
G2 10 15 15
G2 5 1 11
G2 4 16 19
G2 17 14 16
G2 14 13 16
G2 2 0 13
G3 16 13 19
G3 3 12 10
G3 9 4 16
G3 17 3 12
G3 18 4 6
G3 20 1 18
G3 15 17 7
G3 10 16 12
G3 3 12 2
G3 8 2 2
我的目标是比较每个组内的三个分数,看看 group1 的 score1 的平均值是否与 score2 和 score3 有显着差异。并且还要比较每组之间 score1 的均值。 并将分组因子的横轴上的所有三个分数(三条线)映射到一个漂亮的图表上。 我坚持我应该做哪个 R 包。 有人可以让我知道哪个包和函数最能做到这一点吗? 谢谢
是这样的吗?
library(reshape2) # for melt(...)
library(ggplot2)
df.melt <- melt(df, id="Groups", variable.name="Score")
ggplot(df.melt, aes(x=Groups, y=value, color=Score))+
stat_summary(geom="point", fun.y=mean, position=position_dodge(width=0.5))+
stat_summary(geom="errorbar", fun.data=mean_cl_normal, width=0.1, position=position_dodge(width=0.5))+
labs(x="", y="Score")
所以在这里,我们首先将您的数据集从 "wide" 格式(不同列中的分数)转换为 "long" 格式(一列中的所有分数,第二列,Score
,表示每一行属于哪个集合)。我们使用 ggplot
绘制平均分数(使用 stat_summary(fun.y=mean,...)
和 +/- 95% CL(使用 stat_summary(fun.data=mean_cl_normal,...)
。其余只是格式化。
你会由此认为,由于每个组和每个分数的 95% CL 重叠,所以没有 score/group 与任何其他 score/group 不同。但这是误导。例如,如果我们 运行 比较第 2 组中的分数 2 和 3 的 t 检验,
with(df[df$Groups=="G2",],t.test(Score2,Score3))
# Welch Two Sample t-test
#
# data: Score2 and Score3
# t = -2.5857, df = 14.184, p-value = 0.0214
# alternative hypothesis: true difference in means is not equal to 0
# 95 percent confidence interval:
# -9.5080934 -0.8919066
# sample estimates:
# mean of x mean of y
# 9.6 14.8
我们可以看到这两个分数在大约 98% 的水平上是不同的。