简体   繁体   English

混合效应模型 (lme4) 截距(随机斜率)的多个变量

[英]Multiple variables for the intercept (random slopes) of a Mixed Effect Model (lme4)

I am a newbie in R, coming from STATA.我是 R 的新手,来自 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).我想评估一个混合模型 (lme4),其中我的因变量是均值(平均速度),我将人行横道、方法宽度(这两个在一个级别、街道或方法中)、lumix、pop_dens 和 empl_dens(这些在另一层,这一层是交集)。 For the different levels, I have an ID (Int_ID and Approach_ID).对于不同的级别,我有一个 ID(Int_ID 和 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.这个想法是评估Int_ID级别中的lumix、pop_dens和empl_dens以及Approach_ID中的crosswalk、roach_width对means的影响。

I have been trying to find the way to specify different random slopes on lmer function without any success.我一直试图找到在 lmer 函数上指定不同随机斜率的方法,但没有成功。 I know if I just want to evaluate the Int_ID and Approach_ID should be something like this:我知道如果我只想评估 Int_ID 和 Approach_ID 应该是这样的:

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:在 STATA 我会做这样的事情:

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. 在@ Oliver的帮助下,我能够适应我的模型。 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM