Paul
Paul

Reputation: 2959

How can I use summary() with lqmm and formula objects

I've got a list of formula objects to fit Linear Quantile Mixed Models with lqmm::lqmm().

I cannot use summary() to return model coefficients with standard errors etc. from the produced models.

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)

Error: object of type 'symbol' is not subsettable

I tried using eval(x) as suggested here, but got a recursion error.

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

Error: evaluation nested too deeply: infinite recursion / options(expressions=)? Error during wrapup: evaluation nested too deeply: infinite recursion / options(expressions=)? Error: no more error handlers available (recursive errors?); invoking 'abort' restart

Any ideas on how to extract model parameters?

Full sample data was taken from here.

Upvotes: 1

Views: 172

Answers (1)

PKumar
PKumar

Reputation: 11128

Run this like below, It should work:

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)

Output:

> 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)

There is catch after little debug, I realised objects returned by below two approaches are not similar hence I have manipulated one of them like above:

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


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

If we closely observe m1$call and m2$call,(m1 is working well with summary) however, both are different objects and hence leading to the error which OP has encountered, I think its a bug but please let me know if there is any other explanation. Also while running all.equal(m1, m2) it tells me there is indeed a difference. So, after fiddling it with the given info, I have resetted the fixed element of list to original x (which is formula), which it seems to be working for now:

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

Upvotes: 1

Related Questions