0

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....""


1 Answers1

0

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.

Vincent
  • 15,809
  • 7
  • 37
  • 39
  • Hi @vincent! Thank you for your help. I changed the estimate argument on the model summary part, but I am still struggling with the function argument on estimate, I am not sure how to ask it to only return the LATE values. – Caroline Cavallari Apr 10 '22 at 13:10
  • Now I get this error: Error in get_estimates(models[[j]], conf_level = conf_level, vcov = vcov[[i]], : `modelsummary could not extract the required information from a model of class "RD". The package tried a sequence of 2 helper functions to extract estimates: broom::tidy(model) parameters::parameters(model) To draw a table, one of these commands must return a `data.frame` with a column named "term". The `modelsummary` website explains how to summarize unsupported models or add support for new models yourself. – Caroline Cavallari Apr 10 '22 at 13:11
  • It looks like the class of your model is `RD` (try calling `class(ll1_covs)` to see. If that's the case, then your methods need to be called `tidy.RD` and `glance.RD`. Have you read the section on the website on how to add new models? It is quite comprehensive: https://vincentarelbundock.github.io/modelsummary/articles/modelsummary.html#adding-new-models-part-i – Vincent Apr 10 '22 at 20:10
  • Hi Vincent! Yes, I did!! I also altered the RD class, I missed that! – Caroline Cavallari Apr 12 '22 at 15:24
  • I tried extracting the values and turning into a df, but still getting an error 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: Do you have any examples of modelsummary with rdpackages? Thank you so much!! – Caroline Cavallari Apr 14 '22 at 08:45
  • Have you seen this one? https://stackoverflow.com/a/67823928/342331 – Vincent Apr 14 '22 at 12:47
  • Yes, I did! I used it and it worked perfectly for rdrobust, but doesn't work for rddpackage (this one: https://cran.r-project.org/web/packages/rdd/rdd.pdf) – Caroline Cavallari Apr 14 '22 at 13:27
  • Oops, sorry, I confused the two. I don't know the `rdd` package. Again, it would be much easier to help if your initial post had provided a full replicable, working example with actual code and data to estimate the model. See here for tips: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610 – Vincent Apr 14 '22 at 13:44