Hi all,
I’m switching over from {pls}
to {mixOmics}
and am having a hard time completing the transition - specifically, difficulty obtaining regression coefficients.
In {pls}
I would do the following:
mod1 <- pls::plsr(mpg ~ .,
data = mtcars,
ncomp = 3,
scale = TRUE,
center = TRUE)
coef(mod1)
#> , , 3 comps
#>
#> mpg
#> cyl -0.6315124
#> disp -0.6633487
#> hp -0.9388964
#> drat 0.5148309
#> wt -1.5341138
#> qsec 0.1051610
#> vs 0.1929931
#> am 1.0338038
#> gear 0.2979549
#> carb -1.3102833
#>
How do I get the vector of coefficients in {mixOmics}
?
mod2 <- mixOmics::spls(X = mtcars[,-1], Y = mtcars[,1],
ncomp = 3,
scale = TRUE)
Just to demonstrate that these models are equivalent - they give identical predictions(which is why I expect them to give the same coefficients):
predict(mod1, newdata = mtcars[1:2,])[,,3]
#> Mazda RX4 Mazda RX4 Wag
#> 22.41019 22.04333
predict(mod2, newdata = mtcars[1:2,-1])$predict[,,3]
#> Mazda RX4 Mazda RX4 Wag
#> 22.41019 22.04333