-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis.R
971 lines (682 loc) · 31.4 KB
/
analysis.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
# Setup & data
library(dplyr)
library(jagsUI)
source('functions.R')
load('data_cleaned.Rdata')
load('metadata.Rdata')
extract(data)
# Note:
# dayIntervals[i,t] is the intervening time *AFTER* time t.
# So, dayIntervals[i,1] is the intervening time between initial deposition on June 1 and first visit.
# dayIntervals[i,2] is the intervening time between initial deposition on first visit and second visit.
# etc.
# Need to add per_moose_deposition as data.
defecationRates = data.frame(reference = c(rep("Miquelle", 4),
rep("Joyal&Ricard", 3)),
mean = c(10.9, 19, 13, 11.2,
12.3, 13.5, 12.1),
se = c(0.5, 0.5, 0.7, 1,
NA,NA,NA),
sd = c(NA, NA, NA, NA,
5.8, 6.3, 3.9),
N = c(22, 8, 22, 21,
38, 38, 38),
ageClass = c('yearling', 'calf', 'yearling', 'adult',
'calf', 'adult', 'adult'),
sex = c('mf', 'm', 'm', 'mf',
'mf', 'f', 'f'),
status = c('captive', 'captive', 'captive', 'free-range',
'free-range', 'free-range', 'free-range'),
season = c(rep('summer', 4),
rep('winter', 3))
)
miquelleRows = defecationRates$reference == 'Miquelle'
defecationRates$sd[miquelleRows] = with(defecationRates, expr = {se * sqrt(N)})[miquelleRows]
data$per_moose_deposition = mean(defecationRates$mean)
# JAGS run NULL ---------------------------------------------------------------------------------------------------------
params = c("theta00", "p00", "lambda0")
# New autojags FN
ninc = 2000
nburn = 2000
nadapt = 10000
savePath = 'modelOutputs/null/'
fileNameTemp = paste0('out_null_', Sys.time() %>% format("%Y-%m-%d"), "_")
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_null.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileTemplate = fileNameTemp
)
# Continue if interrupted. CONTINUE = TRUE is the only argument needed; the
# backup image will be loaded to continue everything **AS IT WAS** at the end of
# the previous while loop. The arguments passed are *probably* not necessary,
# but better than risking defaults being set.
load('modelOutputs/null/latestBackup.Rdata')
output = autojags(data = NULL, parameters.to.save = params, n.chains = 4, n.adapt = nadapt, iter.increment = ninc,
n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
continue = T, savePath = savePath, fileTemplate = fileNameTemp
)
autojags(continue = T, savePath = savePath, fileTemplate = fileTemplate)
# what to initialize? in the sims, we needed to initialize R, and N1.
# N1 in particular needs to be initialized to avoid the impossible situation where there are fewer scats in the initial deposition than we picked up.
# Previously, initialized to the sum of all the clearing/collections that we made, which is sensible if p is high. If p is low, this should be estimated higher from there.
# Testing with just N1.
niter = 1e4
nburn = niter/10
runDate = Sys.time() %>% format("%Y-%m-%d")
a = Sys.time()
jagsOut = jags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_null.txt',
n.chains = 4, n.iter = niter, n.adapt = 10000,
n.burnin = nburn, parallel = T)
b = Sys.time()
b - a
save(jagsOut, file = paste0('modelOutputs/out_null_', runDate, '.Rdata'))
beepr::beep()
system(command = 'python sendMail.py')
# Optional update
load('modelOutputs/out_null.Rdata')
runDate = Sys.time() %>% format("%Y-%m-%d")
jagsOut_update = jagsUI:::update.jagsUI(jagsOut, parameters.to.save = params, n.iter = 3e4)
save(jagsOut_update, file = paste0('modelOutputs/out_null_update', runDate, '.Rdata'))
system(command = 'python sendMail.py')
# Another update
runDate = Sys.time() %>% format("%Y-%m-%d")
jagsOut_update = jagsUI:::update.jagsUI(jagsOut_update, parameters.to.save = params, n.iter = 3e4)
save(jagsOut_update, file = paste0('modelOutputs/out_null_update', runDate, '.Rdata'))
system(command = 'python sendMail.py')
# nimble run NULL ----------------------------------------------------------------------------------------------------------------------------------------------
library(nimble)
modCode = nimbleCode({
# Priors
p00 ~ dunif(0,1) # May need to make this informative if no information present
theta00 ~ dunif(-10, 5) #prior for theta intercept
lambda0 ~ dunif(-10, 5) #prior for lambda intercept
for(i in 1:nSites){
# Need model for N's
# This iteration of the model has a slightly different structure for N due to changes in simulation.
# Before, y_t ~ Bin(N_t-1, p)
# Now, y_t ~ Bin(N_t, p)
# Initial deposition is Poisson random, and occurs on June 1, 2016 (arbitrary selection, but is the first visit to any site).
N1[i] ~ dpois(lambda[i])
# Time 1 is visit 1, but indexed by 2, since we need to model the initial N. I choose to call that period before any visits time 0.
# Linear model for lambda. Include fixed/random effects here later
lambda[i] <- exp(lambda0) # somewhat immaterial except for mechanistic model of deposition process and observation.
for(v in 1:maxV){
N[i,1,v] <- N1[i]
}
# Deposition between time 0 and first visit is found in days[i,1]
for(t in 1:(maxT - 1)){
R[i,t] ~ dpois(theta[i]*days[i,t]) # Every round has some added deposition after we leave. It is dependent upon the DAYS in between visits.
# For instance, R[i,2] ~ dpois(theta[i]*days[i,2]), where days[i,2] is the intervening time
}
# Linear model for theta. Include fixed/random effects here later
theta[i] <- exp(theta00) # extend to include moose transect effect, spatial covariate effects. This is deposition per grid cell i, and therefore # moose will be calculated as per grid cell.
# Proceeding N's add new recruits and remove current counts from the previous time step's N.
# Recruits are random poisson variates with mean theta.
for(t in 2:maxT){
N[i,t,1] <- N[i,t-1,maxV] - y[i,t-1,maxV] + R[i,t-1] # First time going to a sampling unit what's there is what was there last time, minus what we picked up last time, plus what deposition happened last time.
for(v in 2:maxV){
N[i,t,v] <- N[i,t,v-1] - y[i,t,v-1] # Subsequent visits to a sampling unit what's there is what was there after the first visit, minus what we picked up, all the way to maxV (20 in 2016).
}
}
# Observation likelihood. Counts are conditional on population size at previous time step (after recruits and removals), and detection (which also depends on having visited the site).
for(t in 2:maxT){
for(v in 1:maxV){
# Homogeneous detection
p0[i,t,v] <- p00
# adjust p0 such that those sites not visited are set to 0. Initially, all sites are p0[i,t] = 0.8
# vis is a matrix of binary indicators with '1' being 'visited', and '0' being 'not visited'. Multiply by p0 to fix 'not visited' sites to p = 0, and obtain a new matrix.
p[i,t,v] <- p0[i,t,v] * vis[i,t,v]
y[i,t,v] ~ dbin(p[i,t,v], N[i,t,v])
}
}
#density[i] <- (theta[i] / per_moose_deposition) / 2500 # density of moose per grid cell (50m x 50m = 2500m)
}
})
modConsts = list(
maxT = data$maxT,
maxV = data$maxV,
nSites = data$nSites,
per_moose_deposition = mean(defecationRates$mean)
)
modData = list(
y = data$y,
vis = data$vis,
days = data$days
)
modInits = list(
N1 = rowSums(y),
theta00 = -6,
lambda0 = -4,
p00 = 0.5
)
model = nimbleModel(code = modCode, data = modData, inits = modInits, constants = modConsts)
Cmodel = compileNimble(model)
model_MCMC = buildMCMC(model)
Cmodel_MCMC = compileNimble(model_MCMC, project = model)
niter = 100000
a = Sys.time()
samples = runMCMC(mcmc = Cmodel_MCMC, niter = niter, nburnin = niter/4, nchains = 3, inits = modInits)
b = Sys.time()
b - a
save(samples, file = paste0('modelOutputs/out_null_nimble_', format(b, format = '%Y-%m-%d'),'.Rdata'))
system(command = 'python sendMail.py')
# Covariate analyses
# JAGS Full model, DIFFERENT theta lambda ---------------------------------------------------------------------------------------------------------------------------------------------------
# Setup & data
library(dplyr)
library(jagsUI)
source('functions.R')
load('data_cleaned.Rdata')
load('metadata.Rdata')
extract(data)
# Want to create a function of JAGS runs that operates similarly to autojags, but that saves intermediate output. I don't want interruptions cancelling work.
load('detectCovar.Rdata')
load('gridCovariates.Rdata')
extract(detectCovar)
# Add covariates to data
data$gridCovariates = gridCovariates
data$Dcov = Dcov
data$dogCov = dogCov
data$humCov = humCov
params = c("theta00", "p00", "lambda0",
# Lambda covars
'beta_lam_hab_softwood', 'beta_lam_hab_softwood', 'beta_lam_hab_hardwood', 'beta_lam_hab_wetland',
'beta_lam_hab_mixed', 'beta_lam_elev', 'beta_lam_highway', 'beta_lam_minor_road', 'beta_lam_northing', 'beta_lam_easting',
# Theta covars
'beta_theta_hab_softwood', 'beta_theta_hab_hardwood', 'beta_theta_hab_wetland', 'beta_theta_hab_mixed', 'beta_theta_elev',
'beta_theta_highway', 'beta_theta_minor_road', 'beta_theta_northing', 'beta_theta_easting',
# Detect covars - dog
'beta_detect_skye', 'beta_detect_scooby', 'beta_detect_ranger', 'beta_detect_max', 'beta_detect_hiccup',
# Detect covars - handler
'beta_detect_suzie', 'beta_detect_jennifer', 'beta_detect_justin',
# Detect covars - dist track in grid cell
'beta_detect_dist'
)
# New autojags FN
ninc = 1000
nburn = 1000
nadapt = 10000
savePath = 'modelOutputs/fullModel/'
fileNameTemp = paste0('out_full_', Sys.time() %>% format("%Y-%m-%d"), "_")
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_full.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileNameTemplate = fileNameTemp
)
# Continue if interrupted
ninc = 1000
nburn = 1000
savePath = 'modelOutputs/fullModel/'
# Change to continuing date
fileNameTemp = 'out_full_2018-08-19_'
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_full.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileNameTemplate = fileNameTemp, continue = TRUE, lastModel = output
)
# Critical model, DIFFERENT theta lambda ---------------------------------------------------------------
# Includes only those variables that are EXPECTED to correlate well.
# Setup & data
library(dplyr)
library(jagsUI)
source('functions.R')
load('data_cleaned.Rdata')
load('metadata.Rdata')
extract(data)
# Want to create a function of JAGS runs that operates similarly to autojags, but that saves intermediate output. I don't want interruptions cancelling work.
load('detectCovar.Rdata')
load('gridCovariates.Rdata')
extract(detectCovar)
# Add covariates to data
data$gridCovariates = gridCovariates
data$Dcov = Dcov
data$dogCov = dogCov
data$humCov = humCov
params = c("theta00", "p00", "lambda0",
# Lambda covars
'beta_lam_hab_softwood',
'beta_lam_hab_hardwood',
'beta_lam_hab_wetland',
'beta_lam_hab_mixed',
'beta_lam_elev',
#'beta_lam_highway',
#'beta_lam_minor_road',
'beta_lam_northing',
#'beta_lam_easting',
# Theta covars
'beta_theta_hab_softwood',
'beta_theta_hab_hardwood',
'beta_theta_hab_wetland',
'beta_theta_hab_mixed',
'beta_theta_elev',
#'beta_theta_highway',
#'beta_theta_minor_road',
'beta_theta_northing',
#'beta_theta_easting',
# Detect covars - dog
#'beta_detect_skye', 'beta_detect_scooby', 'beta_detect_ranger', 'beta_detect_max', 'beta_detect_hiccup',
# Detect covars - handler
#'beta_detect_suzie', 'beta_detect_jennifer', 'beta_detect_justin',
# Detect covars - dist track in grid cell
'beta_detect_dist'
)
# New autojags FN
ninc = 1000
nburn = 1000
nadapt = 10000
savePath = 'modelOutputs/rCrit/'
fileNameTemp = paste0('out_reduced_crit_', Sys.time() %>% format("%Y-%m-%d"), "_")
if(!dir.exists(savePath)){dir.create(savePath)}
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_reduced_crit.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileNameTemplate = fileNameTemp
)
# Continue if interrupted
ninc = 1000
nburn = 1000
savePath = 'modelOutputs/rCrit/'
# Change to continuing date
fileNameTemp = 'out_reduced_crit_2018-08-19_'
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_reduced_crit.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileNameTemplate = fileNameTemp, continue = TRUE, lastModel = output
)
# Continous model, DIFFERENT theta lambda ------------------------------------------------------------------------------------
# Only continuous factors
# Setup & data
library(dplyr)
library(jagsUI)
source('functions.R')
load('data_cleaned.Rdata')
load('metadata.Rdata')
extract(data)
# Want to create a function of JAGS runs that operates similarly to autojags, but that saves intermediate output. I don't want interruptions cancelling work.
load('detectCovar.Rdata')
load('gridCovariates.Rdata')
extract(detectCovar)
# Add covariates to data
data$gridCovariates = gridCovariates
data$Dcov = Dcov
data$dogCov = dogCov
data$humCov = humCov
params = c("theta00", "p00", "lambda0",
# Lambda covars
#'beta_lam_hab_softwood',
#'beta_lam_hab_hardwood',
#'beta_lam_hab_wetland',
#'beta_lam_hab_mixed',
'beta_lam_elev',
'beta_lam_highway',
'beta_lam_minor_road',
'beta_lam_northing',
'beta_lam_easting',
# Theta covars
#'beta_theta_hab_softwood',
#'beta_theta_hab_hardwood',
#'beta_theta_hab_wetland',
#'beta_theta_hab_mixed',
'beta_theta_elev',
'beta_theta_highway',
'beta_theta_minor_road',
'beta_theta_northing',
'beta_theta_easting',
# Detect covars - dog
#'beta_detect_skye', 'beta_detect_scooby', 'beta_detect_ranger', 'beta_detect_max', 'beta_detect_hiccup',
# Detect covars - handler
#'beta_detect_suzie', 'beta_detect_jennifer', 'beta_detect_justin',
# Detect covars - dist track in grid cell
'beta_detect_dist'
)
# New autojags FN
ninc = 1000
nburn = 1000
nadapt = 10000
savePath = 'modelOutputs/rCont/'
fileNameTemp = paste0('out_reduced_cont_', Sys.time() %>% format("%Y-%m-%d"), "_")
if(!dir.exists(savePath)){dir.create(savePath)}
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_reduced_continuous.txt',
n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileNameTemplate = fileNameTemp
)
# Continue if interrupted
ninc = 1000
nburn = 1000
savePath = 'modelOutputs/rCont/'
# Change to continuing date
fileNameTemp = 'out_reduced_crit_2018-08-20_'
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_reduced_continuous.txt',
n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileNameTemplate = fileNameTemp, continue = TRUE, lastModel = output
)
# Full model, shared theta lambda ---------------------------------------------------------------------------------------------------------------------------------------------------
# Setup & data
library(dplyr)
library(jagsUI)
source('functions.R')
load('data_cleaned.Rdata')
load('metadata.Rdata')
extract(data)
# Want to create a function of JAGS runs that operates similarly to autojags, but that saves intermediate output. I don't want interruptions cancelling work.
load('detectCovar.Rdata')
load('gridCovariates.Rdata')
extract(detectCovar)
# Add covariates to data
data$gridCovariates = gridCovariates
data$Dcov = Dcov
data$dogCov = dogCov
data$humCov = humCov
params = c("theta00", "p00", "lambda0",
# Lambda covars
'beta_hab_softwood',
'beta_hab_hardwood',
'beta_hab_wetland',
'beta_hab_mixed',
'beta_elev',
'beta_highway',
'beta_minor_road',
'beta_northing',
'beta_easting',
# Detect covars - dog
'beta_detect_skye', 'beta_detect_scooby', 'beta_detect_ranger', 'beta_detect_max', 'beta_detect_hiccup',
# Detect covars - handler
'beta_detect_suzie', 'beta_detect_jennifer', 'beta_detect_justin',
# Detect covars - dist track in grid cell
'beta_detect_dist'
)
# New autojags FN
ninc = 2000
nburn = 2000
nadapt = 10000
savePath = 'modelOutputs/fullModel_tl_shared/'
fileNameTemp = paste0('out_full_', Sys.time() %>% format("%Y-%m-%d"), "_")
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_full_tl_shared.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileTemplate = fileNameTemp
)
system(command = 'python sendMail.py')
# Continue if interrupted
ninc = 2000
nburn = 2000
savePath = 'modelOutputs/fullModel_tl_shared/'
# Change to continuing date
fileNameTemp = 'out_full_2018-09-03_'
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_full_tl_shared.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileTemplate = fileNameTemp, continue = TRUE
)
system(command = 'python sendMail.py')
# Critical model, shared theta lambda ----------------------------------------------------------------------------------------------------------------
# Includes only those variables that are EXPECTED to correlate well.
# Setup & data
library(dplyr)
library(jagsUI)
source('functions.R')
load('data_cleaned.Rdata')
load('metadata.Rdata')
extract(data)
# Want to create a function of JAGS runs that operates similarly to autojags, but that saves intermediate output. I don't want interruptions cancelling work.
load('detectCovar.Rdata')
load('gridCovariates.Rdata')
extract(detectCovar)
# Add covariates to data
data$gridCovariates = gridCovariates
data$Dcov = Dcov
data$dogCov = dogCov
data$humCov = humCov
params = c("theta00", "p00", "lambda0",
# Lambda covars
'beta_hab_softwood',
'beta_hab_hardwood',
'beta_hab_wetland',
'beta_hab_mixed',
'beta_elev',
#'beta_highway',
#'beta_minor_road',
'beta_northing',
#'beta_easting',
# Detect covars - dog
#'beta_detect_skye', 'beta_detect_scooby', 'beta_detect_ranger', 'beta_detect_max', 'beta_detect_hiccup',
# Detect covars - handler
#'beta_detect_suzie', 'beta_detect_jennifer', 'beta_detect_justin',
# Detect covars - dist track in grid cell
'beta_detect_dist'
)
# New autojags FN
ninc = 2000
nburn = 2000
nadapt = 10000
savePath = 'modelOutputs/rCrit_tl_shared/'
if(!dir.exists(savePath)){dir.create(savePath)}
fileNameTemp = paste0('out_reduced_crit_tl_shared_', Sys.time() %>% format("%Y-%m-%d"), "_")
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_reduced_crit_tl_shared.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileTemplate = fileNameTemp
)
system(command = 'python sendMail.py')
# Continue if interrupted
fileNameTemp = 'out_reduced_crit_tl_shared_'
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_reduced_crit_tl_shared.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileNameTemplate = fileNameTemp, continue = TRUE
)
# Continuous model, shared theta lambda ----------------------------------------------------------------------------------------------------------------
# Includes only those variables that are EXPECTED to correlate well.
# Setup & data
library(dplyr)
library(jagsUI)
source('functions.R')
load('data_cleaned.Rdata')
load('metadata.Rdata')
extract(data)
# Want to create a function of JAGS runs that operates similarly to autojags, but that saves intermediate output. I don't want interruptions cancelling work.
load('detectCovar.Rdata')
load('gridCovariates.Rdata')
extract(detectCovar)
# Add covariates to data
data$gridCovariates = gridCovariates
data$Dcov = Dcov
data$dogCov = dogCov
data$humCov = humCov
params = c("theta00", "p00", "lambda0",
# Lambda covars
#'beta_hab_softwood',
#'beta_hab_hardwood',
#'beta_hab_wetland',
#'beta_hab_mixed',
'beta_elev',
'beta_highway',
'beta_minor_road',
'beta_northing',
#'beta_easting',
# Detect covars - dog
#'beta_detect_skye', 'beta_detect_scooby', 'beta_detect_ranger', 'beta_detect_max', 'beta_detect_hiccup',
# Detect covars - handler
#'beta_detect_suzie', 'beta_detect_jennifer', 'beta_detect_justin',
# Detect covars - dist track in grid cell
'beta_detect_dist'
)
# New autojags FN
ninc = 2000
nburn = 2000
nadapt = 10000
savePath = 'modelOutputs/rCont_tl_shared/'
fileNameTemp = paste0('out_reduced_cont_tl_shared_', Sys.time() %>% format("%Y-%m-%d"), "_")
if(!dir.exists(savePath)){dir.create(savePath)}
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_reduced_continuous_tl_shared.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileTemplate = fileNameTemp
)
system(command = 'python sendMail.py')
# Continue if interrupted
ninc = 1000
nburn = 1000
nadapt = 10000
savePath = 'modelOutputs/rCont_tl_shared/'
# Change to match whatever continuing from
fileNameTemp = 'out_reduced_cont_tl_shared_DATEDATEDATEDATE'
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_reduced_continuous_tl_shared.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileNameTemplate = fileNameTemp, continue = TRUE, lastModel = output
)
# Detection distance covariate only -------------------------------------------------------------------------------------------------------------------
# An improvement (?) on the null model.
# Includes only those variables that are EXPECTED to correlate well.
# Setup & data
library(dplyr)
library(jagsUI)
source('functions.R')
load('data_cleaned.Rdata')
load('metadata.Rdata')
extract(data)
# Want to create a function of JAGS runs that operates similarly to autojags, but that saves intermediate output. I don't want interruptions cancelling work.
load('detectCovar.Rdata')
load('gridCovariates.Rdata')
extract(detectCovar)
# Add covariates to data
data$gridCovariates = gridCovariates
data$Dcov = Dcov
data$dogCov = dogCov
data$humCov = humCov
params = c("theta00", "p00", "lambda0", 'beta_detect_dist')
# New autojags FN
ninc = 2000
nburn = 2000
nadapt = 10000
savePath = 'modelOutputs/rDcov/'
fileNameTemp = paste0('out_reduced_Dcov_', Sys.time() %>% format("%Y-%m-%d"), "_")
if(!dir.exists(savePath)){dir.create(savePath)}
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_reduced_Dcov_only.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileTemplate = fileNameTemp
)
system(command = 'python sendMail.py')
# Continue if interrupted
ninc = 2000
nburn = 2000
nadapt = 10000
savePath = 'modelOutputs/rDcov/'
# Change to match whatever continuing from
fileNameTemp = 'out_reduced_Dcov_2018-08-19_'
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_reduced_Dcov_only.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileNameTemplate = fileNameTemp, continue = TRUE, lastModel = output
)
# Model against temperature ---------------------------
# Model to test against the effects of temperature
# Setup & data
library(dplyr)
library(jagsUI)
source('functions.R')
load('data_cleaned.Rdata')
load('metadata.Rdata')
extract(data)
# Want to create a function of JAGS runs that operates similarly to autojags, but that saves intermediate output. I don't want interruptions cancelling work.
load('detectCovar.Rdata')
load('gridCovariates.Rdata')
extract(detectCovar)
# Add covariates to data
data$gridCovariates = gridCovariates
data$Dcov = Dcov
data$dogCov = dogCov
data$humCov = humCov
params = c("theta00", "p00", "lambda0",
# Lambda covars
'beta_hab_softwood',
'beta_hab_hardwood',
'beta_hab_wetland',
'beta_hab_mixed',
#'beta_elev',
'beta_highway',
'beta_minor_road',
#'beta_northing',
#'beta_easting',
# Detect covars - dog
#'beta_detect_skye', 'beta_detect_scooby', 'beta_detect_ranger', 'beta_detect_max', 'beta_detect_hiccup',
# Detect covars - handler
#'beta_detect_suzie', 'beta_detect_jennifer', 'beta_detect_justin',
# Detect covars - dist track in grid cell
'beta_detect_dist'
)
# New autojags FN
ninc = 2000
nburn = 2000
nadapt = 10000
savePath = 'modelOutputs/no_temp/'
fileNameTemp = paste0('out_no_temp', Sys.time() %>% format("%Y-%m-%d"), "_")
if(!dir.exists(savePath)){dir.create(savePath)}
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_no_temp.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileTemplate = fileNameTemp
)
system(command = 'python sendMail.py')
# Continue if interrupted
ninc = 2000
nburn = 2000
nadapt = 10000
savePath = 'modelOutputs/no_temp/'
# Change to match whatever continuing from
fileNameTemp = 'out_no_temp_2018-09-18_'
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_no_temp.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileTemplate = fileNameTemp, continue = TRUE
)
system(command = 'python sendMail.py')
# Model against temperature, and detection ----------------------------
# Model to test against the effects of temperature, omitting track length on detection
# Setup & data
library(dplyr)
library(jagsUI)
source('functions.R')
load('data_cleaned.Rdata')
load('metadata.Rdata')
extract(data)
# Want to create a function of JAGS runs that operates similarly to autojags, but that saves intermediate output. I don't want interruptions cancelling work.
load('detectCovar.Rdata')
load('gridCovariates.Rdata')
extract(detectCovar)
# Add covariates to data
data$gridCovariates = gridCovariates
data$Dcov = Dcov
data$dogCov = dogCov
data$humCov = humCov
params = c("theta00", "p00", "lambda0",
# Lambda covars
'beta_hab_softwood',
'beta_hab_hardwood',
'beta_hab_wetland',
'beta_hab_mixed',
#'beta_elev',
'beta_highway',
'beta_minor_road'#,
#'beta_northing',
#'beta_easting',
# Detect covars - dog
#'beta_detect_skye', 'beta_detect_scooby', 'beta_detect_ranger', 'beta_detect_max', 'beta_detect_hiccup',
# Detect covars - handler
#'beta_detect_suzie', 'beta_detect_jennifer', 'beta_detect_justin',
# Detect covars - dist track in grid cell
#'beta_detect_dist'
)
# New autojags FN
ninc = 2000
nburn = 2000
nadapt = 10000
savePath = 'modelOutputs/no_temp_no_dcov/'
fileNameTemp = paste0('out_no_temp_no_dcov', Sys.time() %>% format("%Y-%m-%d"), "_")
if(!dir.exists(savePath)){dir.create(savePath)}
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_no_temp_no_dcov.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileTemplate = fileNameTemp
)
system(command = 'python sendMail.py')
# Continue if interrupted
ninc = 2000
nburn = 2000
nadapt = 10000
savePath = 'modelOutputs/no_temp_no_dcov/'
# Change to match whatever continuing from
fileNameTemp = 'out_no_temp_no_dcov2018-09-20_'
output = autojags(data = data, inits = inits, parameters.to.save = params, model.file = 'model_cov_no_temp_no_dcov.txt', n.chains = 4, n.adapt = nadapt,
iter.increment = ninc, n.burnin = nburn, save.all.iter = T, parallel = T, n.cores = 4, max.iter = 1e6,
savePath = savePath, fileTemplate = fileNameTemp, continue = TRUE
)
system(command = 'python sendMail.py')