[R] princomp() with missing values in panel data?
henric.nilsson at statisticon.se
Thu Jan 19 13:42:00 CET 2006
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.
> 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]]
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help