首页 > 解决方案 > 比较 lme 中的 beta 系数

问题描述

我正在使用 nlme 包中的 lme 进行分析。我希望测试分析中的两个系数是否在统计上彼此不同。有谁知道这是怎么做到的吗?

标签: rlme4

解决方案


让我们假设以下模型

library(nlme)
my.model=lme(mpg~cyl+disp+hp,random=~1|am,data=mtcars)
summary(my.model)

Linear mixed-effects model fit by REML
 Data: mtcars 
       AIC      BIC    logLik
  181.5913 189.5845 -84.79563

Random effects:
 Formula: ~1 | am
        (Intercept) Residual
StdDev:    2.208646 2.830831

Fixed effects: mpg ~ cyl + disp + hp 
               Value Std.Error DF   t-value p-value
(Intercept) 32.55270 2.9628523 27 10.986945  0.0000
cyl         -0.90447 0.7538504 27 -1.199794  0.2406
disp        -0.00972 0.0105324 27 -0.922877  0.3642
hp          -0.02971 0.0152707 27 -1.945325  0.0622
 Correlation: 
     (Intr) cyl    disp  
cyl  -0.738              
disp  0.327 -0.564       
hp    0.250 -0.484 -0.321

Standardized Within-Group Residuals:
       Min         Q1        Med         Q3        Max 
-1.6025597 -0.7952622 -0.1413537  0.5074603  2.1800330 

Number of Observations: 32
Number of Groups: 2

让我们比较一下 disp 和 hp 项。模型中有四个项,所以我们需要比较第三项和第四项(我们将使用对比矩阵)

cont=matrix(c(0,0,1,-1),ncol=4)
rownames(cont)="disp - hp"
library(multcomp)
summary(glht(my.model,linfct=cont))

     Simultaneous Tests for General Linear Hypotheses

Fit: lme.formula(fixed = mpg ~ cyl + disp + hp, data = mtcars, random = ~1 | 
    am)

Linear Hypotheses:
               Estimate Std. Error z value Pr(>|z|)
disp - hp == 0  0.01999    0.02115   0.945    0.345
(Adjusted p values reported -- single-step method)

推荐阅读