[英]repeated measure anova in longitudinal study
I have a data set like the following: 我有一个类似以下的数据集:
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
My goal is to compare the three scores within each group, and see if the mean of score1 for group1 is significantly different from score2 and score3. 我的目标是比较每个组中的三个分数,并查看第1组的Score1平均值是否与Score2和Score3显着不同。 And also to compare the means of score1 between each group. 并比较各组之间的score1平均值。 And map all the three scores (three lines) on the horizontal axis of the grouping factor on a nice graph. 并在漂亮的图表上将所有三个得分(三行)映射到分组因子的水平轴上。 I am stuck with which R package I should do it. 我受制于应该使用哪个R包。 Could somebody please let me know which package and function best does this? 有人可以让我知道哪个软件包和功能最好吗? thanks 谢谢
Something like this? 像这样吗
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")
So here, we first convert your dataset from "wide" format (scores in different columns) to "long" format (all the scores in one column, with a second column, Score
, indicating which set each row belongs to). 因此,在这里,我们首先将您的数据集从“宽”格式(不同列中的分数)转换为“长”格式(一列中的所有得分,第二列Score
,指示每一行属于哪个集合)。 The we use ggplot
to plot the mean score (using stat_summary(fun.y=mean,...)
and the +/- 95% CL (using stat_summary(fun.data=mean_cl_normal,...)
. The rest is just formatting. 我们使用ggplot
绘制平均得分(使用stat_summary(fun.y=mean,...)
和+/- 95%CL(使用stat_summary(fun.data=mean_cl_normal,...)
。格式。
You would think from this that, since the 95% CL overlap for every group and every score, that no score/group is different from any other score/group. 您可能会认为,由于每个组和每个分数的95%CL重叠,因此没有一个分数/组与任何其他分数/组有所不同。 But this is misleading. 但这是误导。 If we run a t-test comparing scores 2 and 3 in group 2, for instance, 例如,如果我们进行t检验比较第2组的得分2和3,
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
we can see that these two scores are different at approximately the 98% level. 我们可以看到这两个分数在大约98%的水平上有所不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.