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

From: Henric Nilsson <>
Date: Thu 19 Jan 2006 - 23:42:00 EST

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= 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 `', 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.

> Incidentally, R is a lot cleverer than I understand. pc$loadings by itself

Sometimes R is almost too clever, and I end up feeling humliated when finding out that I'm the stupid one... ;-)


> gives me wonderfully intuitive output, with names, text, different
> components---but I can still use p$loadings[,2]. I presume that the array
> operator on the "loadings" object is overloaded. very nice.
> [[alternative HTML version deleted]]
> ______________________________________________
> mailing list
> PLEASE do read the posting guide! mailing list PLEASE do read the posting guide! Received on Fri Jan 20 00:08:35 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:06 EST