lme4包中的lmer函数语法介绍

1. 模型解释

lmer常用模型公式如下:

mod= lmer(data = , formula = y ~ Fixed_Factor + (Random_intercept + Random_Slope | Random_Factor))
  • data,为数据集
  • y,为观测值,所要分析的性状,因变量
  • Fixed_Factor,为固定因子
  • ()内为随机因子
    • Random_intercept,为随机截距,即认为不同群体因变量的分布不同(通俗的解释:有的人生下来起点高,是富二代,有的人是一般群众,起点低)
    • Random_Slope,为随机斜率,即认为不同群体受固定因子的影响不同(通俗解释:有的人是学霸,学习能力强,2个小时学会,斜率高;有的人是学渣,2天才能学会,斜率低)
    • Random_Factor,随机因子

参考: https://zhuanlan.zhihu.com/p/63092231

2. 常用模型

2.1 Random intercept with fixeed mean

这里是截距(intercept)随机,均值(mean)固定。

公式:

  • (1 | g)
  • 也可以写为:1 + (1 | g)

比如下面两种模型是等价的:

mod1a = lmer(Reaction ~ Days + (1 | Subject), data=dat)
mod1aa = lmer(Reaction ~ Days + 1 + (1 | Subject), data=dat)

估计出的随机因子的效应值为:

2.2 Random intercept with a priori means

公式:

  • 0 + offset(0) + (1 | g)
  • 也可以写为:-1 + offset(0) + (1 | g)

这部分没有很理解,也没有例子,官方文档解释如下:

The names of grouping factors are denoted g, g1, and g2, and covariates and a priori known offsets as x and o

2.3 Intercept varying among g1 and g2 within g1

公式:

  • 1 + (1 | g1/g2)
  • 也可以写为:(1 | g1) + (1 | g1:g2)

2.4 Intercept varying among g1 and g2

公式:

  • (1 | g1) + (1|g2)
  • 也可以写为:1 + (1 | g1) + (1|g2)

2.5 Correlated random intercept and slope

公式:

  • x + (x | g)
  • 也可以写为:1 + x + (1 + x|g)

2.6 Uncorrelated random intercept and slope

公式:

  • x + (x || g)
  • 也可以写为:1 + x + (1|g) + (0 + x|g)

公式汇总:

注意:
这里,x为数值协变量,gg1g2为因子协变量。

参考:https://cran.r-project.org/web/packages/lme4/vignettes/lmer.pdf

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值