Learn R Programming

RMC (version 0.2)

MVfill: Fill in missing values via a single imputation from the fitted model.

Description

Inserts the fitted probability of observing the chained data used in estimation for the model (fm). To be used when the outcome variable is used as a covariate at subsequent stages of an analysis. The fitted probability is conditional on the nearest observed value in the chain.

Usage

MVfill( fm, states=NULL, chain.id=NULL, X=NULL)

Arguments

fm
a fitted model for the outcome that is required to be filled. Must be the result of a call to RMC.mod
states
the outcome vector used to estimate the fitted model. Must be sequentially ordered within chains
chain.id
a vector indicating which states belong to which chains
X
the design matrix for the model used to create fm. Column ordering must match that provided to fm and row ordering must match that in states (and chain.id)

Value

References

Foster, S.D., Bravington, M.V., Williams, A., Althaus, F, Laslett, G.M., and Kloser, R.J. (2008) Analysis and prediction of faunal distributions from video and multi-beam sonar data using Markov models. Environmetrics, 20: 541-560.

Examples

Run this code
#form data with NAs in the outcomes
dataEG2.NA <- dataEG2
dataEG2.NA[sample(1:nrow( dataEG2.NA), 1000),"state"] <- NA	#specify lots of NAs
#fit a model using dataEG2.NA
fm.est2.NA <- RMC.mod( states=dataEG2.NA[,2], chain.id=dataEG2.NA[,1], X=dataEG2.NA[,-(1:2)])
#impute the missing values. The result will be a matrix
imputedData <- MVfill( fm.est2.NA, states=dataEG2.NA[,2], chain.id=dataEG2.NA[,1], X=dataEG2.NA[,3:4])
print( head( imputedData, 20))

Run the code above in your browser using DataLab