如何将Modelsummary与rddpackage一起使用?

发布于 2025-01-20 02:44:33 字数 1044 浏览 3 评论 0原文

我正在尝试将我的RDDS模型从RDD软件包输入到模型摘要中,而我不能。 这是我的代码:

rdd_model_names <- paste0("model", 1:8)
  rdd_model <- list(ll1_covs, ll1_no_covs, ll2_covs, ll2_no_covs, ll3_covs, ll3_no_covs, ll4_covs, ll4_no_covs)
 
  tidy.RD <- function(rdd_model, nm) {
  s <- summary(rdd_model)
  df <- data.frame(s$coefficients[1, c(1:4,6), drop = FALSE])
  print(class(df))
  df$term <- nm
  df
}
 rd_outputs <- lapply(1:8, function(i) tidy.RD(rdd_model[[i]], rdd_model_names[i]) ) %>% bind_rows()     
 rd_outputs
    
rdd_table <- modelsummary(rd_outputs, statistic = "p.value") %>%
  kable_styling(bootstrap_options = c("striped", "hover")) %>%
  add_header_above(c(" "= 2, "Female Share" = 2, "Pre-natal care"= 2, "Daycare enroll" = 2, "Pre-scool enroll" = 2))  ```


""The error that I get is:
Warning in get_gof(models[[j]], vcov_type[[i]], ...) :
  `modelsummary could not extract goodness-of-fit statistics from a model
of class "data.frame". The package tried a sequence of 2 helper functions....""


I am trying to input my rdds model from rdd package into model summary and I can't.
This is my code:

rdd_model_names <- paste0("model", 1:8)
  rdd_model <- list(ll1_covs, ll1_no_covs, ll2_covs, ll2_no_covs, ll3_covs, ll3_no_covs, ll4_covs, ll4_no_covs)
 
  tidy.RD <- function(rdd_model, nm) {
  s <- summary(rdd_model)
  df <- data.frame(s$coefficients[1, c(1:4,6), drop = FALSE])
  print(class(df))
  df$term <- nm
  df
}
 rd_outputs <- lapply(1:8, function(i) tidy.RD(rdd_model[[i]], rdd_model_names[i]) ) %>% bind_rows()     
 rd_outputs
    
rdd_table <- modelsummary(rd_outputs, statistic = "p.value") %>%
  kable_styling(bootstrap_options = c("striped", "hover")) %>%
  add_header_above(c(" "= 2, "Female Share" = 2, "Pre-natal care"= 2, "Daycare enroll" = 2, "Pre-scool enroll" = 2))  ```


""The error that I get is:
Warning in get_gof(models[[j]], vcov_type[[i]], ...) :
  `modelsummary could not extract goodness-of-fit statistics from a model
of class "data.frame". The package tried a sequence of 2 helper functions....""


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨后咖啡店 2025-01-27 02:44:33

再看一下错误:

*Assertion failed. One of the following must apply:
    checkmate::check_character(estimate): Must have length 1, but has length 3
    checkmate::check_character(estimate): Must have length 8, but has length 3*

这是指 estimate 参数,它表示它的长度应该是 1 或长度 8。这是因为您的列表中有 8 个模型。因此,您要么只为估计提供一个值,要么为每个模型提供 1 个值。您提供了 3,它不满足任何一个条件。

Look at the error again:

*Assertion failed. One of the following must apply:
    checkmate::check_character(estimate): Must have length 1, but has length 3
    checkmate::check_character(estimate): Must have length 8, but has length 3*

This refers to the estimate argument, and it says that it should be either of length 1 or of length 8. This is because there are 8 models in your list. So either you supply only one value for estimate, or you supply 1 value per model. You supplied 3, which does not fulfill either of the conditions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文