0

I'm trying to use the VIP function in the plsVarSel in R.

> sessionInfo()

R version 3.4.4 (2018-03-15)  
Platform: x86_64-w64-mingw32/x64 (64-bit)  
Running under: Windows 10 x64 (build 16299)  

locale:
[1] LC_COLLATE=Danish_Denmark.1252  LC_CTYPE=Danish_Denmark.1252    LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C                   
[5] LC_TIME=Danish_Denmark.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plsVarSel_0.9.4 pls_2.6-0      

loaded via a namespace (and not attached):
 [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   
 [8] tools_3.4.4       mvtnorm_1.0-7     bdsmatrix_1.3-3   progress_1.1.2    genalg_0.2.0     

Trying to run the example code from the help page:

> pls  <- plsr(octane ~ NIR, ncomp = 10, validation = "LOO", data = gasoline)  
> comp <- which.min(pls$validation$PRESS)  
> vip <- VIP(pls, comp)
Error in diag(crossprod(TT)) : 
  could not find symbol "names" in environment of the generic function

I cannot make sense of the error message, but running the VIPfunction content line by line works fine. I therefore copy pasted the source code from the function to my own function, and it runs like a charm:

myOwnVIP <- function (pls.object, opt.comp, p = dim(pls.object$coef)[1]) 
{
  W <- pls.object$loading.weights
  Q <- pls.object$Yloadings
  TT <- pls.object$scores
  Q2 <- as.numeric(Q) * as.numeric(Q)
  Q2TT <- Q2[1:opt.comp] * diag(crossprod(TT))[1:opt.comp]
  WW <- W * W/apply(W, 2, function(x) sum(x * x))
  VIP <- sqrt(p * apply(sweep(WW[, 1:opt.comp, drop = FALSE], 
                              2, Q2TT, "*"), 1, sum)/sum(Q2TT))
  VIP
}
vip <- myOwnVIP(pls, comp)

Having a colleague running the example did not cause the same problems as mine, and the only difference we found was that when printing the function to the screen, her version had a bytecode - mine didn't. I'm very much outside my comfortzone here. Does it mean that my installation of plsVarSel is not compiled? What can I do about it? (restartning R, shutting down R and updating the packages has all been tried - no changes).

Here is my pint-to-screen of the function:

> VIP
function (pls.object, opt.comp, p = dim(pls.object$coef)[1]) 
{
    W <- pls.object$loading.weights
    Q <- pls.object$Yloadings
    TT <- pls.object$scores
    Q2 <- as.numeric(Q) * as.numeric(Q)
    Q2TT <- Q2[1:opt.comp] * diag(crossprod(TT))[1:opt.comp]
    WW <- W * W/apply(W, 2, function(x) sum(x * x))
    VIP <- sqrt(p * apply(sweep(WW[, 1:opt.comp, drop = FALSE], 
        2, Q2TT, "*"), 1, sum)/sum(Q2TT))
    VIP
}
<environment: namespace:plsVarSel>

I can off cause just hack it by defining my own versions - but it does bug me - I mean it should really work!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.