lme4中的多元线性混合模型 [英] Multivariate Linear Mixed Model in lme4

查看:684
本文介绍了lme4中的多元线性混合模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何用lme4拟合多元线性混合模型.我用以下代码拟合了单变量线性混合模型:

I wonder how to fit multivariate linear mixed model with lme4. I fitted univariate linear mixed models with the following code:

library(lme4)
lmer.m1 <- lmer(Y1~A*B+(1|Block)+(1|Block:A), data=Data)
summary(lmer.m1)
anova(lmer.m1)

lmer.m2 <- lmer(Y2~A*B+(1|Block)+(1|Block:A), data=Data)
summary(lmer.m2)
anova(lmer.m2)

我想知道如何用lme4拟合多元线性混合模型.数据如下:

I'd like to know how to fit multivariate linear mixed model with lme4. The data is below:

Block A B    Y1    Y2
 1    1 1 135.8 121.6
 1    1 2 149.4 142.5
 1    1 3 155.4 145.0
 1    2 1 105.9 106.6
 1    2 2 112.9 119.2
 1    2 3 121.6 126.7
 2    1 1 121.9 133.5
 2    1 2 136.5 146.1
 2    1 3 145.8 154.0
 2    2 1 102.1 116.0
 2    2 2 112.0 121.3
 2    2 3 114.6 137.3
 3    1 1 133.4 132.4
 3    1 2 139.1 141.8
 3    1 3 157.3 156.1
 3    2 1 101.2  89.0
 3    2 2 109.8 104.6
 3    2 3 111.0 107.7
 4    1 1 124.9 133.4
 4    1 2 140.3 147.7
 4    1 3 147.1 157.7
 4    2 1 110.5  99.1
 4    2 2 117.7 100.9
 4    2 3 129.5 116.2

提前感谢您的时间和合作.

Thank in advance for your time and cooperation.

推荐答案

通过简单地重新格式化您的数据,有时在nlme/lme4中可以令人满意地伪造

This can sometimes be faked satisfactorily in nlme/lme4 by simply reformatting your data like

require(reshape)
Data = melt(data, id.vars=1:3, variable_name='Y')
Data$Y = factor(gsub('Y(.+)', '\\1', Data$Y))

> Data
  Block A B Y value
1     1 1 1 1 135.8
2     1 1 2 1 149.4
3     1 1 3 1 155.4
4     1 2 1 1 105.9
5     1 2 2 1 112.9
6     1 2 3 1 121.6
...

,然后在线性混合模型中包含新变量Y.

and then including the new variable Y in your linear mixed model.

但是,对于真正的多元广义线性混合模型(MGLMM),您可能需要sabreR软件包或类似软件包.软件包中还附带一本书,即使用R的多元广义线性混合模型.如果您有订阅机构的代理,您甚至可以从 http://www.crcnetbase.com免费下载. /isbn/9781439813270 .我将转介给您寻求进一步的建议,因为这是一个棘手的话题,而且我是一个新手.

However, for true Multivariate Generalized Linear Mixed Models (MGLMM), you will probably need the sabreR package or similar. There is also an entire book to accompany the package, Multivariate Generalized Linear Mixed Models Using R. If you have a proxy to a subscribing institution, you might even be able to download it for free from http://www.crcnetbase.com/isbn/9781439813270. I would refer you there for any further advice, as this is a meaty topic and I am very much a novice.

这篇关于lme4中的多元线性混合模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆