Mixed models (lme4) + lsmeans to estimate trend in population means

I aim to estimate one populations mean blood pressure during different years. Here is the setting: (1) 7400 onservations; repeated measurements. Unbalanced. (2) measurements are undertaken anually from 2001 to 2012. Eachindividual maybe measured several times. (3) one can expect a time-bias, i.e as time progress, there will be made advances in therapy, which will lead to more efficient blood pressure lowering. These factors will not be taken into account. Deliberately.

Aim: estimate population mean blood pressure each year. Including confidence interval.

Methods: use lme4 package (linear outcome, blood pressure) to account for repeated measurements and lsmeans package to estimate the population mean each year.

Code:

fit <- lmer(bloodpressure ~ year + age + sex + (1 | patient_id), data=data)

'year' is the factor variable for which I'd like to obtsin the means.

lsmeans(fit, ~ year) # not tried


Questions - is this method OK? - will the covariance be respected by using lsmeans, or should I use lmerTest package which has a built in function for estimating lsmeans? - each individual has a random slope in the call above, should I adjust it to include random effects for year also?

Thanks for any advice on this

• The lsmeans package DOES use the ccorrect ovariate matrix from the object. If you look in the vignettes, you'll find some examples with models fitted with lmer. – Russ Lenth Dec 28 '14 at 23:40
• Thanks @rvl. And the results appear plausible after comparing with crude figures. I'm only using a random term for individual. Id you could provide your comment as answer instead I can approve the question as answered. – Adam Robinsson Dec 29 '14 at 16:22

The lsmeans package does produce the correct results with model objects from a number of packages, including lme4. If you have a fairly recent update of lsmeans installed, you can do ? models and see information on what model objects are supported, and details of any special provisions.