[R] Biplot for PCA using labdsv package

Michael Denslow michael.denslow at gmail.com
Mon Apr 5 11:49:20 CEST 2010


Hi Dilys,

On Fri, Apr 2, 2010 at 3:08 AM, Dilys Vela <dilysvd at gmail.com> wrote:
> Hi everyone,
>
> I am doing PCA with labdsv package. I was trying to create a biplot graphs
> in order to observe arrows related to my variables. However when I run the
> script for this graph, the console just keep saying:
>
> *Error in nrow(y) : element 1 is empty;
>   the part of the args list of 'dim' being evaluated was:
>   (x)*
>
> could please someone tell me what this means? what i am doing wrong? I will
> really appreciate any suggestions and help.
>
It seems like you are mixing the pca function from package labdsv with
the biplot function from package stats. Is that correct? pca from
labdsv is a wrapper for prcomp but has a different output. For example
using the Bryce Data from labdsv:

# pca in labdsv
> str(pca(bryceveg))
List of 4
 $ scores  : num [1:160, 1:160] 0.304 -0.107 0.325 0.301 3.051 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:160] "50001" "50002" "50003" "50004" ...
  .. ..$ : chr [1:160] "PC1" "PC2" "PC3" "PC4" ...
 $ loadings: num [1:169, 1:160] -0.00638 0.03989 0.85517 -0.05806 -0.03787 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:169] "junost" "ameuta" "arcpat" "arttri" ...
  .. ..$ : chr [1:160] "PC1" "PC2" "PC3" "PC4" ...
 $ sdev    : num [1:160] 1.799 1.09 0.793 0.647 0.557 ...
 $ totdev  : num 9.24
 - attr(*, "class")= chr "pca"

# prcomp from stats
> str(prcomp(bryceveg))
List of 5
 $ sdev    : num [1:160] 1.799 1.09 0.793 0.647 0.557 ...
 $ rotation: num [1:169, 1:160] -0.00638 0.03989 0.85517 -0.05806 -0.03787 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:169] "junost" "ameuta" "arcpat" "arttri" ...
  .. ..$ : chr [1:160] "PC1" "PC2" "PC3" "PC4" ...
 $ center  : Named num [1:169] 0.0125 0.0813 1.1231 0.1531 0.1 ...
  ..- attr(*, "names")= chr [1:169] "junost" "ameuta" "arcpat" "arttri" ...
 $ scale   : logi FALSE
 $ x       : num [1:160, 1:160] 0.304 -0.107 0.325 0.301 3.051 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:160] "50001" "50002" "50003" "50004" ...
  .. ..$ : chr [1:160] "PC1" "PC2" "PC3" "PC4" ...
 - attr(*, "class")= chr "prcomp"

biplot (or biplot.prcomp) is expecting something like the second example.
I am not sure if there is an equivalent function in labdsv so you may
wish to use prcomp directly. Either way if you provide the code you
used it will make it easier to sort out.

Hope this helps,
Michael

-- 
Michael Denslow

I.W. Carpenter Jr. Herbarium [BOON]
Department of Biology
Appalachian State University
Boone, North Carolina U.S.A.
-- AND --
Communications Manager
Southeast Regional Network of Expertise and Collections
sernec.org

36.214177, -81.681480 +/- 3103 meters



More information about the R-help mailing list