I am a newbie in R, coming from STATA. I want to evaluate a mixed model (lme4) where my dependent variable is a means (mean speed) and I have as independent variables crosswalk, approach_width (these two in one level, street or approach), lumix, pop_dens, and empl_dens (these ones in another level, this level is the intersection). For the different levels, I have an ID (Int_ID and Approach_ID). The idea is to evaluate the effect on means that lumix, pop_dens, and empl_dens in the Int_ID level and crosswalk, approach_width in the Approach_ID have.
I have been trying to find the way to specify different random slopes on lmer function without any success. I know if I just want to evaluate the Int_ID and Approach_ID should be something like this:
memeads <- lmer(means ~ crosswalk + approach_width + lumix + pop_dens + empl_dens + (1 | Approach_ID) + (1 | Int_ID), data = db)
In STATA I'd do something like this:
xtmixed means crosswalk approach_width lumix pop_dens empl_dens || Int_ID : lumix pop_dens empl_dens || Approach_ID : crosswalk + approach_width
Any help would be appreciated
With @Oliver's help, I was able to fit my model. The solution is the following if any in a future.
To have more than one random variable in the slope, the model would be:
memeads <- lmer(means ~ crosswalk + approach_width + lumix + pop_dens + empl_dens + (1 + lumix + pop_dens + empl_dens | Approach_ID) + (1 +crosswalk + approach_width | Int_ID), data = db)
Thanks for the support
Out of curiousity, what is the difference between the solution:
memeads <- lmer(means ~ crosswalk + approach_width + lumix + pop_dens + empl_dens + (1 + lumix + pop_dens + empl_dens | Approach_ID) + (1 +crosswalk + approach_width | Int_ID), data = db)
and this?
memeads <- lmer(means ~ crosswalk + approach_width + lumix + pop_dens + empl_dens + (1 + lumix | Approach_ID) + (1 + pop_dens | Approach_ID) + (1 + empl_dens | Approach_ID) + (1 + crosswalk | Int_ID) + (1 + approach_width | Int_ID), data = db)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.