Skip to content

mice.impute.quadratic bug?? #575

Open
@johamunoz

Description

@johamunoz

Dear all,

** Describe the issue:
I am trying to use the function mice.impute.quadratic in a binomial model. The function works when the outcome "y" is specified as a continuous variable but as soon as I specify it as a factor, I get an error. Is this function applicable for this scenario or is this a bug?

Please look at the following reproducible example
Thank you very much
Johanna

To Reproduce

Create data

N <- 500
Beta <- c(-2.3365665,0.8569439,0.3011304)
X <- runif(n=N, min=-3, max=3)
XX <- X^2
linear <- plogis(Beta[[1]]+Beta[[2]]*X + Beta[[3]]*XX)
Y <- rbinom(n = N, size = 1, prob = linear)
ID <- 1:N

dat <- data.frame(x = X, xx = XX, y = Y, ID = ID)

Ampute

patterns = rbind(c( 1, 1, 0, 1), c(0, 0, 1, 1), c(0, 0, 0, 1)) # (0=missing, 1=observed)
freq = c(1/3, 1/3,1/3) # ocurrence of patterns
mech = c("MAR")
weights = ampute.default.weights(patterns, mech) # Weights of weighted sum scores

data_inc <- ampute(data = dat,
patterns = patterns,
prop = prop, #Percentage of missing cells
freq = freq,
mech = mech,
weights=weights)$amp

Prepare data for imputation

ini <- mice(data_inc, maxit = 0)
meth <- c("quadratic", "~I(x^2)", "logreg","")
pred <- ini$pred
pred["x", "xx"] <- 0

Impute data with y as continuous

imp <- mice(data_inc, meth = meth, pred = pred, quad.outcome = "y")

Warning message:Type mismatch for variable(s): y Imputation method logreg is for categorical data.

Impute data with y as factor

data_inc $y<- as.factor(data_inc$y)
imp <- mice(data_inc, meth = meth, pred = pred, quad.outcome = "y")

iter imp variable1 1 xError in mice.impute.quadratic(y = c(-2.00387528445572, -0.957946232054383, : The name specified for the outcome in 'quad.outcome' can not be found in the data

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions