packages

library(reshape)
library(ggplot2)
library(dplyr)
library(yarrr)
source('./fncs/21_patch_statistics.R')

data

Dataset including the patch size for every location of roe and red deer location dataset.

ce <- read.csv2('../data/2_patchsize/red.csv',dec = ',')
ca <- read.csv2('../data/2_patchsize/roe.csv',dec = ',')
head(ce)
##   X    aniyr study_areas_id sex animals_id       acquisition_time
## 1 1 113_2011              3   m        113 2011-05-01 01:00:41+00
## 2 2 113_2011              3   m        113 2011-05-01 12:00:53+00
## 3 3 113_2011              3   m        113 2011-05-02 00:00:24+00
## 4 4 113_2011              3   m        113 2011-05-02 12:00:47+00
## 5 5 113_2011              3   m        113 2011-05-02 23:00:42+00
## 6 6 113_2011              3   m        113 2011-05-03 11:02:01+00
##   forest_density corine_land_cover_2012_vector_code    timex      datex yearx
## 1              0                                231 01:00:41 2011-05-01  2011
## 2             97                                312 12:00:53 2011-05-01  2011
## 3             93                                231 00:00:24 2011-05-02  2011
## 4             98                                312 12:00:47 2011-05-02  2011
## 5              0                                211 23:00:42 2011-05-03  2011
## 6             98                                312 11:02:01 2011-05-03  2011
##   mid_or_noon doyx min max diff_doy      prop count cnt_night prop_night
## 1    midnight  121 121 304      183 0.9076087   334       168  0.9130435
## 2        noon  121 121 304      183 0.9076087   334       168  0.9130435
## 3    midnight  122 121 304      183 0.9076087   334       168  0.9130435
## 4        noon  122 121 304      183 0.9076087   334       168  0.9130435
## 5    midnight  122 121 304      183 0.9076087   334       168  0.9130435
## 6        noon  123 121 304      183 0.9076087   334       168  0.9130435
##   cnt_day  prop_day TCD_forest_patch_size CLC_forest_patch_size
## 1     166 0.9021739                    NA                    NA
## 2     166 0.9021739              13147200               6053200
## 3     166 0.9021739              13147200                    NA
## 4     166 0.9021739              13147200               6053200
## 5     166 0.9021739                    NA                    NA
## 6     166 0.9021739              13147200              13534000
##   TCD_open_patch_size CLC_open_patch_size       x       y optional
## 1              632800           142250800 4341133 2596948     TRUE
## 2                  NA                  NA 4341369 2597390     TRUE
## 3                  NA           142250800 4341057 2596897     TRUE
## 4                  NA                  NA 4340694 2596719     TRUE
## 5              526800           142250800 4341963 2597197     TRUE
## 6                  NA                  NA 4342160 2597473     TRUE
head(ca)
##        X    aniyr study_areas_id sex animals_id       acquisition_time
## 1 103311 769_2005              1   m        769 2005-05-01 00:02:54+00
## 2 103312 769_2005              1   m        769 2005-05-01 12:01:59+00
## 3 103313 769_2005              1   m        769 2005-05-02 00:03:00+00
## 4 103314 769_2005              1   m        769 2005-05-07 12:03:05+00
## 5 103315 769_2005              1   m        769 2005-05-08 00:02:12+00
## 6 103316 769_2005              1   m        769 2005-05-08 12:02:22+00
##   forest_density corine_land_cover_2012_vector_code    timex      datex yearx
## 1             99                                313 00:02:54 2005-05-01  2005
## 2             86                                311 12:01:59 2005-05-01  2005
## 3             97                                311 00:03:00 2005-05-02  2005
## 4             89                                311 12:03:05 2005-05-07  2005
## 5             94                                311 00:02:12 2005-05-08  2005
## 6             98                                311 12:02:22 2005-05-08  2005
##   mid_or_noon doyx min max diff_doy      prop count cnt_night prop_night
## 1    midnight  121 121 304      183 0.6467391   238       122  0.6630435
## 2        noon  121 121 304      183 0.6467391   238       122  0.6630435
## 3    midnight  122 121 304      183 0.6467391   238       122  0.6630435
## 4        noon  127 121 304      183 0.6467391   238       122  0.6630435
## 5    midnight  128 121 304      183 0.6467391   238       122  0.6630435
## 6        noon  128 121 304      183 0.6467391   238       122  0.6630435
##   cnt_day  prop_day TCD_forest_patch_size CLC_forest_patch_size
## 1     116 0.6304348                    NA                    NA
## 2     116 0.6304348                999600                905600
## 3     116 0.6304348                999600                905600
## 4     116 0.6304348                999600                905600
## 5     116 0.6304348                999600                905600
## 6     116 0.6304348                999600                905600
##   TCD_open_patch_size CLC_open_patch_size       x       y optional
## 1                  NA                  NA 4403227 2557846     TRUE
## 2                  NA                  NA 4403290 2558521     TRUE
## 3                  NA                  NA 4403244 2558778     TRUE
## 4                  NA                  NA 4403501 2558511     TRUE
## 5                  NA                  NA 4403286 2558574     TRUE
## 6                  NA                  NA 4403468 2558505     TRUE

Apply patch_stat function

# CALCULATE NUMBER OF PATCHES AND NUMBER OF FIXES IN A PATCH SMALLER THAN 25 HECTARE 
patch_ce_l <- patch_statistics(ce, patchsize = 250000)
patch_ca_l <- patch_statistics(ca, patchsize = 250000)

nr of small patches

First, we calculated the number of patches per individual. Then we sum up all the patches over all populations per species.

# NR OF PATCHES 
patch_nr_ce <- patch_ce_l[[1]] 
patch_nr_ce$species <- 'red'
patch_nr_ca <- patch_ca_l[[1]] 
patch_nr_ca$species <- 'roe'

patch_nr <- rbind(patch_nr_ce,patch_nr_ca)
patch_nr <- melt(patch_nr, id=c("species","animals_id")) 

# STATISTICS ABOUT NR OF PATCHES PER INDIVIDUAL OVER ALL POPULATIONS PER SPECIES 
(r <- group_by(patch_nr, species, variable) %>% 
    summarise(sum = sum(value), 
              mean= mean(value), 
              median=median(value), 
              max=max(value),
              min=min(value)))
## # A tibble: 8 × 7
## # Groups:   species [2]
##   species variable   sum  mean median   max   min
##   <chr>   <fct>    <int> <dbl>  <int> <int> <int>
## 1 red     TCD_F      406  4.78      3    18     2
## 2 red     CLC_F      208  2.45      2     6     2
## 3 red     TCD_O      707  8.32      8    20     2
## 4 red     CLC_O      269  3.16      3     7     2
## 5 roe     TCD_F      490  4.67      3    27     1
## 6 roe     CLC_F      223  2.12      2     4     1
## 7 roe     TCD_O      340  3.24      2     9     1
## 8 roe     CLC_O      231  2.2       2     6     1
barplot(r$sum, 
        cex.names=0.6,
        names.arg=c(paste0(r$species, ' ' , r$variable)), 
        main='total number of patches over all population')

nr of fixes in patches < 25 hectares

First, we calculated the proportion of fixes that is in a patch smaller than 25 hectare, for each individual. Then, we calculate the mean of that proportion over all populations (and thus all individuals)

patch_fx_ce <- patch_ce_l[[2]]
patch_fx_ce$species <- 'red'
patch_fx_ca <- patch_ca_l[[2]] 
patch_fx_ca$species <- 'roe'

patch_fx <- rbind(patch_fx_ce,patch_fx_ca)
(r <- group_by(patch_fx, species, variable) %>% 
    summarise(mean= mean(Freq), 
              median=median(Freq), 
              max=max(Freq),
              min=min(Freq)))
## # A tibble: 8 × 6
## # Groups:   species [2]
##   species variable    mean  median    max   min
##   <chr>   <chr>      <dbl>   <dbl>  <dbl> <dbl>
## 1 red     CLC_F    0.00663 0       0.543      0
## 2 red     CLC_O    0.00122 0       0.0556     0
## 3 red     TCD_F    0.0451  0.00549 0.779      0
## 4 red     TCD_O    0.432   0.238   1          0
## 5 roe     CLC_F    0.103   0       1          0
## 6 roe     CLC_O    0.0528  0       1          0
## 7 roe     TCD_F    0.389   0.0599  1          0
## 8 roe     TCD_O    0.201   0       1          0
barplot(r$mean, 
        cex.names=0.6,
        names.arg=c(paste0(r$species, ' ', r$variable)), 
        main='mean proportion of fixes in small patches (<25ha) per individual over all populations')

#boxplot(Freq ~ species + variable, data=patch_fx, cex.axis=0.6, main='proportion of fixes in small patches (<25 ha) per individual')
pirateplot(Freq ~ variable  + species, data=patch_fx, cex.axis=0.6, main='proportion of fixes in small patches (<25 ha) per individual')