Multi-line main component in R

Hope I posted in the correct section! I am studying the MPCA method and I have questions because I am a beginner and just want to learn. There is a dataset where var values ​​have scale (sc) and nominal var (cat) When I do the analysis, I got an error. I uselibrary rTensor

library("openxlsx")
dat=read.xlsx("C:/Users/admin/Desktop/corr.xlsx")
View(dat)
mpca(dat, ranks=c(10,10), max_iter = 25, tol = 1e-05)

Error: is(tnsr, "Tensor") is not TRUE

      

What have I misunderstood? How to use this method correctly?

dat

+3


source to share


1 answer


The problem is that the function mpca()

only accepts objects of the tnsr

type as input. You have to convert your object dat

to contain data before in format matrix

and after in format tensor

.

Your current format looks like this:

class(dat)
[1] "data.frame"

      

So, you can transform in this way:



dat <- as.matrix(dat)
dat <- as.tensor(dat)
class(dat)
[1] "Tensor"
attr(,"package")
[1] "rTensor"

      

And then you can use the function mpca()

!

Hope this helps!

+3


source







All Articles