[R-sig-Geo] mcp calculation

Sarah Goslee sarah.goslee at gmail.com
Fri Dec 6 22:18:27 CET 2013


Hi,

On Fri, Dec 6, 2013 at 4:04 PM, Lutfor <rahmannorthampton at gmail.com> wrote:
> Dear Mathieu,

I have no idea who Mathieu is: you sent this message to the entire
r-sig-geo list, if by way of the horrid nabble "interface."

> Thanks for extending your kind help.
> It works perfect with the example data.
> However, I had difficulty when I wanted to use following data unless I
> converted x, y corordinates to spatial data by the command of
> SpatialPointsDataFrame. Please see commands below. I wonder is there any
> other way to calculate MCP without converting SpatialPointsDataFrame.
>
> mcpdata1<-read.csv("DataMCPKernel.csv",header=T)
> attach(mcpdata1)
> XY=mcpdata1[,c("x","y")]
> #Convering your coordinates to spatial data
> *rel2<-SpatialPointsDataFrame(XY, data=mcpdata1)*
> cp2 <- mcp(rel2[,1], percent=100)
> as.data.frame(cp2)
> mcp.area(rel2[,1])

You don't say, but I'm assuming you are using the package
adehabitatHR. It's very important to tell us where you get your
functions from.

If you read the help for mcp.area, you will see:

Arguments

xy An object inheriting the class SpatialPoints containing the x and y
relocations of the animal. If xy inherits the class
SpatialPointsDataFrame, it should contain only one column (a factor)
corresponding to the identity of the animals for each relocation.

So yes, you need a Spatial object. There are other advantages to
Spatial objects, though.

This might be a slightly less convoluted approach:
mcpdata1 <-  structure(list(Stage = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L), .Label = "incubation", class = "factor"), x = c(646395.1,
646395.1, 646395.1, 646395.1, 646382.9, 646395.1, 646238.7, 646531.6,
646408, 646395.1, 646395.1), y = c(5213765L, 5213765L, 5213765L,
5213765L, 5213765L, 5213765L, 5213946L, 5213897L, 5213765L, 5213765L,
5213765L)), .Names = c("Stage", "x", "y"), class = "data.frame",
row.names = c(NA,
-11L))

library(adehabitatHR)

rel2 <- mcpdata1
coordinates(rel2) <- ~x + y

cp2 <- mcp(rel2, percent=100)
mcp.area(rel2)

Sarah

> Data:
>
> Stage   x       y
> incubation      646395.1        5213765
> incubation      646395.1        5213765
> incubation      646395.1        5213765
> incubation      646395.1        5213765
> incubation      646382.9        5213765
> incubation      646395.1        5213765
> incubation      646238.7        5213946
> incubation      646531.6        5213897
> incubation      646408  5213765
> incubation      646395.1        5213765
> incubation      646395.1        5213765
>
> Kind regards
> Lutfor
>
>
>

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-sig-Geo mailing list