Lucia
Lucia

Reputation: 647

Analysis of PCA

I'm using the rela package to check whether I can use PCA in my data.

paf.neur2 <- paf(neur2)
summary(paf.neur2)
# [1] "Your dataset is not a numeric object."

I want to see the KMO (The Kaiser-Meyer-Olkin measure of sampling adequacy test). How to do that?

Output of str(neur2)

  'data.frame': 1457 obs. of  66 variables:
   $ userid : int  200 387 458 649 931 991 1044 1075 1347 1360 ...
   $ funct  : num  3.73 3.79 3.54 3.04 3.81 ...
   $ pronoun: num  2.26 2.55 2.49 1.98 2.71 ...
      .
      .
      . 
   $ time   : num  1.68 1.87 1.51 1.03 1.74 ...
   $ work   : num  0.7419 0.2311 -0.1985 -1.6094 -0.0619 ...
   $ achieve: num  0.174 0.2469 0.1823 -0.478 -0.0513 ...
   $ leisure: num  0.2852 0.0296 0.0583 -0.3567 -0.0408 ...
   $ home   : num  -0.844 -0.58 -0.844 -2.207 -1.079 ...
      .

Variables are all numeric.

Upvotes: 1

Views: 698

Answers (2)

user3710546
user3710546

Reputation:

According to ?paf, object is a numeric dataset (usually a coerced matrix from a prior data frame)

So you need to turn your data.frame neur2 into a matrix: as.matrix(neur2).

Here is a reproduction of your problem using the Seatbelts dataset:

library(rela)

Belts <- Seatbelts[,1:7]
class(Belts)
# [1] "mts"    "ts"     "matrix"

Belts <- as.data.frame(Belts)
# [1] "data.frame"

paf.belt <- paf(Belts)
[1] "Your dataset is not a numeric object."

Belts <- as.matrix(Belts)
class(Belts)
# [1] "matrix"

paf.belt <- paf(Belts)  # Works

Upvotes: 4

Julian Wittische
Julian Wittische

Reputation: 1237

Two options which can do it for you:

kmo_DIY <- function(df){ 
csq = cor(df)^2 
csumsq = (sum(csq)-dim(csq)[1])/2 
library(corpcor) 
pcsq = cor2pcor(cor(df))^2 
pcsumsq = (sum(pcsq)-dim(pcsq)[1])/2 
kmo = csumsq/(csumsq+pcsumsq) 
return(kmo) 
} 

or

the function KMO() from the psych package.

Upvotes: 1

Related Questions