【问题标题】:How can I use summary() with lqmm and formula objects如何将 summary() 与 lqmm 和公式对象一起使用
【发布时间】:2021-03-25 08:04:55
【问题描述】:

我有一个公式对象列表,可以用lqmm::lqmm() 拟合线性分位数混合模型。

我不能使用summary() 从生成的模型中返回具有标准误差等的模型系数。

d <- structure(list(DID = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), pain = c(4L, 2L, 6L, 3L, 3L, 
4L, 3L, 3L, 4L, 5L, 4L, 4L, 5L, 3L, 4L, 3L, 2L, 6L, 5L, 7L, 6L, 
3L, 5L, 1L, 5L, 3L, 4L, 4L, 6L, 5L, 5L, 6L, 5L, 6L, 5L, 6L, 6L, 
5L, 6L, 7L, 4L, 5L, 6L, 6L, 5L, 6L, 4L, 5L, 6L, 7L), wound = c(4L, 
3L, 3L, 3L, 4L, 5L, 4L, 3L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 4L, 3L, 
4L, 4L, 3L, 3L, 3L, 4L, 3L, 3L, 4L, 5L, 3L, 8L, 7L, 7L, 7L, 7L, 
9L, 8L, 8L, 8L, 6L, 7L, 6L, 8L, 7L, 6L, 8L, 7L, 6L, 7L, 8L, 7L, 
7L), mobility = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
3L, 3L, 2L, 1L, 1L, 2L, 2L, 3L, 2L, 3L, 1L, 2L, 2L, 3L, 2L, 3L, 
3L, 6L, 5L, 6L, 6L, 5L, 6L, 5L, 5L, 5L, 5L, 6L, 5L, 6L, 5L, 5L, 
5L, 6L, 5L, 5L, 3L, 5L, 6L)), row.names = c(NA, 50L), class = "data.frame")

library(lqmm)

x <- as.formula("pain ~ wound + mobility")

m1 <- lqmm(x,
           random = ~ 1,
           group = DID,
           data = d)
summary(m1)

错误:“符号”类型的对象不是子集

我尝试按照here 的建议使用eval(x),但出现递归错误。

m2 <- lqmm(eval(x),
           random = ~ 1,
           group = DID,
           data = d)
summary(m2)

错误:求值嵌套太深:无限递归/选项(表达式=)? 总结期间出错:评估嵌套太深:无限递归/选项(表达式=)? 错误:没有更多可用的错误处理程序(递归错误?);调用“中止”重启

关于如何提取模型参数的任何想法?

完整的样本数据取自here

【问题讨论】:

    标签: r summary mixed-models


    【解决方案1】:

    像下面这样运行,它应该可以工作:

    x <- as.formula('pain ~ wound + mobility')
    m1 <- lqmm(x,
               random = ~ 1,
               group = DID,
               data = d)
    ## Fixing the call fixed here.
    m1$call$fixed <- x
    
    summary(m1)
    

    输出:

    > m1$call$fixed <- x
    > summary(m1)
    Call: lqmm(fixed = pain ~ wound + mobility, random = ~1, group = DID, 
        data = d)
    
    Quantile 0.5 
    
    Fixed effects:
                    Value Std. Error lower bound
    (Intercept)  2.765900   1.294809    0.163883
    wound        0.052025   0.077028   -0.102770
    mobility     0.469649   0.127371    0.213687
                upper bound  Pr(>|t|)    
    (Intercept)      5.3679 0.0376887 *  
    wound            0.2068 0.5025982    
    mobility         0.7256 0.0005675 ***
    ---
    Signif. codes:  
    0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    AIC:
    [1] 166.1 (df = 5)
    

    小调试后有问题,我意识到以下两种方法返回的对象并不相似,因此我像上面一样操纵了其中一种:

    m2 <- lqmm(pain ~ wound + mobility,
               random = ~ 1,
               group = DID,
               data = d)
    
    
    m1 <- lqmm(x,
               random = ~ 1,
               group = DID,
               data = d)
    

    如果我们仔细观察 m1$callm2$call,(m1 与摘要配合良好)但是,两者都是不同的对象,因此导致 OP 遇到的错误,我认为这是一个错误,但请告诉我如果有其他解释。同样在运行all.equal(m1, m2) 时,它告诉我确实存在差异。所以,在用给定的信息摆弄它之后,我已经将 list 的固定元素重置为原始 x (这是公式),它现在似乎正在工作:

    > all.equal(m1, m2)
    [1] "Component “call”: target, current do not match when deparsed"
    

    【讨论】:

    • @Paul ,更新看看解决方案是否适合你
    • 谢谢,@PKumar - 我不可能自己解决这个问题!
    猜你喜欢
    • 2011-10-23
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多