[R] princomp() with missing values in panel data?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Jan 19 14:36:31 CET 2006
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)) )
>> 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 at 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
More information about the R-help