[R] problem with pls(x, y, ..., ncomp = 16): Error in inherit s( x, "data.frame") : subscript out of bounds

Liaw, Andy andy_liaw at merck.com
Wed Dec 10 05:14:45 CET 2003


My first guess was wrong (should have RTFM...).  Try:

  m <- pls(x, y, validation = "CV", niter = 68, ncomp = 1:16)

I'm not familiar enough with SIMPLS to know whether it makes sense to pass
ncomp of length 1 to pls(), but the code as is won't work (unless ncomp=1).
The problem is in the following two lines inside simpls():

 YvarExpl <- matrix(0, length(ncomp), npred)
 for (i in 1:max(ncomp)) YvarExpl[i, ] <- diag(cor(Y, X %*% B[, , i]))^2

If ncomp is of length 1, then YvarExpl is a 1x1 matrix, so the loop will
bomb if ncomp > 1.

[I'm CC'ing Prof. Wehrens, who is the package maintainer.]

HTH,
Andy

> From: ryszard.czerminski at pharma.novartis.com 
> 
> Help for pls says:
> 
> > ?pls
> [...]
> Arguments:
> ...
>    ncomp: the numbers of latent variables to be assessed in the
>           modelling. Default is from one to the rank of 'X'.
> [...]
> 
> so my assumption was (maybe wrong) that idea of ncomp parameter is to 
> limit
> number of assessed variables.
> 
> also, if called without crossvalidation it gives the same error:
> 
> > m <- pls(x, y, ncomp = 16)
> Error in inherits(x, "data.frame") : subscript out of bounds
> 
> R
> 
> "Liaw, Andy" <andy_liaw at merck.com>
> 
> I don't know the details of pls (in the pls.pcr package, I 
> assume), but if
> you use validation="CV", that says you want to use CV to 
> select the best
> number of components.  Then why would you specify ncomp as well?
> 
> Andy
> 
> > From: ryszard.czerminski at pharma.novartis.com
> > 
> > When I try to use ncomp parameter in pls procedure  I get 
> > following error:
> > 
> > > library(pls.pcr)
> > > m <- pls(x, y, validation = "CV", niter = 68, ncomp = 16)
> > Error in inherits(x, "data.frame") : subscript out of bounds
> > 
> > Without ncomp parameter everything seems to work OK
> > 
> > > dim(x)
> > [1]  68 116
> > > dim(y)
> > [1] 68  1
> > > m <- pls(x, y, validation = "CV", niter = 68)
> > > length(m$ncomp)
> > [1] 67
> > 
> > Ryszard
> > 
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> > 
> > 
> 
> 
> 
> 
> 
> 
>




More information about the R-help mailing list