[R] Calculating home ranges using mcp in adehabitat

Eric R. ericr at mcs.st-and.ac.uk
Fri Jun 26 10:13:11 CEST 2009


Tom:

The structure of your dataframe (mydata) differs from the structure of the
example dataframe (puechabon) in that the example dataframe has the
structure 'locs' in which resides the x,y data and the individual
identifier.

The clue to your difficulty could be found when you asked to see the object
xy you created and were greeted with 

> xy[1:19,]
NULL
indicating it was empty.

Here is a toy example of what you want to do to successfully use mcp()

library(adehabitat)
mydata <- data.frame(Name='XDRY', X=runif(20)-21, Y=runif(20)+64)
mydata
xy <- mydata[,c("X","Y")]
id <- mydata[,"Name"]
xy[1:20,]
mcp(xy,id,percent=95)


Tom Mason wrote:
> 
> Hello,
> 
> I've been trying to calculate home range sizes (for Icelandic geese!)
> using minimum convex polygons with the adehabitat package. I've tried to
> use the R code shown by demo(homerange) in adehabitat and when that didn't
> work I've fiddled around with it but to no avail...Below is the output of
> the demo that I've attempted to follow, followed by a subset of my data
> (for one individual) and the code I've been trying. Can anyone tell me
> where I may be going wrong???
> 
> 
> #Demo output...
> 
>> data(puechabon)
> 
>> xy<-puechabon$locs[,c("X","Y")]
> 
>> id<-puechabon$locs$Name
> 
>> ## The data are:
>> xy[1:4,]     ## relocations coordinates
>        X       Y
> 1 699889 3161559
> 2 700046 3161541
> 3 698840 3161033
> 4 699809 3161496
> 
>> id[1:4]      ## ID
> [1] Brock Brock Brock Brock
> Levels: Brock Calou Chou Jean
> 
>> ###############################################
>> ###############################################
>> ###
>> ### Home ranges
>> 
>> ## MCP
>> hr<-mcp(xy, id)         ## home range estimation
> 
> 
> 
> # My attempts...
> 
>> mydata
>    Name         X        Y
> 1  XDRY -21.98389 64.06457
> 2  XDRY -21.99759 64.08291
> 3  XDRY -21.98784 64.06467
> 4  XDRY -21.98333 64.06058
> 5  XDRY -21.97889 64.06257
> 6  XDRY -21.98284 64.06044
> 7  XDRY -21.97886 64.06358
> 8  XDRY -21.99741 64.08124
> 9  XDRY -21.99715 64.08330
> 10 XDRY -22.00397 64.09331
> 11 XDRY -21.99811 64.08239
> 12 XDRY -22.00453 64.09337
> 13 XDRY -21.99713 64.08299
> 14 XDRY -21.99608 64.08307
> 15 XDRY -21.99646 64.08352
> 16 XDRY -21.99326 64.08361
> 17 XDRY -22.00770 64.09090
> 18 XDRY -21.98160 64.06400
> 19 XDRY -21.97966 64.06367
> 
>> xy<-mydata$locs[,c("X","Y")]
>> id<-mydata$locs$Name
> 
>> xy[1:19,]
> NULL
>> id[1:19,]
> NULL
> 
>> mcp(xy,id,percent=95)
> Error in if (length(id) != nrow(xy)) stop("xy and id should be of the same
> length") : 
>   argument is of length zero
> 
> 
> #I've also tried things like the code below. But didn't know how to
> incorporate 'locs' into this...
> 
>> xy<-cbind(X,Y)
>> id<-Name[1:19]
> 
>> xy[1:19,]
>               X        Y
>  [1,] -21.98389 64.06457
>  [2,] -21.99759 64.08291
>  [3,] -21.98784 64.06467
>  [4,] -21.98333 64.06058
>  [5,] -21.97889 64.06257
>  [6,] -21.98284 64.06044
>  [7,] -21.97886 64.06358
>  [8,] -21.99741 64.08124
>  [9,] -21.99715 64.08330
> [10,] -22.00397 64.09331
> [11,] -21.99811 64.08239
> [12,] -22.00453 64.09337
> [13,] -21.99713 64.08299
> [14,] -21.99608 64.08307
> [15,] -21.99646 64.08352
> [16,] -21.99326 64.08361
> [17,] -22.00770 64.09090
> [18,] -21.98160 64.06400
> [19,] -21.97966 64.06367
> 
>> id<-Name[1:19]
>> id[1:19]
>  [1] XDRY XDRY XDRY XDRY XDRY XDRY XDRY XDRY XDRY XDRY XDRY
> [12] XDRY XDRY XDRY XDRY XDRY XDRY XDRY XDRY
> Levels: XDRY
> 
>> mcp(xy,id,percent=95)
> Error in apply(xy, 2, mean) : dim(X) must have a positive length
> 
>> xy1<-xy[1:19,]
>> id1<-id[1:19]
>> mcp(xy1,id1,percent=95)
> Error in apply(xy, 2, mean) : dim(X) must have a positive length
> 
> 
> Would be most grateful for any suggestions to where I'm going wrong!
> 
> 
> Tom Mason,
> University of Exeter,
> UK.
> 
> 
> 
> 
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Calculating-home-ranges-using-mcp-in-adehabitat-tp24207532p24216560.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list