在 R 中,计算分位数回归的模型摘要时出现错误

问题描述 投票:0回答:1

我正在使用

rq()
函数(quantreg 包)进行分位数回归。 之前,我们的模型是:

rq_model <- rq(outcome ~ factor(year) + variable2 + variable3, data = data)

我能够使用

modelsummary()
函数(modelsummary 包)和
avg_comparisons
函数(marginaleffects 包)来观察估计值。

modelsummary(rq_model,
             estimate = "{estimate} [{conf.low}, {conf.high}]",
             statistic = NULL, title = "TITLE")

avg_comparisons(rq_model,
                type = "response",
                variables = list(year = c(2018, 2022)),
                by = "variable3")

avg_predictions(rq_model,
                type = "response",
                byfun = median,
                newdata = "median",
                variables = list(year = c(2018, 2019, 2020, 2021, 2022)),
                by = c("year","variable3")) %>% 
                filter(variable3 == 1) %>% 
                select(year, estimate, conf.low, conf.high) %>% 
                mutate(round(across(2:4), 3)) %>% 
                gt::gt() %>% 
                gt::tab_header(title = "TITLE")

但是,由于审稿人的评论,他们要求我们添加三个新变量,以便模型可以解释归因于这些变量的方差。首先,我收到此警告消息:

rq_model <- rq(outcome ~ factor(year) + variable2 + variable3 + variable01 + variable02 + variable03, data = data)

rq.fit.br(x, y, tau = tau, ...) 中的警告:解决方案可能不唯一

此外,我用

modelsummary()
avg_comparison()
:

得到这些错误
modelsummary(rq_model,
             estimate = "{estimate} [{conf.low}, {conf.high}]",
             statistic = NULL, title = "TITLE")

错误:`modelsummary 无法从类“rq”的模型中提取所需的信息。该包尝试了 用于提取估计值的 2 个辅助函数的序列:

参数::参数(型号) 扫帚::整洁(模型)

要绘制表格,这些命令之一必须返回

data.frame
,其中包含名为“term”的列。这
modelsummary
网站解释了如何总结不支持的模型或自己添加对新模型的支持: https://modelsummary.com/articles/modelsummary.html

这些错误消息是在提取过程中生成的:

parameters::parameters(model)
未返回有效的data.frame。
broom::tidy(model)
未返回有效的data.frame。

avg_comparisons(rq_model,
                type = "response",
                variables = list(year = c(2018, 2022)),
                by = "variable3")

警告:无法从此模型中提取方差-协方差矩阵。

avg_predictions(rq_model,
                type = "response",
                byfun = median,
                newdata = "median",
                variables = list(year = c(2018, 2019, 2020, 2021, 2022)),
                by = c("year","variable3")) %>% 
                filter(variable3 == 1) %>% 
                select(year, estimate, conf.low, conf.high) %>% 
                mutate(round(across(2:4), 3)) %>% 
                gt::gt() %>% 
                gt::tab_header(title = "TITLE")

警告:无法从此模型中提取方差-协方差矩阵。

select()
中的错误: 无法选择不存在的列。 列
conf.low
不存在。 回溯:

  1. ...%>%...
  2. dplyr:::select.data.frame(.,年份,估计,conf.low,conf.high)

发生什么事了?当我将这三个变量添加到模型中时,为什么我的脚本不再起作用?这些错误和警告消息意味着什么?

提前谢谢您!

r modelsummary quantile-regression
1个回答
0
投票

http://www.leddelta.com 详细信息 Карт гратат буран и и и и и в из видео Кадры из видео

© www.soinside.com 2019 - 2024. All rights reserved.