scoreBased {mlmi} | R Documentation |
Score based variance estimation for multiple imputation
Description
This function implements the score based variance estimation approach described by von Hippel and Bartlett (2021), which is based on earlier work by Wang and Robins (1998).
Usage
scoreBased(imps, analysisFun, scoreFun, pd = NULL, dfComplete = NULL, ...)
Arguments
imps |
A list of imputed datasets produced by one of the imputation functions
in |
analysisFun |
A function to analyse the imputed datasets that when applied to
a dataset returns a list containing a vector |
scoreFun |
A function whose first argument is a dataset and whose second argument is a vector of parameter values. It should return a matrix of subject level scores evaluated at the parameter value passed to it. |
pd |
If |
dfComplete |
The complete data degrees of freedom. If |
... |
Other parameters that are to be passed through to |
Value
A list containing the overall parameter estimates, its corresponding covariance matrix, and degrees of freedom for each parameter.
References
Wang N., Robins J.M. (1998) Large-sample theory for parametric multiple imputation procedures. Biometrika 85(4): 935-948. doi:10.1093/biomet/85.4.935.
von Hippel P.T. and Bartlett J.W. Maximum likelihood multiple imputation: faster, more efficient imputation without posterior draws. Statistical Science 2021; 36(3) 400-420 doi:10.1214/20-STS793.
Examples
#simulate a partially observed dataset
set.seed(1234)
n <- 100
x <- rnorm(n)
y <- x+rnorm(n)
y[1:50] <- NA
temp <- data.frame(x,y)
#impute using normUniImp, without posterior draws
imps <- normUniImp(temp, y~x, M=10, pd=FALSE)
#define a function which performs our desired analysis on a dataset, returning
#the parameter estimates
yonx <- function(inputData) {
fitmod <- lm(y~x, data=inputData)
list(est=c(fitmod$coef,sigma(fitmod)^2))
}
#define a function which when passed a dataset and parameter
#vector, calculates the likelihood score vector
myScore <- function(inputData, parm) {
beta0 <- parm[1]
beta1 <- parm[2]
sigmasq <- parm[3]
res <- inputData$y - beta0 - beta1*inputData$x
cbind(res/sigmasq, (res*inputData$x)/sigmasq, res^2/(2*sigmasq^2)-1/(2*sigmasq))
}
#call scoreBased to perform variance estimation
scoreBased(imps, analysisFun=yonx, scoreFun=myScore)