Re: [R] help with PLSR Loadings

From: Bjørn-Helge Mevik <b.h.mevik_at_usit.uio.no>
Date: Wed, 18 May 2011 09:52:11 +0200

Amit Patel <amitrhelp_at_yahoo.co.uk> writes:

> x <- loadings(BHPLS1)
>
> my loadings contain variable names rather than numbers.

No, they don't.

>>str(x)
> loadings [1:94727, 1:10] -0.00113 -0.03001 -0.00059 -0.00734 -0.02969 ...
> - attr(*, "dimnames")=List of 2
> ..$ : chr [1:94727] "PCIList1" "PCIList2" "PCIList3" "PCIList4" ...
> ..$ : chr [1:10] "Comp 1" "Comp 2" "Comp 3" "Comp 4" ...
> - attr(*, "explvar")= Named num [1:10] 14.57 6.62 7.59 5.91 3.26 ...
> ..- attr(*, "names")= chr [1:10] "Comp 1" "Comp 2" "Comp 3" "Comp 4" ...

Look at the first line of output. These are the values, and they are numeric (it is a matrix). The other lines are attributes of the matrix.

>>plot(BHPLS1, "loadings", comps = 1:2, legendpos = "topleft", labels = "numbers",
>>xlab = "nm")
> Error in loadingplot.default(x, ...) :
> Could not convert variable names to numbers.

This says that loadingplot.default could not convert variable _names_ to numbers. That is not surprising, since the variable names are PCIList1, PCIList2, etc., and the documentation for loadinplot says:

     with '"numbers"', the variable names are converted to numbers, if
     possible.  Variable names of the forms '"number"' or '"number
     text"' (where the space is optional), are handled.

So don't ask the plot function to use numbers as labels. Use e.g. names instead: labels = "names".

Tip: It is always a good idea to read the output and error messages very carefully.

-- 
Regards,
Bjørn-Helge Mevik

______________________________________________
R-help_at_r-project.org mailing list
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.
Received on Wed 18 May 2011 - 07:54:30 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 18 May 2011 - 08:30:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive