[AniMov] adehabitat
Clément Calenge
calenge at biomserv.univ-lyon1.fr
Wed Nov 17 16:52:53 CET 2004
Dear all,
>4. I believe putting together easy howtos for newbies is important to make
>the
>package more available
This is my opinion too. One tutorial is presently
available in the package to present classes of
map objects, but I also think that others are
necessary to make the package more available to
biologists, e.g. by presenting examples of analyses.
>5. we should study how to move data (polygons, points, lines) to and from
>GRASS, for further more GIS-oriented analyses (eg for DTM: slope, aspect,
>etc, and for integration with different data sources).
I agree that interface between the map objects
of adehabitat (class asc and kasc) and of GRASS
should be done. However, note that the question
of moving data from and to other GIS is of major
concern in the future development of R. As well
as developping spatial analyses, and not only for
biological purposes.
Presently, one can download numerous packages
to achieve these aims with R. A project
(http://agec221.agecon.uiuc.edu/csiss/Rgeo/)
and a mailing list
(https://www.stat.math.ethz.ch/mailman/listinfo/r-sig-geo)
have been set up, and numerous packages are
presently available either to provide
an interface toward other GIS (GRASS, Arcinfo,
Arcview, etc.), or to render spatial
analyses available to R user.
Concerning GRASS, a package of the same name
is already available, to provide an interface
between R and GRASS
(see http://agec221.agecon.uiuc.edu/csiss/Rgeo/GIS.html
and http://grass.itc.it/statsgrass/index.html).
However, I cannot give more info on it, as
I am not a specialist of this software
or of the package.
>2. can somebody compare point-to-point the functions provided by adehabitat
>and those on the wishlist?
I indicate below some clues to
perform the required analyses on the web
site http://www.faunalia.com/animov/
I use here as an example the dataset puechabon
of the package adehabitat.
Some analyses were not performed:
I don't know the Cramer von Mises test
for the CSR, nor the site fidelity test.
However, note that the package splancs
provides numerous tests for the csr.
It should be quite easy to develop
tests of CSR based on analyses available in
this package.
The examples presented below require two other R
packages: the package "CircStats", used to perform
circular statistics, "ellipse" to compute confidence
ellipse, and "gpclib" to deal with minimum convex
polygons.
Hope this helps,
Clément.
###############################################
###############################################
###
### loads data
library(adehabitat)
data(puechabon)
xy<-puechabon$locs[,c("X","Y")]
id<-puechabon$locs$Name
## The data are:
xy[1:4,] ## relocations coordinates
id[1:4] ## ID
###############################################
###############################################
###
### Basic statistics
## Minimum X and Y
apply(xy, 2, min)
## Minimum X and Y per animal
apply(xy, 2, function(x) tapply(x, id, min))
## Mean of X and Y
apply(xy, 2, mean)
## Mean of X and Y per animal
apply(xy, 2, function(x) tapply(x, id, mean))
## Variance of X and Y
apply(xy, 2, var)
## Variance of X and Y per animal
apply(xy, 2, function(x) tapply(x, id, var))
## Sample Size
nrow(xy)
## per animal
table(id)
###############################################
###############################################
###
### distances
## Distance between relocations
di<-as.matrix(dist(xy))
diag(di)<-NA
## min and max distance
min(c(di), na.rm=TRUE)
max(c(di), na.rm=TRUE)
## Distance between relocations, per animal
xyperan<-split(xy, id)
dibis<-lapply(xyperan, function(x) as.matrix(dist(x)))
dibis<-lapply(dibis, function(x) {diag(x)<-NA;x})
## min distance
lapply(dibis, function(x) min(c(x), na.rm=TRUE))
## max distance
lapply(dibis, function(x) max(c(x), na.rm=TRUE))
###############################################
###############################################
###
### compute distance between successive
### relocation
## first, transform the dataset puechabon
## into an object of class traj
# 1. Conversion of the date to the class POSIX
da <- as.POSIXct(strptime(as.character(puechabon$locs$Date),
"%y%m%d"))
# 2. conversion of the data to the class traj
tr <- as.traj(id = id, xy = xy, date = da)
tr
## Minimum date
kk<-tapply(tr$date, tr$id, min)
class(kk)<-"POSIXct"
kk
## Maximum date
kk<-tapply(tr$date, tr$id, max)
class(kk)<-"POSIXct"
kk
## Compute speed
sp<-speed(tr)
## Minimum, maximum and mean speed
tapply(sp$speed, sp$id, min)
tapply(sp$speed, sp$id, max)
tapply(sp$speed, sp$id, mean)
## the distance between successive observation
## is simply
disuc<-sp$speed*sp$dt
## total distance per animal
ditot<-tapply(disuc, sp$id, sum)
## Distance between the first and end relocation
dd<-function(x) {
xfirst<-x[1,]
xend<-x[nrow(x),]
di<-sqrt((xfirst[1]-xend[1])^2 +
(xfirst[2]-xend[2])^2)
return(di)
}
dilin<-unlist(lapply(xyperan, dd))
## The linearity
dilin/ditot
## mean distance per animal
tapply(disuc, sp$id, mean)
## But be careful! the time interval between
## relocations is not necessarily constant
## A better way to work with standardised
## distances, i.e. with speed
## schoener's ratio:
t2 <- lapply(split(disuc, sp$id), function(x) sum(x^2)/length(x))
r2 <- lapply(xyperan, function(x) var(x[,1])+var(x[,2]))
ratio <- unlist(t2)/unlist(r2)
###############################################
###############################################
###
### compute bearings between successive
### trajectories
ang<-angles(tr)
## load the library circstats,
## to work with angles
## see help(package = CircStats)
## for other circular statistics
##
library(CircStats)
## plots the angles:
mm<-split(ang$ang, ang$id)
opar<-par(mfrow=c(2,2))
lapply(mm, circ.plot, stack=TRUE, bins=100)
par(opar)
## mean angle
lapply(mm, circ.mean)
## Concentration and variance of angles
do.call("rbind", lapply(mm, circ.disp))
## Rayleigh's z for angles:
lapply(mm, r.test)
###############################################
###############################################
###
### Home ranges
###
## MCP
hr<-mcp(xy, id)
area.plot(hr)
jj<-mcp.area(xy, id)
jj
plot(jj)
## Kernel home range
hr<-kernelUD(xy, id, h="LSCV")
hr
image(hr)
jj<-kernel.area(xy, id)
jj
plot(jj)
###############################################
###############################################
###
### Primary and secondary axes length
###
## First perform a PCA
pc<-lapply(xyperan, dudi.pca,
scale=FALSE, scannf=FALSE)
## Then, the standard deviation is
## computed for each axis (length
## of primary and secondary axes)
sde<-lapply(pc, function(x) apply(x$li, 2, sd))
sde<-do.call("rbind", sde)
## and the eccentricity
apply(sde, 1, function(x) x[2]/x[1])
## Displays the results:
## this is done using the package "ellipse"
## example: the 95% confidence ellipse
library(ellipse)
foo<-function(x) {
u<-ellipse(cov(x), centre=apply(x,2,mean))
plot(u, ty="n", axes=FALSE)
points(x, pch=16)
lines(u)
box()
}
par(mfrow=c(2,2), mar=c(0,0,0,0))
lapply(xyperan, foo)
======================================
UMR CNRS 5558 - Equipe "Ecologie Statistique"
Laboratoire de Biométrie et Biologie Evolutive
Université Claude Bernard Lyon 1
43, Boulevard du 11 novembre 1918
69622 Villeurbanne Cedex
FRANCE
tel. (+33) 04.72.43.27.57
fax. (+33) 04.72.43.13.88
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.faunalia.com/pipermail/animov/attachments/20041117/ebd4c0c3/attachment.html
More information about the AniMov
mailing list