[R] lost in vegan package

Jari Oksanen jari.oksanen at oulu.fi
Tue Aug 31 09:28:17 CEST 2010

eva <epitta <at> upatras.gr> writes:

> Hi R Helpers, 
> I'm still new to R and i experience many difficulties..I'm using vegan
> package (R version 2.11) trying to calculate checkerboard units for each
> species pair of a matrix. I've prepared the function:
> pair.checker=function (dataset) {designdist (dataset,
> method="c("(A-J)x(B-J)", terms ="binary", abcd=FALSE)}
> to use with function oecosimu as follows:
> oecosimu(dataset, pair.checker, "tswap", nsimul=5000, burnin=0, thin=thin,
> statistic="pair.checker")
> It seemed to work but the output did not include each species pair name. I
> don't know what to do. First column was all NAs. I copied and pasted the
> results of the console and named each species pair in Excel by hand. But
> then I got this really big matrix with 3828 possible species pairs. The
> console couldn't show all posssible species pairs even after resetting the
> max.print option. I've tried saving the output as:

You have several problems with your example:

1) there is a syntax error (or several syntax errors) in the designdist()
'method' you have in you pair.checker().
2) designdist() finds dissimilarities between rows, and with standard usage 
yourspecies are columns: you must transpose your data.
3) designdist() returns a "dist" object which does not have names of pairs 
of species, but you must make them.
4) you should not give the name of the 'statistic' in the oecosimu unless 
you return the result in a list with an item named by the value given to 
the statistic.

Below is a version that seems to work. It corrects the syntax of 'method', 
andchanges the result to a vector named by the species pairs, but it 
doesn't transpose your data:

pair.checker <- function (dataset) 
  d <- designdist (dataset, method="(A-J)*(B-J)", terms ="binary")
  nm <- outer(labels(d), labels(d), paste)[lower.tri(d)]
  d <- as.vector(d)
  names(d) <- nm

If your species are columns (like usually in vegan data set), you must 
transposeyour data when calling this using t() function. Here is a 
working oecosimu call:

oecosimu(t(dune), pair.checker, "tswap", nsimul = 5000, burnin = 0)

I didn't give 'thin' here, since you didn't have a numeric value for 'thin' 
in your example. Further, you shall not give the name of the 'statistic' 
since pair.checker() returns an unnamed vector.

So you write from Patras... I've carried home a paper by Giokas & 
Sfenthourakis to see at my leisure how to implement their methodology in 
vegan. I guess it's above...

Cheers, Jari Oksanen

More information about the R-help mailing list