mediation icon indicating copy to clipboard operation
mediation copied to clipboard

Error in stats::model.frame when specifying a glm formula in a function argument, and boot = T

Open grasshoppermouse opened this issue 3 years ago • 2 comments

This works fine with boot=F, but throws an error when boot=T. A real corner case, I admit:

library(mediation)
#> mediation: Causal Mediation Analysis
#> Version: 4.5.0
test <- function(f1, f2, boot){
  mtcars$mpg <- mtcars$mpg/max(mtcars$mpg)
  m_med <- glm(f1, family=binomial, mtcars)
  m_out <- glm(f2, family=binomial, mtcars)
  mediate(m_med, m_out, treat = "wt", mediator = 'am', boot = boot)
}

x <- test('am ~ wt', 'mpg ~ wt + am', F)
#> Warning in eval(family$initialize): non-integer #successes in a binomial glm!
x <- test('am ~ wt', 'mpg ~ wt + am', T)
#> Warning in eval(family$initialize): non-integer #successes in a binomial glm!
#> Running nonparametric bootstrap
#> Error in stats::model.frame(formula = f1, data = structure(list(am = c(1, : object 'f1' not found

Created on 2021-03-17 by the reprex package (v0.3.0)

grasshoppermouse avatar Mar 18 '21 00:03 grasshoppermouse

I'm seeing the same with an lm model. created a new issue #32

pinusm avatar Jun 03 '21 07:06 pinusm

Hi @grasshoppermouse, I'm having a similar issue. I wonder whether you have found any solutions? If yes, would you mind sharing it with us?

ianaianawong avatar Aug 02 '23 14:08 ianaianawong