[R-sig-eco] Problem with Fourth Corner Analysis

Stéphane Dray stephane.dray at univ-lyon1.fr
Mon Apr 15 18:20:18 CEST 2013


use row.names = 1 in your read.table. Here, you have an extra-column in 
each data.frame.

Cheers.

On 15/04/2013 18:04, daniel hanks wrote:
> Dear All,
>
> I am trying to run a fourth corner analysis and I am having trouble. In
> order to try to work out my problem I have set up dummy data for the
> species, habitat, and traits as three separate Excel files and imported
> them into R as below:
>
> dumbhab=read.table("dumbhab.csv", head=T, sep=",")
> dumbtraits=read.table("dumbtrait.csv", head=T, sep=",")
> dumbspecies=read.table("dumbspecies.csv", head=T, sep=",")
>
> They look as such in R:
>
>
>> head(dumbhab)   X   H1    H2    H3
> 1 R1  low small  tall
> 2 R2 high small short
> 3 R3  low small  tall
> 4 R4  low small  tall
> 5 R5 high small short
> 6 R6 high large short
>
>
>
>> head(dumbspecies)   X sp1 sp2 sp3 sp4 sp5 sp6 sp7 sp8 sp9 sp10
> 1 R1   1   0   0   0   1   1   1   0   0    1
> 2 R2   0   1   0   1   1   1   0   0   1    1
> 3 R3   0   1   0   1   0   1   1   0   1    0
> 4 R4   1   1   1   0   1   1   1   0   0    0
> 5 R5   0   1   0   1   0   0   0   0   0    0
> 6 R6   1   1   0   1   0   1   0   1   0
>
>
>
>> head(dumbtraits)    X TR1 TR2 TR3
> 1 Sp1 yes yes yes
> 2 Sp2  no yes  no
> 3 Sp3  no yes  no
> 4 Sp4 yes yes yes
> 5 Sp5 yes  no yes
> 6 Sp6 yes  no yes
>
>
> I then have combined them into a single list with:
>
> dumb.list=list(species=dumbspecies,hab=dumbhab,traits=dumbtraits)
>
> The mode of the list is:
>
>
>> mode(dumb.list)[1] "list"
>
> The structure of the list is:
>
>
>> str(dumb.list)List of 3
>   $ species:'data.frame':	10 obs. of  11 variables:
>    ..$ X   : Factor w/ 10 levels "R1","R10","R2",..: 1 3 4 5 6 7 8 9 10 2
>    ..$ sp1 : int [1:10] 1 0 0 1 0 1 1 0 1 0
>    ..$ sp2 : int [1:10] 0 1 1 1 1 1 1 0 1 0
>    ..$ sp3 : int [1:10] 0 0 0 1 0 0 0 0 0 1
>    ..$ sp4 : int [1:10] 0 1 1 0 1 1 1 1 0 0
>    ..$ sp5 : int [1:10] 1 1 0 1 0 0 0 1 0 0
>    ..$ sp6 : int [1:10] 1 1 1 1 0 1 0 1 1 1
>    ..$ sp7 : int [1:10] 1 0 1 1 0 0 1 1 1 0
>    ..$ sp8 : int [1:10] 0 0 0 0 0 1 0 1 1 1
>    ..$ sp9 : int [1:10] 0 1 1 0 0 0 1 1 0 1
>    ..$ sp10: int [1:10] 1 1 0 0 0 1 1 0 1 0
>   $ hab    :'data.frame':	10 obs. of  4 variables:
>    ..$ X : Factor w/ 10 levels "R1","R10","R2",..: 1 3 4 5 6 7 8 9 10 2
>    ..$ H1: Factor w/ 2 levels "high","low": 2 1 2 2 1 1 2 2 2 1
>    ..$ H2: Factor w/ 2 levels "large","small": 2 2 2 2 2 1 2 1 2 1
>    ..$ H3: Factor w/ 2 levels "short","tall": 2 1 2 2 1 1 2 1 2 2
>   $ traits :'data.frame':	10 obs. of  4 variables:
>    ..$ X  : Factor w/ 10 levels "Sp1","Sp10","Sp2",..: 1 3 4 5 6 7 8 9 10 2
>    ..$ TR1: Factor w/ 2 levels "no","yes": 2 1 1 2 2 2 2 2 1 2
>    ..$ TR2: Factor w/ 2 levels "no","yes": 2 2 2 2 1 1 1 1 2 1
>    ..$ TR3: Factor w/ 2 levels "no","yes": 2 1 1 2 2 2 2 1 1 2
>
>
> However, when I try to run the analysis I get the error message below.  Can
> someone please help me out?
>
>
>> dumb.try<-fourthcorner(dumb.list$hab,dumb.list$species,dumb.list$traits,nrepet=99)Error in if (any(tabL < 0)) stop("negative values in table L") :
>    missing value where TRUE/FALSE neededIn addition: Warning message:In
> Ops.factor(left, right) : < not meaningful for factors
>
>
>
> Many Thanks!
>
>
>
> Daniel
>
>
>
>
>
>
>
>
>
>
>
>
>
>


-- 
Stéphane DRAY (stephane.dray at univ-lyon1.fr)
Laboratoire BBE-CNRS-UMR-5558, Univ. C. Bernard - Lyon I
43, Bd du 11 Novembre 1918, 69622 Villeurbanne Cedex, France
Tel: 33 4 72 43 27 57       Fax: 33 4 72 43 13 88
http://pbil.univ-lyon1.fr/members/dray/



More information about the R-sig-ecology mailing list