-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathctmm_path_reconstruction.R
94 lines (67 loc) · 2.04 KB
/
ctmm_path_reconstruction.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
# load ctmm package
library(ctmm)
# load buffalo data from package
data(buffalo)
projection(buffalo) <- median(buffalo)
names(buffalo)
# look at Cilla
DATA <- buffalo$Cilla
# selected autocorrelation model
GUESS <- ctmm.guess(DATA,interactive=FALSE)
FIT <- ctmm.select(DATA,GUESS,trace=3)
# save(FIT,file="cilla.rda")
# I've already run this
load("data/cilla.rda")
#############
# PREDICT
#############
# take the first 10 locations
SUB <- DATA[1:10,]
# plot subset
plot(SUB)
# if working with this amount of data, you might consider alternative ICs
# in particular IC="LOOCV"
help("ctmm.select")
# I'm just sub-setting for purposes of visualization and speed
# convenience function
help("%#%")
1 %#% 'hr'
# make an array of times over the same period, but 5 min apart
SEQ <- seq(from=SUB$t[1],to=SUB$t[10],by=5 %#% 'min')
# predict locations at those times
help('predict.ctmm')
PRED <- predict(SUB,FIT,t=SEQ)
# plot predictions & data
plot(list(PRED,SUB),col=c('blue','red'))
#############
# CONDITIONAL SIMULATION
#############
# 1 minute sequence
SEQ <- seq(from=SUB$t[1],to=SUB$t[10],by=1 %#% 'min')
# simulate locations at those time
help('simulate.ctmm')
SIM <- simulate(SUB,FIT,t=SEQ)
# plot conditional simulation & data
plot(list(SIM,SUB),col=c('blue','red'),type=c('l','p'))
SIM2 <- simulate(SUB,FIT,t=SEQ)
# plot conditional simulation & data
plot(list(SIM,SIM2,SUB),col=c('blue','orange','red'),type=c('l','l','p'))
# that is only trajectory uncertainty
# can also include parameter uncertainty
help('emulate')
SIM3 <- simulate(SUB,emulate(FIT, fast = T),t=SEQ)
plot(list(SIM,SIM2,SIM3,SUB),col=c('blue','orange','black','red'),type=c('l','l','l','p'))
##########################
# Occurrence distributions
##########################
# full dataset
plot(DATA)
OD <- occurrence(DATA,FIT)
plot(OD,col.level=NA)
SIM <- simulate(DATA,FIT,dt=5 %#% 'min')
plot(SIM)
# If you have habitat values and want to know how much
# time an animal spent you can calculate the weighted average:
# sum(RASTER*OD) = E[RASTER]
# where OD is the exported 'PMF'
help('export')