[R] How-To construct a cov list to use a covariance matrix in factanal?

William Revelle lists at revelle.net
Wed Feb 7 02:59:22 CET 2007


Alistair,


>
>I have worked through the examples. They work because the covmat 
>were produced by the cov.wt which provides output as a list object. 
>I am trying to construct my own list object to use as the covmat. 
>There are no obvious instructions on how to do this.
>
>So, here is what I have done so far.
>
>I reconstructed the covariance matrix in the example and created a dataframe:
>
>  > testmatrix
>   general picture  blocks   maze reading   vocab
>1  24.641   5.991  33.520  6.023  20.755  29.701
>2   5.991   6.700  18.137  1.782   4.936   7.204
>3  33.520  18.137 149.831 19.424  31.430  50.753
>4   6.023   1.782  19.424 12.711   4.757   9.075
>5  20.755   4.936  31.430  4.757  52.604  66.762
>6  29.701   7.204  50.753  9.075  66.762 135.292
>
>and then used this to construct a list object like the output from 
>the example;
>
>>  tstcov<- list(cov=testmatrix, center=c(0,0,0,0,0), n.obs=112)
>
>I tested to see whether my list object looked like the examples
>
>>  tstcov
>$cov
>   general picture  blocks   maze reading   vocab
>1  24.641   5.991  33.520  6.023  20.755  29.701
>2   5.991   6.700  18.137  1.782   4.936   7.204
>3  33.520  18.137 149.831 19.424  31.430  50.753
>4   6.023   1.782  19.424 12.711   4.757   9.075
>5  20.755   4.936  31.430  4.757  52.604  66.762
>6  29.701   7.204  50.753  9.075  66.762 135.292
>
>$centers
>[1] 0 0 0 0 0
>
>$n.obs
>[1] 112
>
>It looks the same. So I then used this list as the argument in 
>factanal and get the error message.
>
>>  factanal(factors=2, covmat=tstcov, rotation="varimax")
>Error in sqrt(diag(cv)) : Non-numeric argument to mathematical function
>
>I know that what you see of a list is not necessarily all that is 
>there. So, I figure I am missing some part of the object that makes 
>this list suitable for use by factanal.
>
So, I hope this is enough detail. Any thoughts would be appreciated.
>--
>Dr Alistair Campbell, PhD
>Senior Lecturer in Clinical Psychology
>School of Psychology
>James Cook University
Townsville Queensland Australia



The call to factanal requires you to specify that you have a 
covariance matrix (covmat).  Using your matrix and specifying two 
factors:


test.df
   general picture  blocks   maze reading   vocab
1  24.641   5.991  33.520  6.023  20.755  29.701
2   5.991   6.700  18.137  1.782   4.936   7.204
3  33.520  18.137 149.831 19.424  31.430  50.753
4   6.023   1.782  19.424 12.711   4.757   9.075
5  20.755   4.936  31.430  4.757  52.604  66.762
6  29.701   7.204  50.753  9.075  66.762 135.292
>  test.mat <- as.matrix(test.df)
>  tf <- factanal(factors=2,covmat=test.mat)
>  tf

Call:
factanal(factors = 2, covmat = test.mat)

Uniquenesses:
general picture  blocks    maze reading   vocab
   0.455   0.589   0.218   0.769   0.052   0.334

Loadings:
   Factor1 Factor2
1 0.499   0.543 
2 0.156   0.622 
3 0.206   0.860 
4 0.109   0.468 
5 0.956   0.182 
6 0.785   0.225 

                Factor1 Factor2
SS loadings      1.858   1.724
Proportion Var   0.310   0.287
Cumulative Var   0.310   0.597

The degrees of freedom for the model is 4 and the fit was 0.0572

Bill

>

-- 
William Revelle		http://pmc.psych.northwestern.edu/revelle.html   
Professor			http://personality-project.org/personality.html
Department of Psychology       http://www.wcas.northwestern.edu/psych/
Northwestern University	http://www.northwestern.edu/



More information about the R-help mailing list