[R] Problems with data structure when using plsr() from package pls

S Ellison S.Ellison at LGCGroup.com
Fri Jan 15 14:38:35 CET 2016

> > I am trying to make pls-regression using plsr() from package pls, with
> > Mevik & Wehrens (2007) as tutorial and the datasets from the package.
> > Everything works real nice as long as I use the supplied datasets, but
> > I don´t understand how to prepare my own data.
> > This is what I have done:
> >
> > > frame1 <- data.frame(gushVM, I(n96))

Reading ?plsr examples and inspecting the data they use, you need to arrange frame1 so that it has the data from n96 included as columns with names of the from "n96.xxx" whre xxx can be numbers, names etc.

If n96 is a data frame, try something like
names(n96) <- paste("n96", 1:96) 
frame1 <- cbind(gushVM, n96)

pls1 <- plsr(gushVM ~ n96, data = frame1)

If n96 is a matrix, 

frame1 <- data.frame(gushVM, n96=n96)

should also give you a data frame with names of the right format.

I() wrapped round a matrix or data frame does nothing like what is needed if you include it in a data frame construction, so either things have changed since the tutorial was written, or the authors were not handling a matrix or data frame with I().

S Ellison

This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If 
you have received this message in error, please notify the sender 
immediately via +44(0)20 8943 7000 or notify postmaster at lgcgroup.com 
and delete this message and any copies from your computer and network. 
LGC Limited. Registered in England 2991879. 
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK

More information about the R-help mailing list