SHARE
TWEET

Untitled

a guest Jun 20th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. > sessionInfo()
  2.  
  3. R version 3.4.4 (2018-03-15)  
  4. Platform: x86_64-w64-mingw32/x64 (64-bit)  
  5. Running under: Windows 10 x64 (build 16299)  
  6.  
  7. locale:
  8. [1] LC_COLLATE=Danish_Denmark.1252  LC_CTYPE=Danish_Denmark.1252    LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C                  
  9. [5] LC_TIME=Danish_Denmark.1252    
  10.  
  11. attached base packages:
  12. [1] stats     graphics  grDevices utils     datasets  methods   base    
  13.  
  14. other attached packages:
  15. [1] plsVarSel_0.9.4 pls_2.6-0      
  16.  
  17. loaded via a namespace (and not attached):
  18.  [1] MASS_7.3-49       compiler_3.4.4    magrittr_1.5      assertthat_0.2.1  R6_2.4.0          prettyunits_1.0.2 parallel_3.4.4  
  19.  [8] tools_3.4.4       mvtnorm_1.0-7     bdsmatrix_1.3-3   progress_1.1.2    genalg_0.2.0
  20.      
  21. > pls  <- plsr(octane ~ NIR, ncomp = 10, validation = "LOO", data = gasoline)  
  22. > comp <- which.min(pls$validation$PRESS)  
  23. > vip <- VIP(pls, comp)
  24. Error in diag(crossprod(TT)) :
  25.   could not find symbol "names" in environment of the generic function
  26.      
  27. myOwnVIP <- function (pls.object, opt.comp, p = dim(pls.object$coef)[1])
  28. {
  29.   W <- pls.object$loading.weights
  30.   Q <- pls.object$Yloadings
  31.   TT <- pls.object$scores
  32.   Q2 <- as.numeric(Q) * as.numeric(Q)
  33.   Q2TT <- Q2[1:opt.comp] * diag(crossprod(TT))[1:opt.comp]
  34.   WW <- W * W/apply(W, 2, function(x) sum(x * x))
  35.   VIP <- sqrt(p * apply(sweep(WW[, 1:opt.comp, drop = FALSE],
  36.                               2, Q2TT, "*"), 1, sum)/sum(Q2TT))
  37.   VIP
  38. }
  39. vip <- myOwnVIP(pls, comp)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top