vdorie / blme

Bayesian Linear Mixed Effect Models
39 stars 7 forks source link

cov.prior set up #14

Open JJ-Zhang-DS opened 1 year ago

JJ-Zhang-DS commented 1 year ago

I want to fix the cov.prior to 10 and residual var to 5. But the cov.prior can not be passed to the model. How to fix the cov.prior? Here I only have an intercept for one random effect 'rep'. '''

Define the model formula

formula <- y ~ trt + (1|rep)

Define the control parameters

control = lmerControl(optimizer ='bobyqa')

Fit the model with a prior variance of 10 for the random intercepts

model <- blmer(formula, data=data, cov.prior = (diag(1)*10), resid.prior = point(value=5, posterior.scale='var'), control=control) '''

vdorie commented 1 year ago

The model is a function of the covariance of the random effects (see https://www.jstatsoft.org/article/view/v067i01/). If the covariance is fixed, there is no optimization problem to perform. If you just want to recover the (restricted) maximum likelihood estimate of the treatment parameter, you can do something similar to what is in this response. The main change you would need to make would be replace the call to optim with a single evaluation of the deviance function at sqrt(10) / sqrt(5).