Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predictors argument not supported in coefplot.glm #22

Open
IsadoraBM opened this issue Oct 9, 2020 · 2 comments
Open

Predictors argument not supported in coefplot.glm #22

IsadoraBM opened this issue Oct 9, 2020 · 2 comments

Comments

@IsadoraBM
Copy link

coefplot.glm produces graph when not specifying predictors but adding it produces:
Error in $<-.data.frame(tmp, ".Type", value = c(DV= "factor", : replacement has 11 rows, data has 10

@jaredlander
Copy link
Owner

Hmmm, odd. Can you provide the code that you used that caused the error?

@IsadoraBM
Copy link
Author

IsadoraBM commented Oct 9, 2020

Yes I see the issue is the glm has weights. If they are removed it works. Here's a reproducible example

library(politicaldata)
library(janitor)
Pres <- pres_results
Pres %<>% mutate(Swing=case_when(
  dem >.50 ~ "Democratic",
  rep >.50 ~ "Republican",
TRUE ~ "Tossup"),
`SwingDemocratic`=case_when(
  dem >.50 ~ 1,
  rep >.50 ~ 0,
  TRUE ~ NA_real_,
))
House <- house_results
House %<>% rename("HouseDem"="dem", "HouseRep"="rep",
  "state"="state_abb")
Pres %<>% right_join(House, by = c("year", "state"))
Pres %<>% mutate(`House` = case_when(
  HouseDem>.5 ~ "HouseDem",
  HouseRep>.5~ "HouseRep",
  TRUE~ "Tossup"))
Pres %<>% mutate(HouseDivided = case_when(
  dem >.50 & HouseDem>.5 ~ "No",
  rep >.50 & HouseRep>.5~ "No",
  TRUE ~ "Yes"))

Pres %<>% mutate(confidence = 
                   sample(0:1, size = nrow(Pres), replace = TRUE), 
                 weights = sample(0:1, size = nrow(Pres), replace = TRUE)
                 )

lm <- glm(SwingDemocratic~confidence+HouseDivided,
          data = Pres, family = binomial, weights = weights)
coefplot.glm(title = "", model = lm, innerCI = 0,
             intercept = FALSE, predictors = c("confidence"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants