如何在 R 中的多列中执行具有三组、三个时间点和一个因变量的双向混合方差分析
我从大脑中的几个感兴趣区域(fMRI)中提取了时间序列,并且在与大脑中两个节点之间的相关性相对应的列下为每个受试者添加了成对相关性(Fisher-Z)值(例如:stim_lvis3、stim = 刺激部位,lvis3= 左视觉网络 3)。现在,我想对此数据集执行方差分析,以查看效果以及组间/组内差异(3 组 x 3 个时间点)。我的数据已经是长格式了。
*groups= ctbs [10 个受试者 x 3 个时间点]、itbs = [10 个受试者 x 3 个时间点] 和 sham [10 个受试者 x 3 个时间点]
考虑到我有 12 列,关于如何做到这一点的任何建议连接值(stim_lvis3...stim_rpcc1)。例如,我无法绘制按时间和组划分的数据箱线图?
在这种情况下,如何在特定时间点对每组的所有 12 列执行双向混合方差分析,然后在每个时间点比较各组?
我将主题、时间和组转换为因素
tbs %>%
group_by(time, group) %>%
get_summary_stats(stim_lVis3, type = "mean_sd")
tbs(.) 中的错误:找不到函数“tbs”
bxp <- ggboxplot(
tbs, x = "time", y = "stim_lvis3",
color = "group", palette = "jco"
)
bxp
FUN(X[[i]], ...) 中的错误:找不到对象“stim_lvis3”
I have extracted time series from a few regions of interest in the brain (fMRI) and I have added pairwise correlation (Fisher-Z) values for each subject under columns corresponding the correlation between two nodes in the brain (for example: stim_lvis3, stim = stimulation site and lvis3= left visual network 3). Now, I would like to perform ANOVAs on this dataset to look at the effects and between/within group differences (3 groups x 3 timepoints). My data is already in long format.
*groups= ctbs [10 subjects x 3 timepoints], itbs = [10 subjects x 3 timepoints], and sham [10 subjects x 3 timepoints]
Any suggestions on how this can be done, given that I have 12 columns with connectivity values (stim_lvis3....stim_rpcc1). for example I have not been able to box plot the data faceted both by time and group?
How to perform a two-way mixed anova in this situation for all 12 columns for each group at a specific timepoints and then compare groups at each timepoint?
I converted subject, time and group to factors
tbs %>%
group_by(time, group) %>%
get_summary_stats(stim_lVis3, type = "mean_sd")
Error in tbs(.) : could not find function "tbs"
bxp <- ggboxplot(
tbs, x = "time", y = "stim_lvis3",
color = "group", palette = "jco"
)
bxp
Error in FUN(X[[i]], ...) : object 'stim_lvis3' not found
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
欢迎来到SO!您看起来像是新手,但将来要快速获得出色的答案,请确保以可用的格式包含示例数据(即
dput(head(myData))
的输出) 。看看:制作 R 可重现的问题。我知道有两种在方差分析内和之间完成的方法。更容易实现的版本来自
ez
包。jmv
包提供了更复杂的编写,但您也拥有大量的控制权。我确信ez
的版本还有更多内容,但我还没有经常使用该包。我创建了数据来模拟您正在使用的内容。
要使用
ez
,这是一个非常简单的实现。尽管如此,我找不到允许多个因变量的选项。本质上,您要么需要pivot_long
,要么可以使用jmv
。对于这种方法,您无法获得事后比较;效应大小是广义的 η2。
现在要使用
jmv
,您需要将数据旋转得更宽。您的受试者内数据需要位于单独的列中。由于时间
是用stim
...列中的受试者内值表示的因素,因此这就是您需要进行旋转的因素。现在您已准备好使用
jmv
。bs
相当于科目间;rm
相当于重复测量。如果您打印
fit
,您将获得大量信息。除了ezANOVA
提供的内容之外,它还提供了每个组、时间、因变量以及每个变量的混合的事后比较;统计假设的结果:用于同质性的 Levene 和用于正态性的残差 QQ 图;以及估计的边际平均值表和这些平均值的图。我意识到您的数据中的字段比我这里的字段多。我相信我已经为你提供了足够的基础。
我建议您确定要从数据中学习什么,并从中选择算法。
如果您有任何疑问,请告诉我。
Welcome to SO! It's looks like you're new, but in the future to get great answers quickly, make sure you include sample data in a format that useable (i.e., the output from
dput(head(myData))
). Check it out: making R reproducible questions.I know of two approaches to completing within and between ANOVA. The easier to implement version is from the package
ez
. The packagejmv
offers a much more complex write-up but you have an immense amount of control, as well. I'm sure there is more toez
's version, but I haven't worked with that package very much.I created data to somewhat simulate what you are working with.
To use
ez
, it's a pretty straightforward implementation. Although, I couldn't find an option that allowed for multiple dependent variables. Essentially, you would either need topivot_long
or you can usejmv
.For this method, you don't get the post hoc comparisons; the effect size is the generalized η2.
Now to use
jmv
, you will need to pivot the data wider. Your within-subject data needs to be in separate columns. Sincetime
is the factor that represents with the within-subject values in thestim
... columns, that's what you need to pivot.Now you're ready for
jmv
.bs
equates to between-subjects;rm
equates to repeated measures.If you print
fit
, you're going to get a ton of information. In addition to the content provided byezANOVA
, this provides the post hoc comparisons of each group, time, dependent variable, and the intermix of each; the results of the statistical assumptions: Levene's for homogeneity and a QQ plot of the residuals for normality; and the estimated marginal means table and a plot of those means.I realize that you have more fields in your data than what I have here. I believe I've provided enough for you to build off of.
I suggest that you determine what you want to learn from the data and choose the algorithm from there.
If you have any questions, let me know.