Reputation: 24623
I am using following code using mtcars data and factanal function for factor analysis. The print of fit$loadings give the proportional variance but it does not seem to be there in str(fit$loadings) :
> fit <- factanal(mtcars, 3, rotation="varimax")
> fit$loadings
Loadings:
Factor1 Factor2 Factor3
mpg 0.643 -0.478 -0.473
cyl -0.618 0.703 0.261
disp -0.719 0.537 0.323
hp -0.291 0.725 0.513
drat 0.804 -0.241
wt -0.778 0.248 0.524
qsec -0.177 -0.946 -0.151
vs 0.295 -0.805 -0.204
am 0.880
gear 0.908 0.224
carb 0.114 0.559 0.719
Factor1 Factor2 Factor3
SS loadings 4.380 3.520 1.578
Proportion Var 0.398 0.320 0.143 <<<<<<<<<<<<< I NEED THESE NUMBERS AS A VECTOR
Cumulative Var 0.398 0.718 0.862
>
> str(fit$loadings)
loadings [1:11, 1:3] 0.643 -0.618 -0.719 -0.291 0.804 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:11] "mpg" "cyl" "disp" "hp" ...
..$ : chr [1:3] "Factor1" "Factor2" "Factor3"
How can I get Proportional variance vector from fit$loadings? Thanks for your help.
Upvotes: 2
Views: 58
Reputation: 48251
Let obj <- fit$loadings
. Here is a complete path how to obtain the result.
By writing fit$loadings
(or obj
) we actually call print(obj)
. So, after looking at str
, you might want to check what does the specific print
method do with obj
. To know what method we should look for, we check class(obj)
and get "loadings"
.
Then, writing print.loadings
does not give anything because the function is hidden. Therefore, since function factanal
is in the package stats
, we call stats:::print.loadings
and get a complete source code of the function. By inspecting it, we see that we can get the desired result as follows.
colSums(obj^2) / nrow(obj)
# Factor1 Factor2 Factor3
# 0.3982190 0.3199652 0.1434125
Upvotes: 2