1

I am fitting a bayesian linear mixed model in R with 6 variables and 2 random effects. Inclusion of all 6 variables is motivated by a well-founded hypothesis. Does it make sense to do variable selection or can I report whether or not each fixed effect has an effect on the dependent variable (CI does not overlap 0)? And then, perhaps, compare the final model to an intercept only model using LOOIC to evaluate model fit? Or run the full model, select only the significant variables, and compare?

If I should do stepwise variable selection is there a way to automate it as with dredge() in MuMIn?

I am trying to figure out the most correct way to test if each covariate has an effect on y without running ~100 models (which I would have to do to examine model fit for all combinations of covariates).

eg,

library(brms)
library(loo)
model.full <- brm(data = data,
             family = gaussian,
             formula = y1 ~ x1 + x2 + x3 + x4 + x5 + x6 +
               (1|r1) + (1|r2),
             prior = c(prior(normal(0, 10), class = Intercept),
                       prior(cauchy(0, 1), class = sd),
                       prior(cauchy(0, 1), class = sigma)),
             iter = 2000, warmup = 1000, chains = 4, cores = 2,
             control = list(adapt_delta = .975, max_treedepth = 20),
             seed = 12261996)

model.intercept <- brm(data = data,
             family = gaussian,
             formula = y1 ~ 1 +
               (1|r1) + (1|r2),
             prior = c(prior(normal(0, 10), class = Intercept),
                       prior(cauchy(0, 1), class = sd),
                       prior(cauchy(0, 1), class = sigma)),
             iter = 2000, warmup = 1000, chains = 4, cores = 2,
             control = list(adapt_delta = .975, max_treedepth = 20),
             seed = 12261996)

loo(model.full, model.intercept)
margie
  • 25
  • 4

1 Answers1

2

Given you have well-founded hypotheses about which variables should be included as predictors of your outcome, there is little reason to worry about variable selection.

As you point out, the model comparison you are running with loo is evaluating the fit of a model with only intercepts and no predictors to a model with all the predictors plus the intercepts. Unless most of your predictors are not at all helping to explain the outcome (or predict to new observations), I would be shocked if the results indicated the random intercept only model was the superior model. Thus I am not sure it makes sense to run the model comparison using these two models.

Is it the case that one or more of the predictors are less well-founded in the literature? If so, you might instead remove those two predictors, run that model, and compare it to the model with all predictors included. Or, if there is some reason to believe that the effect of one or more of the predictors on the outcome vary across groups (i.e., a random slope), you might estimate such a model and compare it to the model without random slopes.

Given Bayesian estimation and loo takes some time to run, depending on sample size and model complexity, I would be more judicious about model comparison. Or, I would consider doing some of these comparisons using maximum likelihood in lmer or perhaps rstanarm because the models are pre-compiled. Perhaps also consider using variational inference with either brms or rstanarm with the (algorithm="meanfield") option just to speed things up for model testing.

Erik Ruzek
  • 3,297
  • 10
  • 18
  • Thank you very much! I was unsure about whether variable selection is necessary with bayesian given the ubiquity of of it in frequentist stats. I think that all of the hypotheses are equally well-founded and I don't think the effect of them will vary across groups so I can report the effect size and credible intervals of the full model (along with model diagnostics) and not worry about model selection beyond that? I initially ran my model in lmer but was getting issues with the complexity of the random effect (singularity warnings). – margie Mar 20 '20 at 20:19
  • Also, is pareto shape k used as an indicator of outliers? Sorry - I did take a bayesian stats class but I am not to applying it to my own data! – margie Mar 20 '20 at 20:22
  • 1
    @CSyrup, I would investigate the singularity issues. It could be due to maximum likelihood problems or it could be because the data doesn't support your random effects structure. Also, in terms of outliers, do you mean in the raw data or in the posterior distribution? I'm not as sure about identifying those in the posterior. – Erik Ruzek Mar 20 '20 at 21:12
  • Okay! Thank you! It seems as though bayesian linear regression is great for testing if I should include the random effect structure. I think I should add this to my model selection process (i.e., test if I should include each random effect) for the bayesian linear mixed models? If I shouldn't then maybe singularity in the frequentist approach was due to the data not supporting the random effects structure? I am not sure how to investigate if it was because of ML problems? – margie Mar 21 '20 at 16:29
  • For outliers - I guess my question is that I have a few observations with high pareto shape k estimates and was wondering if I should exclude these from my data? I did trying excluding data points with high pareto shape k estimates but when I refit the model I just found that the new model had other observations with high pareto shape k estimates. I tried several transformations of my data to reduce the pareto shape k estimates but that didn't seem to work either. I am a little lost at to how to appropriately deal with high pareto shape k estimates. – margie Mar 21 '20 at 16:35
  • 1
    You might start by estimating the models with a single random intercept and looking at the variance estimate for the random effects. If the variance of one of the random intercepts is very small, then it may be the case that there is not enough group variation to justify the random intercept. With regards to pareto shape k and loo, this blog post seems really useful: https://solomonkurz.netlify.com/post/robust-linear-regression-with-the-robust-student-s-t-distribution/ – Erik Ruzek Mar 21 '20 at 21:47