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

Failure in bootstrapped CI due to missing factor levels #52

Open
billdenney opened this issue May 17, 2021 · 0 comments · May be fixed by #53
Open

Failure in bootstrapped CI due to missing factor levels #52

billdenney opened this issue May 17, 2021 · 0 comments · May be fixed by #53

Comments

@billdenney
Copy link
Contributor

When factor levels are missing from a model, no surprise, it cannot predict rows with that factor level. The issue comes from the use of predict() in those models updated without all levels. The reprex below illustrates the issue.

set.seed(5)
library(ciTools)
#> ciTools version 0.6.1 (C) Institute for Defense Analyses
library(tidyverse)

my_data <-
  data.frame(
    counts=c(18,17,15,20,10,20,25,13,12),
    outcome=gl(3,1,9),
    treatment=gl(3,3)
  )

my_model <- glm(counts ~ outcome + treatment, data=my_data)

# Works because it is not using `predict()`
my_new_data <-
  my_data %>%
  add_ci(fit=my_model)

# Fails because data subsetting is not contingent on input factor levels
my_new_data <-
  my_data %>%
  add_ci(fit=my_model, type="boot")
#> Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels): factor treatment has new levels 2

Created on 2021-05-17 by the reprex package (v2.0.0)

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