[R] Factor Analysis in R

Gavin Simpson gavin.simpson at ucl.ac.uk
Sat Aug 8 14:32:05 CEST 2009


On Sat, 2009-08-08 at 17:38 +0530, Arup Pramanik wrote:
> hi,
> 
> Thanks for your reply but now it is giving me a message that Error in
> factanal(~., data = sony_factor, factors = 10, na.action = na.omit) : 
>   factor analysis applies only to numerical variables. All the
> variable which I am having are numeric in nature..What should I do
> next? Shall I try as.numeric(mydata) then also the error is coming
> "Error: (list) object cannot be coerced to type 'double'. Thanks.

1) Please don't send personal requests; keep replies on list, when
requesting further help.
2) You haven't read or complied with the posting guide, providing none
of the requested information.

The error is telling you that as far as R is concerned, some of your
data are not considered numeric. R doesn't care what /you/ think your
data are, only what /it/ thinks they are.

Look at the output of

str(sony_factor)

and if any of the variables are not numeric, sort out why it isn't a
numeric, or convert it to one.

You can't convert a data.frame to numeric as the second error is telling
you. You can convert the *components* of the data.frame to numerics, for
example

foo$bar <- as.numeric(foo$bar)

or

foo <- within(foo, bar <- as.numeric(bar))

But that isn't sufficient for factors, you need to convert to character
then to numeric:

foo$bar <- as.numeric(as.character(foo$bar))

or

foo <- within(foo, bar <- as.numeric(as.character(bar)))

HTH

G

> 
> Regards,
> 
> Arup 
> 
> 
> 
> On Sat, Aug 8, 2009 at 5:18 PM, Gavin Simpson
> <gavin.simpson at ucl.ac.uk> wrote:
>         On Fri, 2009-08-07 at 19:07 -0700, Arup wrote:
>         > Hi I am trying to run Factor Analysis using R...I am using
>         the syntax
>         > factanal(m1, factors=3)  but it's giving me an message Error
>         in cov.wt(z) :
>         > 'x' must contain finite values only
>         >  ...I am using a data set which is having only numeric
>         variables and have
>         > some NA's also in it..What should I do next..Someone please
>         help me out with
>         > the syntax..Thanks in advance
>         
>         
>         NA's are *not* finite, we don't know what value they are.
>         
>         Read ?factanal
>         
>         If you specify the model with a formula, you can use the
>         'na.action'
>         argument to tell it what to do with missing values. Something
>         like,
>         
>         factanal(~ ., data = m1, factors = 3, na.action = na.omit)
>         
>         or do this yourself with
>         
>         factanal(na.omit(m1), factors = 3)
>         
>         HTH
>         
>         G
>         
>         --
>         %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~
>         %~%~%~%
>          Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
>          ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
>          Pearson Building,             [e]
>         gavin.simpsonATNOSPAMucl.ac.uk
>          Gower Street, London          [w]
>         http://www.ucl.ac.uk/~ucfagls/
>          UK. WC1E 6BT.                 [w]
>         http://www.freshwaters.org.uk
>         %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~
>         %~%~%~%
>         
> 
> 
> 
> 
> 
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%




More information about the R-help mailing list