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 due to update with add_ci(type="boot") #50

Closed
billdenney opened this issue May 17, 2021 · 0 comments · Fixed by #51
Closed

Failure due to update with add_ci(type="boot") #50

billdenney opened this issue May 17, 2021 · 0 comments · Fixed by #51

Comments

@billdenney
Copy link
Contributor

Thank you for the wonderful package!

I am a new user, and I'm having an issue with a model that I fit in one environment and need to use ciTools in another environment. My general use case is illustrated by the reprex below:

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=rep(1:3, 3),
    treatment=rep(1:3, each=3)
  )

fit_my_data <- function(my_data_in_the_function) {
  link <- "log"
  glm.D93 <- glm(counts ~ outcome + treatment, data=my_data_in_the_function, family=gaussian(link=link))
  glm.D93
}

my_model <- fit_my_data(my_data)

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

# Fails because `link` is not set in the current environment (it is only set in
# the function environment)
my_new_data <-
  my_data %>%
  add_ci(fit=my_model, type="boot")
#> Error in gaussian(link = link): object 'link' not found

# Works because now the call doesn't rely on the link from the current
# environment; the link comes from the model family.
my_model_update <- my_model
my_model_update$call$family <- my_model$family
my_new_data <-
  my_data %>%
  add_ci(fit=my_model_update, type="boot")
#> Warning in predict.lm(object, newdata, se.fit, scale = 1, type = if (type == :
#> prediction from a rank-deficient fit may be misleading

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