How could I extract coefficients (b0 and b1) with their respectively standard errors for each experimental unit (plot )in a linear mixed model such as this one:
Better fits for a linear model
with this same dataset(df), and for the fitted model (fitL1): how could I get a data frame as this one...
plot b0 b0_se b1 b1_se
1 2898.69 53.85 -7.5 4.3
... ... ... ... ...
The first comment is that this is actually a non-trivial theoretical question: there is a rather long thread on r-sig-mixed-models that goes into some of the technical details; you should definitely have a look, even though it gets a bit scary. The basic issue is that the estimated coefficient values for each group are the sum of the fixed-effect parameter and the BLUP/conditional mode for that group, which are different classes of objects (one is a parameter, one is a conditional mean of a random variable), which creates some technical difficulties.
The second point is that (unfortunately) I don't know of an easy way to do this in
lme
, so my answer useslmer
(from thelme4
package).If you are comfortable doing the easiest thing and ignoring the (possibly ill-defined) covariance between the fixed-effect parameters and the BLUPs, you can use the code below.
Two alternatives would be (1) to fit your model with a Bayesian hierarchical approach (e.g. the
MCMCglmm
package) and compute the standard deviations of the posterior predictions for each level (2) use parametric bootstrapping to compute the BLUPs/conditional modes, then take the standard deviations of the bootstrap distributions.Please remember that as usual this advice comes with no warranty.
To get you partway there using nlme...
You can pull the components of summary() using:
etc.
You can further subset those by rows:
to extract individual parameters or standard errors and combine them into a data frame using, for example:
To adjust these parameters for each plot (the random effect, I presume), you can pull the random coefficients with:
and add them to the parameter estimates (B0 (intercept), B1, etc.). However, I am not sure how the standard errors should be adjusted for each plot.