[R] about correctness of calculated factor scores in robCompositions

Hamid h@m|d200356 @end|ng |rom gm@||@com
Sun Apr 24 22:42:30 CEST 2022


Please have a look at  the factor scores returned from robCompositions
package  in this example:

data(expenditures)
x <- expenditures

 res.rob <- pfa(x, factors=1, score="regression")


according to ?pfa since the covariance  is not specified,
the covariance is estimated from isometric log-ratio transformed data
internally, but the data used for factor analysis are backtransformed
to the clr space.

So the clr transformed data obtain as follows:

# ilr transformation
ilr <- function(x){
x.ilr=matrix(NA,nrow=nrow(x),ncol=ncol(x)-1)
  for (i in 1:ncol(x.ilr)){
    x.ilr[,i]=sqrt((i)/(i+1))*log(((apply(as.matrix(x[,1:i]), 1,
prod))^(1/i))/(x[,i+1]))
  }
return(x.ilr)
}

# construct orthonormal basis: (matrix with ncol(x) rows and ncol(x)-1
columns)
V=matrix(0,nrow=ncol(x),ncol=ncol(x)-1)
for (i in 1:ncol(V)){
  V[1:i,i] <- 1/i
  V[i+1,i] <- (-1)
  V[,i] <- V[,i]*sqrt(i/(i+1))
}
z=ilr(x) #ilr transformed data
y=z%*%t(V) #clr transformed data
now the factor scores using regression method might be calculated as
follows:

 loa<-c(0.970,0.830,0.986,0.876,0.977)  #res.rob object

facscores<- y%*%loa

> head(facscores)
             [,1]
[1,] -0.009485110
[2,]  0.009680645
[3,]  0.008426665
[4,] -0.015401000
[5,] -0.003610644
[6,] -0.004584145

but calling res.rob$scores returns us
head(res.rob$scores)
> head(res.rob$scores)
       Factor1
[1,] -755.2681
[2,]  705.5309
[3,] 4196.5652
[4,] -778.6955
[5,] -628.2141
[6,] -663.4534

So please check am I wrong or there is probably  a bug in the pfa command ?
Yours,
Hamid

	[[alternative HTML version deleted]]



More information about the R-help mailing list