[R] Adehabitat package question - trying to generate animal home ranges

Peter H Singleton psingleton at fs.fed.us
Tue Oct 2 20:58:22 CEST 2007


Hello,

I'm new to R and am trying to use the adehabitat package for home range and
habitat selection analysis for some animal radiotelemetry data sets I have,
but I can't get the home range functions (mcp & kernelUD) to work with my
data. I think that my problem is that I don't properly understand how the
package uses data frames and factors, and I may not be defining the id
factor correctly.

I've started out by trying to imitate the code in the homerange.r demo that
comes with the ade package. The code I'm trying to repeat with my data is:
###############################################
###############################################
###
### loads the 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


###############################################
###############################################
###
### Home ranges

## MCP
hr<-mcp(xy, id)         ## home range estimation
plot(hr)                ## displays the MCP
(jj<-mcp.area(xy, id))  ## home range size
plot(jj)                ## plots home-range size


## Kernel home range
(hr<-kernelUD(xy, id, h="LSCV", grid=100)) ## UD estimation
plotLSCV(hr)                               ## LSCV criterion
image(hr)                                  ## displays the UD
(jj<-kernel.area(xy, id))                  ## home range size
plot(jj)                                   ## Plots home range size
ver <- getverticeshr(hr)                   ## home-range contours
plot(ver)                                  ## Plots contours

======================================================================================================================================
The following is as far as I have gotten with my attempt to repeat the
above:

> require(adehabitat)
...
## I can get my data into the data frame object test
> test = read.csv("c:/rjunk/testdata.csv", header=T)
> test
   BIRD_LOC BIRD SEX      DATE TIME DATEVALUE SEASON      X       Y
1   CBF1001  CBF   F 5/18/2004 1756     38125   04BR 675022 5302087
2   CBF1002  CBF   F 5/19/2004 1817     38126   04BR 674988 5302111
...
90  CBM1043  CBM   M 9/28/2004  739     38258   04BR 675305 5302229
91  CBM1044  CBM   M 10/1/2004  738     38261   04BR 675005 5302109

## What does the $locs do? Am I correct that this is referring to something
that I don't have defined in my data frame?
> xy<-test$locs[,c("X","Y")]
> id<-test$locs$bird
> xy
NULL
> id
NULL

## I figured out how to subset the data into my XY coordinates and the BIRD
id lables, but the mcp and kernelUD functions don't work with these
subsets. Do I need to do something else to identify BIRD as a factor? Is
there a data prep step that I'm missing?
> xy <- subset(test, select = c(X, Y))
> xy
        X       Y
1  675022 5302087
2  674988 5302111
...
90 675305 5302229
91 675005 5302109
> id <- subset(test, select = c(BIRD))
> id
   BIRD
1   CBF
2   CBF
...
90  CBM
91  CBM
> hr <- mcp(xy, id)
Error in mcp(xy, id) : xy and id should be of the same length
> hr <- kernelUD(xy, id, h="LSCV", grid=100)
Error in kernelUD(xy, id, h = "LSCV", grid = 100) :
        id should have the same length as xy


<<->><<->><<->><<->><<->><<->><<->>
Peter Singleton
Wildlife Ecologist
USFS Pacific Northwest Research Station
1133 N. Western Ave.
Wenatchee WA 98801
Phone: (509)664-1732
Fax: (509)665-8362
E-mail: psingleton at fs.fed.us



More information about the R-help mailing list