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

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Feb 7 09:07:59 CET 2007


We still do not have reproducible code, but a 'dataframe' is not a matrix.
And I would expect a covariance matrix to have the same row and column 
names: the examples do.

On Wed, 7 Feb 2007, Alistair Campbell wrote:

> Thanks for that Brian,
>
> 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.

Well, the instructions to follow cov.wt seem obvious to me, and as I have 
said before, covariance matrices also work.

> 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list