[R] Pls package

Bjørn-Helge Mevik b.h.mevik at usit.uio.no
Mon Aug 31 12:25:12 CEST 2009


Payam Minoofar <payam.minoofar at meissner.com> writes:

> I have managed to format my data into a single datframe consisting of two AsIs response and predictor dataframes in order to supply the plsr command of the pls package for principal components analysis.
>
> When I execute the command, however, I get this error:
>> fiber1 <- plsr(respmat ~ predmat, ncomp=1, data=inputmat,validation="LOO")
> Error in model.frame.default(formula = respmat ~ predmat, data = inputmat) :
>   invalid type (list) for variable 'respmat'
>
> I happen to have a lot of NAs  in some of the columns. Is that the
> problem?

The underlying PLSR/PCR functions do not handle NAs, but that is
probably not the problem here.

My guess is that you have done something like

  inputmat <- data.frame(respmat = I(foo), predmat = I(bar))

where foo (and perhaps bar) is a _data.frame_ (that is at leas
consistent with the error message).  If sapply(inputmat, class) produces
something like

     respmat      predmat        
[1,] "AsIs"       "AsIs"      
[2,] "data.frame" "data.frame"

then this is certainly the case.  That will not work.  They should be
matrices instead of data frames, for instance by converting them like
this:

  inputmat <- data.frame(respmat = I(as.matrix(foo)), predmat = I(as.matrix(bar)))

As for missing values: the default behaviour of plsr is to omit cases
with missing values.  This is controlled by the 'na.action' argument.
See ?na.action for details.

-- 
Regards,
Bjørn-Helge Mevik




More information about the R-help mailing list