[R] factor score from PCA

Sarah Goslee sarah.goslee at gmail.com
Fri Oct 19 17:39:13 CEST 2012


>From ?princomp

Arguments:
scores: a logical value indicating whether the score on each
          principal component should be calculated.
Value:
  scores: if ‘scores = TRUE’, the scores of the supplied data on the
          principal components.  These are non-null only if ‘x’ was
          supplied, and if ‘covmat’ was also supplied if it was a
          covariance list.  For the formula method, ‘napredict()’ is
          applied to handle the treatment of values omitted by the
          ‘na.action’.

     ## NA-handling
     USArrests[1, 2] <- NA
     pc.cr <- princomp(~ Murder + Assault + UrbanPop,
                       data = USArrests, na.action=na.exclude, cor = TRUE)
     pc.cr$scores[1:5, ]


>From the help for psych:::principal:

Arguments:
  scores: If TRUE, find component scores
Value:
  scores: If scores=TRUE, then estimates of the factor scores are
          reported

So the scores are returned as pc$scores in your example, and princomp
will also calculate them.

Sarah

On Fri, Oct 19, 2012 at 11:30 AM, ya <xinxi813 at 126.com> wrote:
>
>
>
> Hi everyone,
>
> I am trying to get the factor score for each individual case from a principal component analysis, as I understand, both princomp() and prcomp() can not produce this factor score, the principal() in psych package has this option: scores=T, but after running the code, I could not figure out how to show the factor score results. Here is my code, could anyone give me some advice please? Thank you very much.
>
>> pc <- principal(a,rotate="varimax",scores=TRUE)
>> pc
> Principal Components Analysis
> Call: principal(r = a, rotate = "varimax", scores = TRUE)
> Standardized loadings (pattern matrix) based upon correlation matrix
>      PC1      h2   u2
> V1  0.80 6.4e-01 0.36
> V2  0.03 7.9e-04 1.00
> V3 -0.92 8.4e-01 0.16
> V4  0.00 2.0e-06 1.00
> V5  0.54 2.9e-01 0.71
>
>                 PC1
> SS loadings    1.77
> Proportion Var 0.35
>
> Test of the hypothesis that 1 component is sufficient.
>
> The degrees of freedom for the null model are  10  and the objective function was  0.87
> The degrees of freedom for the model are 5  and the objective function was  0.39
> The number of observations was  20  with Chi Square =  6.14  with prob <  0.29
>
> Fit based upon off diagonal values = 0.61
>
>> summary(pc)
>
> Factor analysis with Call: principal(r = a, rotate = "varimax", scores = TRUE)
>
> Test of the hypothesis that 1 factor is sufficient.
> The degrees of freedom for the model is 5  and the objective function was  0.39
> The number of observations was  20  with Chi Square =  6.14  with prob <  0.29
>
>
>

-- 
Sarah Goslee
http://www.functionaldiversity.org




More information about the R-help mailing list