Message-ID: <47CBFB51.3060601@vanderbilt.edu>
Date: 2008-03-03T13:21:21Z
From: Frank E Harrell Jr
Subject: Studdy Missing Data, differentiate between a percent with in the valid answers and with in the different missing answers
In-Reply-To: <47CBBE99.4030109@stat.auckland.ac.nz>
James Reilly wrote:
> On 3/3/08 8:21 PM, Ericka Lundstr?m wrote:
> > I'm trying to emigrate from SPSS to R, thou I have some problems whit
> > getting R to distinguish between the different kind of missing.
> ...
> > Is there a smart way in R to differentiate between missing and valid
> > and at the same time treat both the categories within missing and
> > valid as answers (like SPSS did above)
>
>
> The Hmisc package has some support for special missing values, for
> instance when reading in SAS datasets using sas.get. I don't believe
> spss.get offers the same facility, though.
>
> You can define special missing values for a variable manually, which
> might seem a bit involved, but this could easily be automated. For your
> example, try:
>
> special <- dataFrame$TWO %in% c("?","X")
> attr(dataFrame$TWO, "special.miss") <-
> list(codes=as.character(dataFrame$TWO[special]),
> obs=(1:length(dataFrame$TWO))[special])
> class(dataFrame$TWO) <- c("factor", "special.miss")
> is.na(dataFrame$TWO) <- special
>
> # Then describe gives new percentages
>
> describe(dataFrame$TWO)
> dataFrame$TWO
> n missing ? X unique
> 3 4 2 2 2
>
> No (2, 67%), yes (1, 33%)
>
> HTH,
> James
Thanks for pointing out how this can be done with Hmisc, James. If the
foreign package can sense SPSS special missing values in general, it
would not be hard to add the special.miss mechanism to spss.get in Hmisc.
Frank
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University