Open IsadoraBM opened 4 years ago
Hmmm, odd. Can you provide the code that you used that caused the error?
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"))
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