[R] missing data imputation

Frank E Harrell Jr f.harrell at vanderbilt.edu
Sat Jul 9 00:59:56 CEST 2005


Anders Schwartz Corr wrote:
> Dear R-help,
> 
> I am trying to impute missing data for the first time using R. The norm
> package seems to work for me, but the missing values that it returns seem
> odd at times -- for example it returns negative values for a variable that
> should only be positive. Does this matter in data analysis, and/or is
> there a way to limit the imputed values to be within the minimum and
> maximum of the actual data? Below is the code I am using.
> 
> Thanks,
> 
> Anders Corr
> Ph.D. Candidate

Yes that matters.  That's one reason I wrote the aregImpute function in 
the Hmisc package.  By default it uses predictive mean matching so it 
can't produce illegal values.

Frank

> 
> 
> #DOWNLOAD DATA (61Kb)
> download.file("http://www.people.fas.harvard.edu/~corr/tc.csv","C:/R")
> 
> #RUN NORM
> tc <- read.csv("tc.csv", header = TRUE)
> rngseed(1234567)   #set random number generator seed
> s  <-  prelim.norm(tc)
> thetahat <- em.norm(s)   #find the MLE for a starting value
> theta <- da.norm(s,thetahat,steps=20,showits=TRUE,return.ymis=TRUE)  #take 20 steps
> ximp <- imp.norm(s,thetahat,tc)  #impute missing data under the MLE
>
-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University




More information about the R-help mailing list