-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathctmm_speed.R
98 lines (73 loc) · 2.1 KB
/
ctmm_speed.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#############################
# Speed, distance, diffusion
# https://movementecologyjournal.biomedcentral.com/articles/10.1186/s40462-019-0177-1
#############################
library(ctmm)
#! load buffalo dataset from ctmm
data(buffalo)
# north-up projection
projection(buffalo) <- median(buffalo)
# consider first buffalo
DATA <- buffalo[[1]]
# load model fits from ctmm.select
load("data/cilla.rda")
# units operator
?`%#%`
1 %#% 'day' # day in seconds
1 %#% 'year' # year in seconds
# for time, will consider the first week of data
DATA <- DATA[DATA$t <= DATA$t[1] + 1%#%'week',]
plot(DATA,col=color(DATA,by='time'),error=FALSE)
# fit to first month only
FIT <- ctmm.select(DATA,FIT,trace=3)
# the speed estimate here is RMS Gaussian
summary(FIT)
# Gaussian (regular speed - not RMS)
speed(FIT)
# non-parametric speed estimation
# "2019 Noonan Fleming Akre ... Calabrese.pdf" in Readings/Continuous_Time folder
SPD <- speed(DATA,FIT)
SPD
# Impact of coarsening the data
SUB <- DATA
FIT.SUB <- FIT
#########################
# remove every other time
#########################
SUB <- SUB[as.logical(1:nrow(SUB)%%2),]
plot(SUB,col=color(SUB,by='time'),error=FALSE)
FIT.SUB <- ctmm.select(SUB,FIT.SUB,trace=3)
# the speed estimate here is RMS Gaussian
summary(FIT)
summary(FIT.SUB)
# Gaussian (regular speed - not RMS)
speed(FIT)
speed(FIT.SUB)
# non-parametric speed estimation
SPD
speed(SUB,FIT.SUB)
#########################
# repeat until data become too coarse
# keep in mind the stationary assumption of the model
# see the appendix of Noonan et al.
###########################
# Population meta-analysis
###########################
help('meta')
#Load in the fitted movement models
load("data/buffalo.rda")
#Estimate mean spead for each animal
SPEEDS <- list()
for(i in 1:length(buffalo))
{
SPEEDS[[i]] <- speed(buffalo[[i]],FITS[[i]])
}
names(SPEEDS) <- names(buffalo)
# save(SPEEDS,file="data/buffalo_speeds.rda")
load("data/buffalo_speeds.rda")
meta(SPEEDS,sort=TRUE)
###########################
# Instantaneous speeds
###########################
INST_SPEEDS <- speeds(buffalo[[1]],FITS[[1]])
head(INST_SPEEDS)