Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bayes factor for a single parameter in multilevel regression #142

Open
jen265 opened this issue Apr 23, 2020 · 0 comments
Open

Bayes factor for a single parameter in multilevel regression #142

jen265 opened this issue Apr 23, 2020 · 0 comments

Comments

@jen265
Copy link

jen265 commented Apr 23, 2020

Hello,
Is it possible to compute a bayes factor against the null for a single parameter in multilevel regression? For example, in the model below, Subject is the grouping variable, IV1 is the level-1 predictor with a random slope, and IV2 to IV6 are level-2 predictors. I want to know if a bayes factor is in favor of a specific cross-level interaction being unequal to zero, rather than being equal to zero.

full_BF = lmBF(DV ~ IV1 * IV2 + IV1 * IV3 + IV1 * IV4 + IV1 * IV5 + IV1 * IV6 + Subject + IV1:Subject, data = data, whichRandom = c('Subject','IV1:Subject'))

I have found an example on how to compute a bayes factor for a single parameter in multiple linear regression in Heck, D. W. (2019). A caveat on the Savage–Dickey density ratio: The case of computing Bayes factors for regression parameters. British Journal of Mathematical and Statistical Psychology, 72(2), 316-333. The relevant code of that example is:

full_model <- cranium_capacity ~ parasites + temp_variation + isosd + population_dens
select_pred <- 1 # = test the effect of "parasites"

DV and design matrix

y <- bailey2009$cranium_capacity
X_unscaled <- model.matrix(full_model, data = bailey2009)[,-1, drop = FALSE]
X <- scale(X_unscaled, scale = FALSE)
attr(X, "scaled:center") <- NULL
P <- ncol(X)

BayesFactor package (Morey & Rouder, 2015)

t_bayesfactor <- system.time({
bf.full <- regressionBF(full_model, bailey2009)
# select relevant Bayes factor for "select_pred == 1"
idx <- 0
for(i in 1:(P-1))
idx <- idx + choose(P, i)
bf_BF <- 1 / extractBF(bf.full / bf.full[length(bf.full)])[idx,"bf"]
})

Is it possible to adjust the code such that it can be used for the lmBF function? Or is there any other possibility to compute a bayes factor against the null for a single parameter in multilevel regression?

I am thankful for any idea on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant