[R] Problems using plsr() in the pls package

Rui Barradas ruipbarradas at sapo.pt
Sun Nov 20 21:03:48 CET 2016


Hello,

I know nothing about the plsr package but in the data.frame 'gasoline' 
the column NIR is numeric and in 'lid_allt2' the column lid_nose is 
character. Maybe you need

lid_allt2$lid_nose <- as.numeric(lid_allt2$lid_nose)

but I really don't know if this is the problem.

Hope this helps,

Rui Barradas

Em 20-11-2016 19:04, CG Pettersson escreveu:
> Dear all,
> I am trying to do a PLS regression using plsr() from the pls package.
> I have tried to make a dataset according to the methods recommended in "Introduction to the pls Package" (Mevik & Wehrens, 2015) and it looks like I get a structure in the dataset that resembles what is packed with the package:
>
>> str(gasoline)
> 'data.frame':   60 obs. of  2 variables:
> $ octane: num  85.3 85.2 88.5 83.4 87.9 ...
> $ NIR   : AsIs [1:60, 1:401] -0.0502 -0.0442 -0.0469 -0.0467 -0.0509 ...
>    ..- attr(*, "dimnames")=List of 2
>    .. ..$ : chr  "1" "2" "3" "4" ...
>    .. ..$ : chr  "900 nm" "902 nm" "904 nm" "906 nm" ...
>
>> str(lid_allt2)
> 'data.frame':   223 obs. of  2 variables:
> $ DON     : num  55 55 55 55 55 55 55 55 55 55 ...
> $ lid_nose: 'AsIs' chr [1:223, 1:192] "215.074835" "203.803736" "197.364614" "192.765756" ...
>    ..- attr(*, "dimnames")=List of 2
>    .. ..$ : chr  "1" "2" "3" "4" ...
>    .. ..$ : chr  "n1" "n2" "n3" "n4" ...
>
> Where "gasoline" is a dataset from the package and "lid_allt2" is my own dataset. The reason there are so many "55" in the example row in the str() call is that I have repeated measurments with an electronic nose, normally six repetition for each control measurement.
>
> When I try to explain the DON variable with "lid_nose", the plsr() accepts my coding but returns a error message after on second or so:
>
>> don1 <- plsr(DON ~ lid_nose, ncomp = 10, data = lid_allt2, validation = "LOO")
> Error in `[[<-.data.frame`(`*tmp*`, i, value = c(16088L, 14624L, 14080L,  :
>    replacement has 42816 rows, data has 223
>
> I have clearly asked plsr() to do something very stupid, but what, and what should I do to come out a little better?
>
> Med v�nlig h�lsning/Best regards
> CG Pettersson
> Senior Scientific Advisor, 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]]
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list