[R-sig-eco] construct a nearest neighbor contingency table
Jari Oksanen
jari.oksanen at oulu.fi
Wed Jun 4 06:58:36 CEST 2008
Quoting Sarah Goslee <sarah.goslee at gmail.com>:
> What about using dist() on the xy coordinates, then finding the minimum
> for each row? That would get you nearest neighbor for each site.
>
>
One rule in R mailing list is that you should never hurry with your
answers. Somebody else may have answered already, or there is a more
obvious way. I have been submerged in spdep lately and came out with a
spdep package way of finding k nearest neighbours. You do not need
that, but the standard R package class has function knn.cv just for
this purpose (class is in the VR bundle of Venables & Ripley and
should be installed with any standard distribution of R). Usually knn
methods need train and test data set, but knn.cv does simple cross
validation. With the examle of the previous post (gender = gender
name, coord = spatial coordinates) you get
table(gender, knn.cv(coord, cl=gender))
coord need not be spatial coordinates (in the examples they are not),
but they can be.
cheers, jari oksanen
> On Tue, Jun 3, 2008 at 7:28 PM, Tom Elliott <tnelliott at gmail.com> wrote:
>> Hello-
>>
>> I have plot data of mapped male and female cottonwoods, collected for
>> my master's thesis. The data are multiple rows in 3 columns:
>> x-coordinate, y-coordinate, and a code for male, female, or unknown. I
>> want to test it for spatial segregation of the sexes using methods by
>> Phillip Dixon (1994, 2002).
>>
>> Is there a way in R to build a nearest neighbor contingency table for
>> the data? I would like the format to be 3 rows (male, female,
>> unknown), with columns for counts of the nearest neighbors in each
>> class.
>>
>> Thanks,
>> Tom
>>
>
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
More information about the R-sig-ecology
mailing list