Re: [R] princomp() with missing values in panel data?

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri 20 Jan 2006 - 00:36:31 EST

On Thu, 19 Jan 2006, Henric Nilsson wrote:

> ivo welch said the following on 2006-01-18 14:56:
>
>> thank you. I am still not sure how to get the scores in princomp, though:
>>
>> ds= as.data.frame( cbind(rnorm(10),rnorm(10)) )
>> names(ds)=c("x1","x2")
>> ds[5,]=c(NA,NA)
>> pc= princomp( formula = ~ ds$x1 + ds$x2, na.action=na.omit)
>> ds$pc1 = pc$scores[,1] #<-- error, scores has 9 obs, ds has 10 obs
>>
>> is there an elegant method to do this, or do I need to learn how to operate
>
> Prof Ripley told you how to do it: `na.action = na.exclude'.
>
>> with pc$loadings? (may I also humbly suggest that the default behavior or
>> $scores should be to contain NA in row 5?)
>
> Choosing sensible defaults in the case of NAs is a tricky business.
>
> Personally, I'd like the default to be `na.fail', so that I don't miss
> out on NAs if I've been sloppy while screening the data. Genrally, just
> ignoring missings and analysing the data as if it were complete may lead
> to seriously biased results.

I tend to agree (and so does S). You can achieve this with options(na.action=na.fail), almost everywhere.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Jan 20 00:52:07 2006

This archive was generated by hypermail 2.1.8 : Fri 20 Jan 2006 - 02:16:49 EST