[R] Problems with data structure when using plsr() from package pls
CG Pettersson
cg.pettersson at lantmannen.com
Sun Jan 17 13:29:36 CET 2016
Thanks a lot to both of you for the effort and nice suggestions.
I have tested all suggested coding variants and I do succeed in changing the data structure, for example like this (with a test using str())
> names(n96) <- paste("n96", 1:96)
> frame1 <- cbind(gushVM, n96)
>
> str(frame1)
'data.frame': 15 obs. of 97 variables:
$ gushVM: num 2 23.2 14.3 40.9 32.8 29.1 0 79 0 0 ...
$ n96 1 : num 34.2 31.8 52 36.1 47 ...
$ n96 2 : num 23.3 21.1 33.6 24.3 31.5 ...
$ n96 3 : num 97.5 80.6 89.5 97.3 122.4 ...
$ n96 4 : num 79.2 64.4 79.9 79.4 99.7 ...
$ n96 5 : num 24.1 25.8 45.3 25.8 45.2 ...
$ n96 6 : num 83.1 81.7 119 82.6 140.2 ...
$ n96 7 : num 10 10.8 16.2 10.9 15.9 ...
$ n96 8 : num 129 124 180 135 202 ...
$ n96 9 : num 58.8 52.9 84 61.7 76.7 ... and so on until row variable 96 inside n96
But using this dataframe with plsr() results in the same error message, like:
> pls1 <- plsr(gushVM ~ n96, data = frame1)
Error in model.frame.default(formula = gushVM ~ n96, data = frame1) :
invalid type (list) for variable 'n96'
Which is the same message as ever. The same happens with the other two suggestions, even if the detail structure of "n96" inside "frame" differ a little whe I test it with str().
Still stuck, but thanks all the same!
/CG
-----Ursprungligt meddelande-----
Från: S Ellison [mailto:S.Ellison at LGCGroup.com]
Skickat: den 15 januari 2016 14:39
Till: Sarah Goslee; CG Pettersson
Kopia: r-help at r-project.org
Ämne: RE: [R] Problems with data structure when using plsr() from package pls
> > 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