[R] Questions on formula in princomp

Gabor Grothendieck ggrothendieck at gmail.com
Fri Apr 14 21:30:46 CEST 2006


Just use model.frame to examine what is passed:

> ir <- rbind(iris3[,,1], iris3[,,2], iris3[,,3])
> lir <- data.frame(log(ir))
> names(lir) <- c("a","b","c","d")
> lir[1,1] <- NA
> mf <- model.frame(~., lir,na.action=na.omit)
> head(mf)
         a        b         c          d
2 1.589235 1.098612 0.3364722 -1.6094379
3 1.547563 1.163151 0.2623643 -1.6094379
4 1.526056 1.131402 0.4054651 -1.6094379
5 1.609438 1.280934 0.3364722 -1.6094379
6 1.686399 1.360977 0.5306283 -0.9162907
7 1.526056 1.223775 0.3364722 -1.2039728
> head(lir)
         a        b         c          d
1       NA 1.252763 0.3364722 -1.6094379
2 1.589235 1.098612 0.3364722 -1.6094379
3 1.547563 1.163151 0.2623643 -1.6094379
4 1.526056 1.131402 0.4054651 -1.6094379
5 1.609438 1.280934 0.3364722 -1.6094379
6 1.686399 1.360977 0.5306283 -0.9162907

On 4/14/06, Sasha Pustota <popgen at gmail.com> wrote:
> Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> > Sasha Pustota <popgen at gmail.com> wrote:
> > > ir <- rbind(iris3[,,1], iris3[,,2], iris3[,,3])
> > > lir <- data.frame(log(ir))
> > > names(lir) <- c("a","b","c","d")
> > >
> > > I'm trying to understand the meaning of expressions like "~ a+b+c+d",
> > > used with princomp, e.g.
> > > princomp(~ a+b+c+d, data=lir, cor=T)
> > > By inspection, it looks like the result is the same as in
> > > princomp(lir, cor = T).
> >
> > Yes, princomp.formula just takes the model matrix of the formula
> > and passes it to princomp.default.
>
> Thanks. A further question. If I set some values to NA, a call
>
> princomp(~., data=mir, cor=T, na.action=na.omit)$scores
>
> indicates there have been predicted values imputed in place of NA.
> The documentation says 'napredict' is used but I can't find details.
> My guess is that these are predicted from linear multiple regression
> of other columns on NAs. However, what method is used exactly, in
> the case of princomp?  (and how do I find out these things?)
>
> ______________________________________________
> R-help at 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
>




More information about the R-help mailing list