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

CG Pettersson cg.pettersson at lantmannen.com
Wed Jan 13 20:02:25 CET 2016


R version 3.2.3, W7 64bit.

Dear all!

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))

Where gushVM is a vector with fifteen reference analysis values of a quality problem in grain and n96 is a matrix with fifteen rows and 96 columns from an electronic nose. I try to copy the methods as in 3.2 in Mevik & Wehrens, and want to keep n96 as one variable to avoid addressing 96 different variables in the plsr call. If I don´t use I() in the call I get 96 variables instead.
Looking at the dataframe by summary(frame1) get a return quite like summary(gasoline) from the package (not shown here).
But when I try to use plsr() with my own data it doesn´t work due to an error in the data structure:

> pls1 <- plsr(gushVM ~ n96, data = frame1)
Error in model.frame.default(formula = gushVM ~ n96, data = frame1) :
  invalid type (list) for variable 'n96'
>
So, n96 has turned into a list, and that is a problem. If gushVM is a vector (one variable) och a matrix (five variables) does not seem to change anything, managing n96 is the problem
I have tried all alternative ways of creating a proper data frame suggested in the article with exactly the same result.
I have tried the documentation for data.frame() but I probably don´t understand what it says.

What should I do to change "n96" into something better than "list"?

Thanks
/CG

Med vänlig hälsning/Best regards
CG Pettersson
Scientific Project Manager, PhD
______________________
Lantmännen Corporate R&D
Phone:  +46 10 556 19 85
Mobile: + 46 70 330 66 85
Email: cg.pettersson at lantmannen.com<mailto:cg.pettersson at lantmannen.com>
Visiting Address: S:t Göransgatan 160 A
Address: Box 30192, SE-104 25 Stockholm
Webb: http://www.lantmannen.com<http://www.lantmannen.com/>
Registered Office: Stockholm
Before printing, think about the environment


	[[alternative HTML version deleted]]



More information about the R-help mailing list