如何将 summary() 与 lqmm 和公式对象一起使用
How can I use summary() with lqmm and formula objects
我有一个公式对象列表来拟合具有 lqmm::lqmm()
的线性分位数混合模型。
我不能使用 summary()
到 return 模型系数和来自生成模型的标准误差等。
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
我尝试按照建议使用 eval(x)
here,但出现递归错误。
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
关于如何提取模型参数有什么想法吗?
完整样本数据取自 here。
运行 如下所示,它应该可以工作:
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$call
和 m2$call
,(m1 与摘要配合使用效果很好)然而,两者是不同的对象,因此导致 OP 遇到的错误,我认为这是一个错误,但如果有任何其他解释,请告诉我。同时 运行 all.equal(m1, m2)
它告诉我确实存在差异。所以,在用给定的信息摆弄它之后,我将列表的固定元素重置为原始 x (这是公式),它现在似乎正在工作:
> all.equal(m1, m2)
[1] "Component “call”: target, current do not match when deparsed"
我有一个公式对象列表来拟合具有 lqmm::lqmm()
的线性分位数混合模型。
我不能使用 summary()
到 return 模型系数和来自生成模型的标准误差等。
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
我尝试按照建议使用 eval(x)
here,但出现递归错误。
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
关于如何提取模型参数有什么想法吗?
完整样本数据取自 here。
运行 如下所示,它应该可以工作:
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$call
和 m2$call
,(m1 与摘要配合使用效果很好)然而,两者是不同的对象,因此导致 OP 遇到的错误,我认为这是一个错误,但如果有任何其他解释,请告诉我。同时 运行 all.equal(m1, m2)
它告诉我确实存在差异。所以,在用给定的信息摆弄它之后,我将列表的固定元素重置为原始 x (这是公式),它现在似乎正在工作:
> all.equal(m1, m2)
[1] "Component “call”: target, current do not match when deparsed"