inla.rgeneric.milm.model | R Documentation |
Multiple imputation using a linear regression model. The response may have missing values to be imputed, but the covariates must be fully observed.
inla.rgeneric.milm.model(
cmd = c("graph", "Q", "mu", "initial", "log.norm.const", "log.prior", "quit"),
theta = NULL
)
cmd |
Arguments used by latent effects defined using the 'rgeneric' latent effect. |
theta |
Vector of hyperparameters. |
This function used is used to define a latent effect that is a linear term on some covariates with missing observations. However, multiple imputation is performed on the missing values of the covariates internally using another linear model. For this reason, this package requires the following arguments when defining the latent effect:
x Vector of covariates (with missing observations).
XX Matrix of covariates to be used in the multiple imputation linear model. Must be fully observed.
n Number of observations.
idx.na Index with the positions of the missing observations.
This model is defined using the 'f()' function and an index of NA
's
is set so that imputation is done but the covariate not included in the
actual model. Then, this latent effect is 'copied', which makes the
covariates (observed and imputed values) into a linear term in the liner
predictor. See the example.
This is used internally by the 'INLA::inla()'.
library(INLA)
library(MIINLA)
library(mice)
data(nhanes)
nhanes$age1 <- as.numeric(nhanes$age == 1)
nhanes$age2 <- as.numeric(nhanes$age == 2)
nhanes$age3 <- as.numeric(nhanes$age == 3)
# Standard model (if bmi == NA then the term is not included in l.pred.)
m0 <- inla(chl ~ bmi, data = nhanes, control.predictor = list(compute = TRUE))
summary(m0)
# Imputation model on 'bmi'
r.imp <- inla(bmi ~ age2 + age3, data = nhanes, control.predictor = list(compute = TRUE))
summary(r.imp)
# Define imputation model
model <- inla.rgeneric.define(inla.rgeneric.milm.model, debug = TRUE,
x = nhanes$bmi,
XX = cbind(1, nhanes$age2, nhanes$age3),
n = nrow(nhanes),
idx.na = which(is.na(nhanes$bmi)))
nhanes$idx <- rep(NA, nrow(nhanes))
nhanes$idx2 <- 1:nrow(nhanes)
formula = chl ~ 1 + f(idx, model = model) + f(idx2, copy = "idx", fixed = FALSE,
hyper = list(beta = list(prior = "normal", param = c(0, 0.001))))
#Joint model: main model + imputation of missing covariates
r = inla(formula, data = nhanes[, c("chl", "idx", "idx2")],
family = "gaussian",
verbose = TRUE,
control.family = list(hyper = list(prec = list(param = c(0.01, 0.01)))),
control.fixed = list(prec.intercept = 0.001))
summary(r)
r.imp$summary.fitted.values[, "mean"]
r$summary.random$idx[, "mean"]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.