动物的平均家庭范围

时间:2014-05-28 16:30:59

标签: r

现在已经挣扎了好几天了。我在这里使用我的数据的子集,3个人,每个7个重定位,跟踪3个赛季。并非所有季节都有鱼类存在,并且它们的位置因季节而异。我需要估算每个季节鱼类的平均家庭范围并绘制它。

我认为Anthony Fischbach的回复是我需要做的,我只是停留在那里(主要是因为我对空间分析和adehabitatHR很新)。

http://r-sig-geo.2731867.n2.nabble.com/averaging-home-range-contours-td7499301.html#a7503972

df <- structure(list(Season = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L), .Label = c("Spring", "Summer", "Fall"), class = "factor"), 
Easting = c(425952.746437786, 425930.124103401, 425904.838430173, 
425897.396103185, 425859.77203381, 425769.155466566, 425698.934422453, 
425172.162553713, 425201.54784946, 425265.188960297, 425293.907156855, 
425334.519543017, 425351.98115297, 425341.657291998, 426499.521534761, 
426491.617459401, 426489.21804795, 426458.425998741, 426444.572705444, 
426435.13014907, 426428.521796826, 425206.363932968, 425214.055516556, 
425214.686198032, 425219.462846981, 425224.610973811, 425225.509004604, 
425231.130704745, 425295.438309455, 425295.033258023, 425298.385156621, 
425286.605300153, 425292.736058183, 425296.563442322, 425289.068691518, 
425262.047903812, 425245.264536305, 425236.068286685, 425246.961026478, 
425244.291558159, 425234.858476333, 425220.329721481), Northing = c(5630038.14127036, 
5630042.68938361, 5630053.17010795, 5630050.05067675, 5630050.03021924, 
5630044.42581987, 5630080.68394433, 5631660.65042482, 5631622.41326505, 
5631580.90371775, 5631564.80939618, 5631533.30748204, 5631498.46768363, 
5631476.0382073, 5629521.34564057, 5629530.46592294, 5629545.1806574, 
5629555.1802463, 5629557.15541335, 5629572.08088964, 5629598.08820948, 
5630913.54144105, 5630904.64457731, 5630904.41307655, 5630898.56103167, 
5630889.14462961, 5630887.90831366, 5630886.93779994, 5630645.78035996, 
5630647.00958702, 5630649.85318956, 5630643.90518234, 5630648.93328633, 
5630650.5466496, 5630648.65226268, 5631661.36063509, 5631635.46509059, 
5631632.70549606, 5631635.88559859, 5631631.47516021, 5631626.93945528, 
5631610.91014489), ID = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L), .Label = c("01", "04", "06"), class = "factor")), .Names =         
c("Season", 
"Easting", "Northing", "ID"), row.names = c(NA, 42L), class = "data.frame")

## following the advice in the link above:
library(adehabitatHR)
tagList <- unique(df$ID)

kud1 <- list()
kud_spdf <- list()
vd <- list()

## running a loop across animals, estimating 95% 
for(i in tagList){
thing <- SpatialPoints(subset(df[df$ID == i,], select = c(Easting, Northing)),   
proj4string = CRS("+proj=utm +zone=11 +ellps=WGS84"))
thing <- SpatialPointsDataFrame(coords = thing, data = subset(df[df$ID == i,], select = c(Season)))
thing$Season <- as.character(thing$Season)
kud1[[i]] <- kernelUD(thing, grid = 120, extent = 0.2, same4all=TRUE)
kud_spdf[[i]] <- estUDm2spixdf(kud1[[i]]) 
    fullgrid(kud_spdf[[i]]) <- TRUE
vd[[i]] <- kud_spdf[[i]]@data 
     }

然后我被卡住了,因为vd中的每条鱼都有不同的点数(因为据我所知,网格是针对每条鱼单独计算的)。如何进行鱼类平均,按像素对数据进行求和和归一化等?

我可以使用绘图部分,只要我可以在kernelUD对象上使用getverticeshr,然后运行fortify,并使用ggmap和ggplot按组绘图。

任何帮助将不胜感激......

1 个答案:

答案 0 :(得分:1)

我不确定我理解你的问题,但为什么你们不能一起工作,物种和季节一起?

sp_df <- subset(df, select = c(IDS, Easting, Northing))
coordinates(sp_df) <- ~Easting+Northing
#plot(sp_df, axes = T, col = )
kud <- kernelUD(sp_df[ ,1], grid = 200, same4all=TRUE)
hr <- kernel.area(kud, percent = 95)

    X01Fall X01Summer X04Spring X04Summer X06Spring X06Summer
95 8.638694  8.118291  1.353048    2581.2    2581.2 0.4163226

并从这里开始工作以总结个人数据

这里有很多选择......

hr1 <- as.data.frame(t(hr))
hr1$ID <- factor(rep(c(1,4,6), each = 2))
names(hr1)[1] <- 'p95'
# Using base functions
aggregate(p95~ ., hr1, mean)

# Fast and simple
library(dplyr)
hr1 %>%
  group_by(ID)%>%
  summarise(mean_hr = mean(p95))
    Source: local data frame [3 x 2]

  ID   mean_hr
1  1 8.4037848
2  4 0.8040197
3  6 0.2109327

修改

我不理解当个体显示出显着的空间位移时获得平均原始范围的相关性,就像在这种情况下一样。

kareas <- getverticeshr(kud, 95)
library(ggplot2)
kdareas <- fortify(kareas)
ggplot(kdareas) +
  geom_polygon(aes(x=long, y=lat, group = group, fill = id, colour = id),
               alpha = .4) +
  theme_bw() +
  coord_equal()

kernel area

我不明白你为什么要这样做,但那就是我......