BayesFactor anovaBF 语法
BayesFactor anovaBF syntax
我想获得类似于经典 F 检验的 ANOVA 的贝叶斯因子,我只是想确保我正确理解如何编写语法,尤其是关于主题 ID。
例如,我有主体间自变量a_between
和b_between
,主体内变量c_within
和d_within
,因变量values
, 用 subject_id
来标识每个主题;在数据集中 my_data
.
如果我理解正确,对于完整的方差分析,我应该使用:
anovaBF(values~a_between*b_between*c_within*d_within+subject_id, data = my_data, whichModels="bottom", whichRandom="subject_id") # and I assume the order of variables does not matter, e.g. it could also be d_within*a_between*c_within*b_between+subject_id
仅对于受试者内方差分析,我应该使用:
anovaBF(values~c_within*d_within+subject_id, data = my_data, whichModels="bottom", whichRandom="subject_id")
仅对于受试者间方差分析,我应该使用:
anovaBF(values~a_between*b_between, data = my_data, whichModels="bottom", whichRandom="subject_id")
所以在最后一种情况下我没有 +subject_id
- 否则我得到 Error in base::try(expression, silent = silent) : not enough observations
。 (也许是因为每个 subject_id 只有一行?)
两个主要问题:
- 不管是什么原因,上面的解决方案是否正确?
- 如果解决方案正确,为什么我必须为主题内变量指定两次主题 ID(一次为
whichRandom
,一次为 +subject_id
),为什么不指定只有主体间变量?
(仅供参考,有一个相关的问题和答案,但不完全是我想知道的:https://stats.stackexchange.com/questions/230224/mixed-bayesian-anova-using-bayesfactor-package-in-r)
来自https://forum.cogsci.nl/index.php?p=/discussion/5203/bayesfactor-anovabf-syntax:
Generally, yes - but I'm not sure you want to use whichModels = "bottom"
- it is advised to stick with the defaults here (whichModels = "withmain"
). Also you can't really get a BF for an F test - as BF are always comparative, so if you want a BF for each "effect" you'll need to think which comparison of which two models might represent that (like in step-wise hierarchical regression). Or, you may want to try to compute Inclusion BFs via bayestestR::bayesfactor_inclusion()
(equivalent to JASP's effects panel).
anovaBF
isn't really an anova at all - it is actually a linear mixed model. So you need to specify +subject_id
as it is an effect in your model, but you also need to tell anovaBF
that it is a random effect (and not a fixed one).
更多有用的链接:
https://forum.cogsci.nl/index.php?p=/discussion/2426/type-of-sums-of-squares
https://www.cogsci.nl/blog/interpreting-bayesian-repeated-measures-in-jasp
无论如何,我会坚持使用 bayestestR::bayesfactor_inclusion()
和 match_models = TRUE
;这对我来说似乎是最直接的。
我想获得类似于经典 F 检验的 ANOVA 的贝叶斯因子,我只是想确保我正确理解如何编写语法,尤其是关于主题 ID。
例如,我有主体间自变量a_between
和b_between
,主体内变量c_within
和d_within
,因变量values
, 用 subject_id
来标识每个主题;在数据集中 my_data
.
如果我理解正确,对于完整的方差分析,我应该使用:
anovaBF(values~a_between*b_between*c_within*d_within+subject_id, data = my_data, whichModels="bottom", whichRandom="subject_id") # and I assume the order of variables does not matter, e.g. it could also be d_within*a_between*c_within*b_between+subject_id
仅对于受试者内方差分析,我应该使用:
anovaBF(values~c_within*d_within+subject_id, data = my_data, whichModels="bottom", whichRandom="subject_id")
仅对于受试者间方差分析,我应该使用:
anovaBF(values~a_between*b_between, data = my_data, whichModels="bottom", whichRandom="subject_id")
所以在最后一种情况下我没有 +subject_id
- 否则我得到 Error in base::try(expression, silent = silent) : not enough observations
。 (也许是因为每个 subject_id 只有一行?)
两个主要问题:
- 不管是什么原因,上面的解决方案是否正确?
- 如果解决方案正确,为什么我必须为主题内变量指定两次主题 ID(一次为
whichRandom
,一次为+subject_id
),为什么不指定只有主体间变量?
(仅供参考,有一个相关的问题和答案,但不完全是我想知道的:https://stats.stackexchange.com/questions/230224/mixed-bayesian-anova-using-bayesfactor-package-in-r)
来自https://forum.cogsci.nl/index.php?p=/discussion/5203/bayesfactor-anovabf-syntax:
Generally, yes - but I'm not sure you want to use
whichModels = "bottom"
- it is advised to stick with the defaults here (whichModels = "withmain"
). Also you can't really get a BF for an F test - as BF are always comparative, so if you want a BF for each "effect" you'll need to think which comparison of which two models might represent that (like in step-wise hierarchical regression). Or, you may want to try to compute Inclusion BFs viabayestestR::bayesfactor_inclusion()
(equivalent to JASP's effects panel).
anovaBF
isn't really an anova at all - it is actually a linear mixed model. So you need to specify+subject_id
as it is an effect in your model, but you also need to tellanovaBF
that it is a random effect (and not a fixed one).
更多有用的链接:
https://forum.cogsci.nl/index.php?p=/discussion/2426/type-of-sums-of-squares
https://www.cogsci.nl/blog/interpreting-bayesian-repeated-measures-in-jasp
无论如何,我会坚持使用 bayestestR::bayesfactor_inclusion()
和 match_models = TRUE
;这对我来说似乎是最直接的。