-
Notifications
You must be signed in to change notification settings - Fork 0
/
supplementary_stuff.R
495 lines (351 loc) · 18.9 KB
/
supplementary_stuff.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
#supplementary
#data distribution check####
ppcontrol_mod_nb= tsglm(ppcont_covs_dat$abundance, model = list(past_obs=c(1,12)),
distr = "nbinom",
xreg = ppcont_covs_dat[,3:5],
link = "log")
ppexclosure_mod_nb= tsglm(ppexcl_covs_dat$abundance, model = list(past_obs=c(1,12)),
distr = "nbinom",
xreg = ppexcl_covs_dat[,3:5],
link = "log")
ppcontrol_mod_poi= tsglm(ppcont_covs_dat$abundance, model = list(past_obs=c(1,12)),
distr = "pois",
xreg = ppcont_covs_dat[,3:5],
link = "log")
ppexclosure_mod_poi= tsglm(ppexcl_covs_dat$abundance, model = list(past_obs=c(1,12)),
distr = "pois",
xreg = ppexcl_covs_dat[,3:5],
link = "log")
AIC(ppcontrol_mod_nb)
AIC(ppexclosure_mod_nb)
AIC(ppcontrol_mod_poi)
AIC(ppexclosure_mod_poi)
pbcontrol_mod_nb= tsglm(pbcont_covs_dat$abundance, model = list(past_obs=c(1,12)),
distr = "nbinom",
xreg = pbcont_covs_dat[,3:5],
link = "log")
pbexclosure_mod_nb= tsglm(pbexcl_covs_dat$abundance, model = list(past_obs=c(1,12)),
distr = "nbinom",
xreg = pbexcl_covs_dat[,3:5],
link = "log")
pbcontrol_mod_poi= tsglm(pbcont_covs_dat$abundance, model = list(past_obs=c(1,12)),
distr = "pois",
xreg = pbcont_covs_dat[,3:5],
link = "log")
pbexclosure_mod_poi= tsglm(pbexcl_covs_dat$abundance, model = list(past_obs=c(1,12)),
distr = "pois",
xreg = pbexcl_covs_dat[,3:5],
link = "log")
AIC(pbcontrol_mod_nb)
AIC(pbexclosure_mod_nb)
AIC(pbcontrol_mod_poi)
AIC(pbexclosure_mod_poi)
#AR structure####
#pacf
par(mfrow=c(1,2))
pacf(ppcont_covs_dat$abundance, lag.max = 12,main="desert pocket mouse")
pacf(pbcont_covs_dat$abundance, lag.max = 12,main="Bailey's pocket mouse")
#acf
par(mfrow=c(1,2))
acf(ppcont_covs_dat$abundance, lag.max = 12,main="desert pocket mouse")
acf(pbcont_covs_dat$abundance, lag.max = 12,main="Bailey's pocket mouse")
#acf of model residuals
acf(ppcontrol_mod_nb$residuals, lag.max = 12,main="desert pocket mouse")
acf(pbcontrol_mod_nb$residuals, lag.max = 12,main="Bailey's pocket mouse")
#interpolated data length####
mdate=read.csv("https://raw.githubusercontent.com/weecology/PortalData/main/Rodents/moon_dates.csv")
#PB
pbm=mdate%>%filter(!newmoonnumber<278, !newmoonnumber>396)
pbm_na=pbm%>%filter(is.na(censusdate))
length(pbm_na$newmoonnumber)/length(pbm$newmoonnumber)
#PP
ppm=mdate%>%filter(!newmoonnumber<411, !newmoonnumber>526)
ppm_na=ppm%>%filter(is.na(censusdate))
length(ppm_na$newmoonnumber)/length(ppm$newmoonnumber)*100
#intercept-slope covariance plot####
#PP
c1=ggplot(coef_df_PP, aes(x=intercept, y=temp, col=treatment))+geom_point()+theme_classic()+
geom_smooth(method="lm")+ylab("mean temp (lag=1)")+xlab("")+
ggtitle(expression(italic("C. penicillatus")))+scale_color_manual(values=c(control="#9900cc", removal="#FFcc00"))+
scale_y_continuous(n.breaks=3, labels = scales::label_number(accuracy = 0.01))
c2=ggplot(coef_df_PP, aes(x=intercept, y=warm_precip, col=treatment))+geom_point()+theme_classic()+
geom_smooth(method="lm")+ylab("warm precipitation")+
scale_color_manual(values=c(control="#9900cc", removal="#FFcc00"))+xlab("")+
scale_y_continuous(n.breaks=3, labels = scales::label_number(accuracy = 0.01))
c3=ggplot(coef_df_PP, aes(x=intercept, y=cool_precip, col=treatment))+geom_point()+theme_classic()+
geom_smooth(method="lm")+ylab("cool precipitation")+
scale_color_manual(values=c(control="#9900cc", removal="#FFcc00"))+
scale_y_continuous(n.breaks=3, labels = scales::label_number(accuracy = 0.01))
ggarrange(c1,c2,c3, common.legend = T, nrow=3, legend="bottom")
#PB
z1=ggplot(coef_df_PB, aes(x=intercept, y=temp, col=treatment))+geom_point()+theme_classic()+
geom_smooth(method="lm")+ylab("mean temp (lag=1)")+xlab("")+
ggtitle(expression(italic("C. baileyi")))+scale_color_manual(values=c(control="#9900cc", removal="#FFcc00"))+
scale_y_continuous(n.breaks=3, labels = scales::label_number(accuracy = 0.01))
z2=ggplot(coef_df_PB, aes(x=intercept, y=warm_precip, col=treatment))+geom_point()+theme_classic()+
geom_smooth(method="lm")+ylab("warm precipitation")+
scale_color_manual(values=c(control="#9900cc", removal="#FFcc00"))+xlab("")+
scale_y_continuous(n.breaks=3, labels = scales::label_number(accuracy = 0.01))
z3=ggplot(coef_df_PB, aes(x=intercept, y=cool_precip, col=treatment))+geom_point()+theme_classic()+
geom_smooth(method="lm")+ylab("cool precipitation")+
scale_color_manual(values=c(control="#9900cc", removal="#FFcc00"))+
scale_y_continuous(n.breaks=3, labels = scales::label_number(accuracy = 0.01))
ggarrange(z1,z2,z3, common.legend = T, nrow=3, legend="bottom")
#covariate correlation####
get_temp_warmppt_corr=function(split, model){
analysis_set=analysis(split)
covariates=analysis_set[,3:5]
temp_wprecip=cor.test(analysis_set[,3], analysis_set[,4])$estimate
}
get_temp_coolppt_corr=function(split, model){
analysis_set=analysis(split)
covariates=analysis_set[,3:5]
temp_cprecip=cor.test(analysis_set[,3], analysis_set[,5])$estimate
}
get_warmppt_coolppt_corr=function(split, model){
analysis_set=analysis(split)
covariates=analysis_set[,3:5]
wprecip_cprecip=cor.test(analysis_set[,4], analysis_set[,5])$estimate
}
#PP
#all data
cor.test(ppcont_covs_dat$meantemp_lag1, ppcont_covs_dat$warm_precip)
cor.test(ppcont_covs_dat$meantemp_lag1, ppcont_covs_dat$cool_precip)
cor.test(ppcont_covs_dat$warm_precip, ppcont_covs_dat$cool_precip)
#at multiple origins
sh1=map(PPcontrol_dat$splits, get_temp_warmppt_corr)
sh2=map(PPcontrol_dat$splits, get_temp_coolppt_corr)
sh3=map(PPcontrol_dat$splits, get_warmppt_coolppt_corr)
sh11=as.vector(unlist(sh1))
sh22=as.vector(unlist(sh2))
sh33=as.vector(unlist(sh3))
par(mfrow=c(1,3))
hist(sh11, main="temperature-warm precipitation", xlab="")
hist(sh22, main ="temperature-cool precipitation", xlab="Pearson's correlation coefficient")
hist(sh33, main="warm-cool precipitation", xlab="")
mtext(expression(italic("C. penicillatus")), side = 3, line = -1.5, outer = TRUE, font=12)
#PB
#all data
cor.test(pbcont_covs_dat$meantemp_lag1, pbcont_covs_dat$warm_precip)
cor.test(pbcont_covs_dat$meantemp_lag1, pbcont_covs_dat$cool_precip)
cor.test(pbcont_covs_dat$warm_precip, pbcont_covs_dat$cool_precip)
zh1=map(PBcontrol_dat$splits, get_temp_warmppt_corr)
zh2=map(PBcontrol_dat$splits, get_temp_coolppt_corr)
zh3=map(PBcontrol_dat$splits, get_warmppt_coolppt_corr)
zh11=as.vector(unlist(zh1))
zh22=as.vector(unlist(zh2))
zh33=as.vector(unlist(zh3))
par(mfrow=c(1,3))
hist(zh11, main="temperature-warm precipitation", xlab="")
hist(zh22, main ="temperature-cool precipitation", xlab="Pearson's correlation coefficient")
hist(zh33, main="warm-cool precipitation", xlab="")
mtext(expression(italic("C. baileyi")), side = 3, line = -1.5, outer = TRUE, font=12)
#parameter covariances####
get_cov_matrix=function(split, model) {
covariance_matrix=invertinfo(model$info.matrix_corrected, silent=T, stopOnError = F)$vcov #compute a covariance matrix
#from a given Fisher information matrix by inversion (used info.matrix output of model)
}
#PB control model
d1=pmap(list(PBcontrol_dat$splits, PBcontrol_dat$model), get_cov_matrix)
d2=do.call(rbind.data.frame, d1)
parameters=c("Intercept", "beta_1", "beta_12", "meantemp_lag1", "warm_precip", "cool_precip")
params=rep(parameters,48)
label_rows1=d2%>%cbind(d2, params)%>%select(,7:13)
meantemp_wprecip=label_rows1%>%select(meantemp_lag1, params)%>%filter(params=="warm_precip")
meantemp_cprecip=label_rows1%>%select(meantemp_lag1, params)%>%filter(params=="cool_precip")
cprecip_wprecip=label_rows1%>%select(cool_precip, params)%>%filter(params=="warm_precip")
#PB exclosure model
dx1=pmap(list(PBexclosure_dat$splits, PBexclosure_dat$model), get_cov_matrix)
dx2=do.call(rbind.data.frame, dx1)
parameters=c("Intercept", "beta_1", "beta_12", "meantemp_lag1", "warm_precip", "cool_precip")
params=rep(parameters,48)
label_rows1x=dx2%>%cbind(dx2, params)%>%select(,7:13)
meantemp_wprecipx=label_rows1x%>%select(meantemp_lag1, params)%>%filter(params=="warm_precip")
meantemp_cprecipx=label_rows1x%>%select(meantemp_lag1, params)%>%filter(params=="cool_precip")
cprecip_wprecipx=label_rows1x%>%select(cool_precip, params)%>%filter(params=="warm_precip")
par(mfrow=c(2,3))
hist(meantemp_wprecip$meantemp_lag1, main ="meantemp-warm precip", xlab="", ylab="control")
hist(meantemp_cprecip$meantemp_lag1, main="meantemp-cool precip", xlab="", ylab="")
hist(cprecip_wprecip$cool_precip, main="cool-warm precip", xlab="", ylab="")
mtext(expression(italic("C. baileyi")), side = 3, line = -1.5, outer = TRUE, font=12)
hist(meantemp_wprecipx$meantemp_lag1, main =NULL, xlab="", ylab="removal")
hist(meantemp_cprecipx$meantemp_lag1, main=NULL, xlab="covariance", ylab="")
hist(cprecip_wprecipx$cool_precip, main=NULL, xlab="", ylab="")
mtext(expression(italic("C. baileyi")), side = 3, line = -1.5, outer = TRUE, font=12)
#PP control model
f1=pmap(list(PPcontrol_dat$splits, PPcontrol_dat$model), get_cov_matrix)
f2=do.call(rbind.data.frame, f1)
parameters=c("Intercept", "beta_1", "beta_12", "meantemp_lag1", "warm_precip", "cool_precip")
params=rep(parameters,45)
label_rows2=f2%>%cbind(f2, params)%>%select(,7:13)
PPmeantemp_wprecip=label_rows2%>%select(meantemp_lag1, params)%>%filter(params=="warm_precip")
PPmeantemp_cprecip=label_rows2%>%select(meantemp_lag1, params)%>%filter(params=="cool_precip")
PPcprecip_wprecip=label_rows2%>%select(cool_precip, params)%>%filter(params=="warm_precip")
#PP exclosure model
fx1=pmap(list(PPexclosure_dat$splits, PPexclosure_dat$model), get_cov_matrix)
fx2=do.call(rbind.data.frame, fx1)
parameters=c("Intercept", "beta_1", "beta_12", "meantemp_lag1", "warm_precip", "cool_precip")
params=rep(parameters,45)
label_rows2x=fx2%>%cbind(fx2, params)%>%select(,7:13)
PPmeantemp_wprecipx=label_rows2x%>%select(meantemp_lag1, params)%>%filter(params=="warm_precip")
PPmeantemp_cprecipx=label_rows2x%>%select(meantemp_lag1, params)%>%filter(params=="cool_precip")
PPcprecip_wprecipx=label_rows2x%>%select(cool_precip, params)%>%filter(params=="warm_precip")
par(mfrow=c(2,3))
hist(PPmeantemp_wprecip$meantemp_lag1, main ="meantemp-warm precip", xlab="", ylab="control")
hist(PPmeantemp_cprecip$meantemp_lag1, main="meantemp-cool precip", xlab="", ylab="")
hist(PPcprecip_wprecip$cool_precip, main="cool-warm precip", xlab="", ylab="")
mtext(expression(italic("C. penicillatus")), side = 3, line = -1.5, outer = TRUE, font=12)
hist(PPmeantemp_wprecipx$meantemp_lag1, main =NULL, xlab="", ylab="removal")
hist(PPmeantemp_cprecipx$meantemp_lag1, main=NULL, xlab="covariance", ylab="")
hist(PPcprecip_wprecipx$cool_precip, main=NULL, xlab="", ylab="")
mtext(expression(italic("C. baileyi")), side = 3, line = -1.5, outer = TRUE, font=12)
#parameter correlations####
#PP control
pp_c1=pmap(list(PPcontrol_dat$splits, PPcontrol_dat$model), get_cov_matrix)
pp_cd1=map(pp_c1, cov2cor)
pp_cd2=do.call(rbind.data.frame, pp_cd1)
parameters=c("Intercept", "beta_1", "beta_12", "meantemp_lag1", "warm_precip", "cool_precip")
params=rep(parameters,45)
label_rowsc1=pp_cd2%>%cbind(pp_cd2, params)%>%select(,7:13)
meantemp_wprecipc=label_rowsc1%>%select(meantemp_lag1, params)%>%filter(params=="warm_precip")
meantemp_cprecipc=label_rowsc1%>%select(meantemp_lag1, params)%>%filter(params=="cool_precip")
cprecip_wprecipc=label_rowsc1%>%select(cool_precip, params)%>%filter(params=="warm_precip")
#PP exclosure
pp_d1=pmap(list(PPexclosure_dat$splits, PPexclosure_dat$model), get_cov_matrix)
pp_dc1=map(pp_d1, cov2cor)
pp_dc2=do.call(rbind.data.frame, pp_dc1)
parameters=c("Intercept", "beta_1", "beta_12", "meantemp_lag1", "warm_precip", "cool_precip")
params=rep(parameters,45)
label_rowscx1=pp_dc2%>%cbind(pp_dc2, params)%>%select(,7:13)
meantemp_wprecip2=label_rowscx1%>%select(meantemp_lag1, params)%>%filter(params=="warm_precip")
meantemp_cprecip2=label_rowscx1%>%select(meantemp_lag1, params)%>%filter(params=="cool_precip")
cprecip_wprecip2=label_rowscx1%>%select(cool_precip, params)%>%filter(params=="warm_precip")
par(mfrow=c(2,3))
hist(meantemp_wprecipc$meantemp_lag1, main ="meantemp-warm precip", xlab="", ylab="control")
hist(meantemp_cprecipc$meantemp_lag1, main="meantemp-cool precip", xlab="", ylab="")
hist(cprecip_wprecipc$cool_precip, main="cool-warm precip", xlab="", ylab="")
mtext(expression(italic("C. penicillatus")), side = 3, line = -1.5, outer = TRUE, font=12)
hist(meantemp_wprecip2$meantemp_lag1, main =NULL, xlab="", ylab="removal")
hist(meantemp_cprecip2$meantemp_lag1, main=NULL, xlab="correlation", ylab = "")
hist(cprecip_wprecip2$cool_precip, main=NULL, xlab="", ylab="")
mtext(expression(italic("C. penicillatus")), side = 3, line = -1.5, outer = TRUE, font=12)
#PB control
pb_c1=pmap(list(PBcontrol_dat$splits, PBcontrol_dat$model), get_cov_matrix)
pb_cd1=map(pb_c1, cov2cor)
pb_cd2=do.call(rbind.data.frame, pb_cd1)
parameters=c("Intercept", "beta_1", "beta_12", "meantemp_lag1", "warm_precip", "cool_precip")
params=rep(parameters,48)
label_rowsd1=pb_cd2%>%cbind(pb_cd2, params)%>%select(,7:13)
meantemp_wprecipd=label_rowsd1%>%select(meantemp_lag1, params)%>%filter(params=="warm_precip")
meantemp_cprecipd=label_rowsd1%>%select(meantemp_lag1, params)%>%filter(params=="cool_precip")
cprecip_wprecipd=label_rowsd1%>%select(cool_precip, params)%>%filter(params=="warm_precip")
#PB exclosure
pb_d1=pmap(list(PBexclosure_dat$splits, PBexclosure_dat$model), get_cov_matrix)
pb_dc1=map(pb_d1, cov2cor)
pb_dc2=do.call(rbind.data.frame, pb_dc1)
parameters=c("Intercept", "beta_1", "beta_12", "meantemp_lag1", "warm_precip", "cool_precip")
params=rep(parameters,48)
label_rowsdx1=pb_dc2%>%cbind(pb_dc2, params)%>%select(,7:13)
meantemp_wprecipd2=label_rowsdx1%>%select(meantemp_lag1, params)%>%filter(params=="warm_precip")
meantemp_cprecipd2=label_rowsdx1%>%select(meantemp_lag1, params)%>%filter(params=="cool_precip")
cprecip_wprecipd2=label_rowsdx1%>%select(cool_precip, params)%>%filter(params=="warm_precip")
par(mfrow=c(2,3))
hist(meantemp_wprecipd$meantemp_lag1, main ="meantemp-warm precip", xlab="", ylab="control")
hist(meantemp_cprecipd$meantemp_lag1, main="meantemp-cool precip", xlab="", ylab="")
hist(cprecip_wprecipd$cool_precip, main="cool-warm precip", xlab="", ylab="")
mtext(expression(italic("C. baileyi")), side = 3, line = -1.5, outer = TRUE, font=12)
hist(meantemp_wprecipd2$meantemp_lag1, main =NULL, xlab="", ylab="removal")
hist(meantemp_cprecipd2$meantemp_lag1, main=NULL, xlab="correlation", ylab = "")
hist(cprecip_wprecipd2$cool_precip, main=NULL, xlab="", ylab="")
mtext(expression(italic("C. baileyi")), side = 3, line = -1.5, outer = TRUE, font=12)
#models with scaled covariates####
s_covar=covars%>%mutate(meantemps=scale(meantemp_lag1, center = T, scale = T)[, 1],
wprecs=scale(warm_precip, center = T, scale = T)[, 1],
cprecs=scale(cool_precip, center = T, scale = T)[, 1])
#PP scaled data
ppcont_covs=right_join(s_covar, ppcont_dat)%>%
select(newmoonnumber, meantemps,
wprecs, cprecs, PP)%>%rename("abundance"="PP")
ppexcl_covs=right_join(s_covar, ppexcl_dat)%>%
select(newmoonnumber, meantemps,
wprecs, cprecs, PP)%>%rename("abundance"="PP")
#select data from Sept 2010- Dec 2019
ppcont_covs_dat=ppcont_covs%>% filter(!newmoonnumber<411, !newmoonnumber>526)
ppexcl_covs_dat=ppexcl_covs%>% filter(!newmoonnumber<411, !newmoonnumber>526)
#interpolate missing data
ppcont_covs_dat$abundance=round_na.interp(ppcont_covs_dat$abundance)
ppexcl_covs_dat$abundance=round_na.interp(ppexcl_covs_dat$abundance)
#PB scaled data
pbcont_covs=right_join(s_covar, pbcont_dat)%>%
select(newmoonnumber, meantemps,
wprecs, cprecs, PB)%>%rename("abundance"="PB")
pbexcl_covs=right_join(s_covar, pbexcl_dat)%>%
select(newmoonnumber, meantemps,
wprecs, cprecs, PB)%>%rename("abundance"="PB")
#select data from Dec 1999- June 2009
pbcont_covs_dat=pbcont_covs%>%filter(!newmoonnumber<278, !newmoonnumber>396)
pbexcl_covs_dat=pbexcl_covs%>%filter(!newmoonnumber<278, !newmoonnumber>396)
#interpolate missing data
pbcont_covs_dat$abundance=round_na.interp(pbcont_covs_dat$abundance)
pbexcl_covs_dat$abundance=round_na.interp(pbexcl_covs_dat$abundance)
rolling_mod=function(split) {
analysis_set= analysis(split) #get dataframe
fit_model= tsglm(analysis_set[,"abundance"], model = list(past_obs=c(1,12)),
distr = "nbinom",
xreg = analysis_set[,2:4],
link = "log")
}
get_preds=function(split, model,y_source) {
analysis_set= analysis(split) #get training data
assessment_set=assessment(split) #get testing data
model$ts = y_source$ts #select the initial condition from matching model
model$response = y_source$response
preds=predict(model, n.ahead=12, newxreg= assessment_set[,2:4])$pred
}
#model with AR(13)####
rolling_mod=function(split) {
analysis_set= analysis(split) #get dataframe
fit_model= tsglm(analysis_set[,"abundance"], model = list(past_obs=c(1,13)),
distr = "nbinom",
xreg = analysis_set[,3:5],
link = "log")
}
get_preds=function(split, model,y_source) {
analysis_set= analysis(split) #get training data
assessment_set=assessment(split) #get testing data
model$ts = y_source$ts #select the initial condition from matching model
model$response = y_source$response
preds=predict(model, n.ahead=13, newxreg= assessment_set[,3:5])$pred
}
mod_evals_same=function(split, preds_same) {
assessment_set= assessment(split) #get validation data
holdout= assessment_set[,"abundance"] #select relevant column in dataframe
preds_same= preds_same
rmse1_same=pmap(list(holdout[1], preds_same[1]), Metrics::rmse)
rmse6_same=pmap(list(holdout[6], preds_same[6]), Metrics::rmse)
rmse12_same=pmap(list(holdout[13], preds_same[13]), Metrics::rmse)
rmse_same=cbind(rmse1_same, rmse6_same, rmse12_same)
}
mod_evals_switch=function(split, preds_switch) {
assessment_set= assessment(split) #get validation data
holdout= assessment_set[,"abundance"] #select relevant column in dataframe
preds_switch= preds_switch
rmse1_switch=pmap(list(holdout[1], preds_switch[1]), Metrics::rmse)
rmse6_switch=pmap(list(holdout[6], preds_switch[6]), Metrics::rmse)
rmse12_switch=pmap(list(holdout[13], preds_switch[13]), Metrics::rmse)
rmse_switch=cbind(rmse1_switch, rmse6_switch, rmse12_switch)
}
#run before building rolling origin bject
n_moons_yr=13
n_yrs=5
n_moons_train=n_moons_yr*n_yrs
n_moons_test=n_moons_yr*1
#run before making forecasts
#PP
m=rep(seq(1:39), each=13) #no.of splits
code1="same"
code2="switched"
#PB
m=rep(seq(1:42), each=13)
code1="same"
code2="switched"