如何用R与plsr得到权重矩阵?

时间:2016-08-30 06:12:25

标签: r matrix least-squares

我在R中使用plsr包,使用SIMPLS方法,但这没有给我权重矩阵W,有人可以帮助我,并告诉我如何创建或获得这个W矩阵?这是我的代码的一部分:

plsr(Y ~ X, ncomp, validation = "CV", dframe = T, method = "SIMPLS")

我需要W矩阵来实现VIP方法。

1 个答案:

答案 0 :(得分:0)

List<Character> letters = string.chars()
    .mapToObj(i -> (char) i)
    .filter(Character::isAlphabetic)
    .collect(Collectors.toList());

我们可以通过以下方式访问原始权重:

library(pls) #only for preloaded data
library(plsdepot)
plsreg1(yarn$NIR, yarn$density) #using preloaded yarn dataset from pls library

PLS Regression 1
--------------------------------------------
$x.scores     X-scores (T-components)
$x.loads      X-loadings
$y.scores     Y-scores (U-components)
$y.loads      Y-loadings
$cor.xyt      score correlations
$raw.wgs      raw weights
$mod.wgs      modified weights
$std.coefs    standard coefficients
$reg.coefs    regular coefficients
$R2           R-squared
$R2Xy         explained variance of X-y by T
$y.pred       y-predicted
$resid        residuals
$T2           T2 hotelling
$Q2           Q2 cross validation
--------------------------------------------

#Example of first 5 rows of weights matrix. head(plsreg1(yarn$NIR, yarn$density)$raw.wgs #or plsreg1(yarn$NIR, yarn$density)[6] w1 w2 X1 0.01716477 -0.04809644 X2 0.03875600 -0.06025352 X3 0.04857839 -0.06807797 X4 0.05023674 -0.07540982 X5 0.04571729 -0.08515648 X6 0.03690089 -0.09647263

也是如此