-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGAMs - explanatory variables.R
312 lines (240 loc) · 18.5 KB
/
GAMs - explanatory variables.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
library(stats)
library (mgcv)
###------GAMs of fall MD population density including explanatory variables, no autocorrelation
# Data Analysis of data that is added for this step
count_nas(AllMeans$AvrgWinterMinTemp)#0, ok
count_nas(AllMeans$FawnFall_mean)#7
count_nas(AllMeans$FemaleFall_mean)#7
count_nas(AllMeans$MaleFall_mean)#7
count_nas(AllMeans$FawnTotalRatioFall_mean)#7
####Check for outliers of data that is added for this step
plot(AllMeans$AvrgWinterMinTemp)
###Effect of Average Minimum Winter Temperature on each macrounit
gam_temp <- gam(MDperKMsqFall_mean ~ s(AvrgWinterMinTemp, bs="cs"), data=AllMeans)
gam_temp <- gam(MDperKMsqFall_mean ~ s(AvrgWinterMinTemp, by=macrounit, bs="cs") + macrounit, data=AllMeans)
gam_temp <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") +s(AvrgWinterMinTemp, bs="cs"), data=AllMeans)
gam_temp <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + s(AvrgWinterMinTemp, by=macrounit, bs="cs") + macrounit, data=AllMeans)
gam_temp <- gam(MDperKMsqFall_mean ~ s(year, by=macrounit, bs="cs") +s(AvrgWinterMinTemp, bs="cs") + macrounit, data=AllMeans)
gam_temppred <- data.frame(year=AllMeans$year, macrounit=AllMeans$macrounit, AvrgWinterMinTemp=AllMeans$AvrgWinterMinTemp)
gam_temppred <- cbind(gam_temppred, predict(gam_temp, se.fit=T, newdata=data.frame("year"=AllMeans$year, "macrounit"=AllMeans$macrounit, "AvrgWinterMinTemp"=AllMeans$AvrgWinterMinTemp), type="response"))
macrounitplots(glmobject = gam_temppred,xcol="AvrgWinterMinTemp",title="gam_temp fall - effect of Mean Winter Minimum Temperature",colour="red")
macrounitplots(glmobject = gam_temppred,title="gam_temp fall - effect of Mean Winter Minimum Temperature",colour="red")
summary(gam_temp)
AIC(gam_temp)
par(oma=c(2,0,2,0))
gam.check(gam_temp)
# title("Gam_all2 fall residual check", outer=TRUE)
# #comparison nullmodell gam_all09 and gam_all2
# anova(gam_all0, gam_all2, test="F")
# Check Residuals for temporal autocorrelation
gam_tempres <- residuals(gam_temp, type = "deviance")
plot(gam_tempres ~AllMeans$year[which(!is.na(AllMeans$MDperKMsqFall_mean))]) #
acf(gam_tempres, na.action = na.pass,main = "gam_temp: D ~ s(year) + s(AvrgWinMinTemp)")#including autocorrelation
MD <- AllMeans$MDperKMsqFall_mean
year <- time(AllMeans$year)
temp <- AllMeans$AvrgWinterMinTemp
gam_temp2 <- gam(MD ~ s(year, bs="cs") +s(temp, bs="cs"))
gam_tempres2 <- residuals(gam_temp2, type = "deviance")
acf(gam_tempres2, na.action = na.pass,main = "Auto-correlation plot for residuals gam_temp fall")
###Effect of hunting Density on each macrounit
gam_hunt <- gam(MDperKMsqFall_mean ~ s(HuntDen_All_mean_tminus1, bs="cs"), data=AllMeans)
gam_hunt <- gam(MDperKMsqFall_mean ~ s(HuntDen_All_mean_tminus1, by=macrounit, bs="cs") + macrounit, data=AllMeans)
gam_hunt <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + s(HuntDen_All_mean_tminus1, bs="cs"), data=AllMeans)
gam_hunt <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + s(HuntDen_All_mean_tminus1, by=macrounit, bs="cs") + macrounit, data=AllMeans)
gam_hunt <- gam(MDperKMsqFall_mean ~ s(year, by=macrounit, bs="cs") + s(HuntDen_All_mean_tminus1, bs="cs") + macrounit, data=AllMeans)
gam_huntpred <- data.frame(year=AllMeans$year, macrounit=AllMeans$macrounit, HuntDen_All_mean_tminus1=AllMeans$HuntDen_All_mean_tminus1)
gam_huntpred <- cbind(gam_huntpred, predict(gam_hunt, se.fit=T, newdata=data.frame("year"=AllMeans$year, "macrounit"=AllMeans$macrounit, "HuntDen_All_mean_tminus1"=AllMeans$HuntDen_All_mean_tminus1), type="response"))
macrounitplots(glmobject = gam_huntpred,xcol="year",title="gam_hunt fall - effect of Hunting Density",colour="red")
macrounitplots(glmobject = gam_huntpred,title="gam_hunt fall - effect of Hunting Density",colour="red")
summary(gam_hunt)
AIC(gam_hunt)
gam_huntres <- residuals(gam_hunt, type = "deviance")
plot(gam_huntres ~AllMeans$year[which(!is.na(AllMeans$MDperKMsqFall_mean))]) #
acf(gam_huntres, na.action = na.pass,main = "Auto-correlation plot for residuals gam_hunt fall")
gam.check(gam_hunt)
###Effect of Oil Well Density on each macrounit
gam_oil <- gam(MDperKMsqFall_mean ~ s(WellDen_mean, bs="cs"), data=AllMeans)
gam_oil <- gam(MDperKMsqFall_mean ~ s(WellDen_mean, by=macrounit, bs="cs") + macrounit, data=AllMeans)
gam_oil <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + s(WellDen_mean, bs="cs"), data=AllMeans)
gam_oil <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + s(WellDen_mean, by=macrounit, bs="cs") + macrounit, data=AllMeans)
gam_oil <- gam(MDperKMsqFall_mean ~ s(year, by=macrounit, bs="cs") + s(WellDen_mean, bs="cs") + macrounit, data=AllMeans)
gam_oilpred <- data.frame(year=AllMeans$year, macrounit=AllMeans$macrounit, WellDen_meann=AllMeans$WellDen_mean)
gam_oilpred <- cbind(gam_oilpred, predict(gam_oil, se.fit=T, newdata=data.frame("year"=AllMeans$year, "macrounit"=AllMeans$macrounit, "WellDen_mean"=AllMeans$WellDen_mean), type="response"))
macrounitplots(glmobject = gam_oilpred,xcol="WellDen_mean",title="gam_oil fall - effect of Oil Well Density",colour="red")
macrounitplots(glmobject = gam_oilpred,title="gam_oil fall - effect of Oil Well Density",colour="red")
summary(gam_oil)
AIC(gam_oil)
gam_oilres <- residuals(gam_oil, type = "deviance")
plot(gam_oilres ~AllMeans$year[which(!is.na(AllMeans$MDperKMsqFall_mean))]) #
acf(gam_oilres, na.action = na.pass,main = "Auto-correlation plot for residuals Oil Well Density")
gam.check(gam_oil)
###Effect of Coyote Density on each macrounit
gam_coyote <- gam(MDperKMsqFall_mean ~ s(CoyoteDen_mean, bs="cs"), data=AllMeans)
gam_coyote <- gam(MDperKMsqFall_mean ~ s(CoyoteDen_mean, by=macrounit, bs="cs") + macrounit, data=AllMeans)
gam_coyote <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + s(CoyoteDen_mean, bs="cs"), data=AllMeans)
gam_coyote <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + s(CoyoteDen_mean, by=macrounit, bs="cs") + macrounit, data=AllMeans)
gam_coyote <- gam(MDperKMsqFall_mean ~ s(year, by=macrounit, bs="cs") + s(CoyoteDen_mean, bs="cs") + macrounit, data=AllMeans)
gam_coyotepred <- data.frame(year=AllMeans$year, macrounit=AllMeans$macrounit, CoyoteDen_meann=AllMeans$CoyoteDen_mean)
gam_coyotepred <- cbind(gam_coyotepred, predict(gam_coyote, se.fit=T, newdata=data.frame("year"=AllMeans$year, "macrounit"=AllMeans$macrounit, "CoyoteDen_mean"=AllMeans$CoyoteDen_mean), type="response"))
macrounitplots(glmobject = gam_coyotepred,xcol="CoyoteDen_mean",title="gam_coyote fall - effect of Coyote Density",colour="red")
macrounitplots(glmobject = gam_coyotepred,title="gam_coyote fall - effect of Coyote Density",colour="red")
summary(gam_coyote)
AIC(gam_coyote)
gam_coyoteres <- residuals(gam_coyote, type = "deviance")
plot(gam_coyoteres ~AllMeans$year[which(!is.na(AllMeans$MDperKMsqFall_mean))]) #
acf(gam_coyoteres, na.action = na.pass,main = "Auto-correlation plot for residuals Coyote Density")
gam.check(gam_coyote)
###Effect of Woody Vegetation on each macrounit
#collinearity issues with year in some of the MUs,so:
gam_woodyveg <- gam(MDperKMsqFall_mean ~ s(WoodyVeg_mean, bs="cs"), data=AllMeans)
gam_woodyveg <- gam(MDperKMsqFall_mean ~ s(WoodyVeg_mean, by=macrounit, bs="cs") + macrounit, data=AllMeans)
gam_woodyveg <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + s(WoodyVeg_mean, bs="cs"), data=AllMeans)
gam_woodyveg <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + s(WoodyVeg_mean, by=macrounit, bs="cs") + macrounit, data=AllMeans)
gam_woodyveg <- gam(MDperKMsqFall_mean ~ s(year, by=macrounit, bs="cs") + s(WoodyVeg_mean, bs="cs") + macrounit, data=AllMeans)
pred_single <- predict(gam_woodyveg, se.fit=T, newdata=data.frame("year"=AllMeans$year, "macrounit"=AllMeans$macrounit, "WoodyVeg_mean"=AllMeans$WoodyVeg_mean), type="response")
gam_woodyvegpred <- data.frame(year=AllMeans$year, macrounit=AllMeans$macrounit, WoodyVeg_meann=AllMeans$WoodyVeg_mean)
gam_woodyvegpred <- cbind(gam_woodyvegpred, predict(gam_woodyveg, se.fit=T, newdata=data.frame("year"=AllMeans$year, "macrounit"=AllMeans$macrounit, "WoodyVeg_mean"=AllMeans$WoodyVeg_mean), type="response"))
macrounitplots(glmobject = gam_woodyvegpred,xcol="year",title="gam_woodyveg fall - effect of Woody Vegetation",colour="red")
macrounitplots(glmobject = gam_woodyvegpred,title="gam_woodyveg fall - effect of Woody Vegetation",colour="red")
summary(gam_woodyveg)
AIC(gam_woodyveg)
plot(gam_woodyveg)
gam_woodyvegres <- residuals(gam_woodyveg, type = "deviance")
plot(gam_woodyvegres ~AllMeans$year[which(!is.na(AllMeans$MDperKMsqFall_mean))]) #
acf(gam_woodyvegres, na.action = na.pass,main = "PopDen ~ s(year) + s(WoodyVeg)")
gam.check(gam_woodyveg)
###Effect of Fawn:Female Ratio
gam_ffratio <- gam(MDperKMsqFall_mean ~ s(FawnFemaleRatio_mean, bs="cs"), data=AllMeans)
gam_ffratio <- gam(MDperKMsqFall_mean ~ s(FawnFemaleRatio_mean, by=macrounit, bs="cs") + macrounit, data=AllMeans)
gam_ffratio <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + s(FawnFemaleRatio_mean, bs="cs"), data=AllMeans)
gam_ffratio <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + s(FawnFemaleRatio_mean, by=macrounit, bs="cs") + macrounit, data=AllMeans)
gam_ffratio <- gam(MDperKMsqFall_mean ~ s(year, by=macrounit, bs="cs") + s(FawnFemaleRatio_mean, bs="cs") + macrounit, data=AllMeans)
gam_ffratiores <- residuals(gam_ffratio, type = "deviance")
summary(gam_ffratio)
AIC(gam_ffratio)
##### All explanatory variables, Whole Area Means (equivalent to gam_all3)
gam_combine <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + s(AvrgWinterMinTemp, bs="cs") + s(HuntDen_All_mean_tminus1, bs="cs") + s(WellDen_mean, bs="cs") + s(CoyoteDen_mean, bs="cs") + s(WoodyVeg_mean, bs="cs"), data=AllMeans)
gam_combine <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + s(WellDen_mean, bs="cs") + s(CoyoteDen_mean, bs="cs") + s(WoodyVeg_mean, bs="cs"), data=AllMeans)
summary(gam_combine)
AIC(gam_combine)
gam_combineres <- residuals(gam_combine, type = "deviance")
#plot(gam_combineres ~AllMeans$year[which(!is.na(AllMeans$MDperKMsqFall_mean))]) #
acf(gam_combineres, na.action = na.pass,main = "Auto-correlation plot for residuals Coyote Density")
gam.check(gam_combine)
### MULTIVARIATE MODELS without s(year), one of WoodyVeg,WellDen and FFratio at a time as these are collinear----
gam_combinewoody <- gam(MDperKMsqFall_mean ~ s(AvrgWinterMinTemp, bs="cs") + s(HuntDen_All_mean_tminus1, bs="cs") + s(CoyoteDen_mean, bs="cs") + s(WoodyVeg_mean, bs="cs"), data=AllMeans)
gam_combinewoodyres <- residuals(gam_combinewoody, type = "deviance")
acf(gam_combinewoodyres, na.action = na.pass,main = "8: WoodyVeg",cex.label=3)
# on each of the macrounits seperately
png("combinewoody_acf.png", width=2200, height=1500)
par(mfrow=c(2,2),oma=c(10,10,10,10),mar=c(10, 10, 10, 10))
gam_combinewoodypred <- data.frame(year=AllMeans$year, macrounit=AllMeans$macrounit, WoodyVeg_mean=AllMeans$WoodyVeg_mean, fit=numeric(204), se.fit=numeric(204))
macrounits <- levels(AllMeans$macrounit)
parinfo <- data.frame("0-1" = numeric(5), "0-2" = numeric(5), "0-3" = numeric(5), "0-4" = numeric(5), row.names=c("p.AvrgWinterMinTemp", "p.HuntDen_All_mean_tminus1", "p.CoyoteDen_mean", "p.WoodyVeg_mean", "AIC"))
for (i in 1:length(macrounits)){
cond = which(AllMeans$macrounit==macrounits[i])
gam_combinewoody <- gam(MDperKMsqFall_mean ~ s(AvrgWinterMinTemp, bs="cs") + s(HuntDen_All_mean_tminus1, bs="cs") + s(CoyoteDen_mean, bs="cs") + s(WoodyVeg_mean, bs="cs"), data=AllMeans[cond,])
parinfo[,i] <- c((summary(gam_combinewoody)$s.table[,"p-value"]),AIC(gam_combinewoody))
gam_combinewoodypred[cond,4:5] <- predict(gam_combinewoody, se.fit=T, newdata=data.frame("year"=AllMeans$year[cond], "macrounit"=AllMeans$macrounit[cond], "WoodyVeg_mean"=AllMeans$WoodyVeg_mean[cond],"AvrgWinterMinTemp"=AllMeans$AvrgWinterMinTemp[cond],"HuntDen_All_mean_tminus1"=AllMeans$HuntDen_All_mean_tminus1[cond], "CoyoteDen_mean"=AllMeans$CoyoteDen_mean[cond]), type="response")
gam_combinewoodyres <- residuals(gam_combinewoody, type = "deviance")
acf(gam_combinewoodyres, na.action = na.pass,main = macrounits[i])
}
title("Autocorrelation model 8:combinewoody", outer=TRUE, cex=3)
dev.off()
macrounitplots(glmobject = gam_combinewoodypred,xcol="year",title="Combine woodyveg fall",colour="red")
which(parinfo < 0.001,arr.ind = TRUE)
parinfo <- format(parinfo, scientific=FALSE)#after which beacuse otherwise which doesnt work anymore
parinfo
sum(as.numeric(parinfo[5,]))#sum of AIC: 253.1412
summary(gam_combinewoody)
AIC(gam_combinewoody)
gam_combinewell <- gam(MDperKMsqFall_mean ~ s(AvrgWinterMinTemp, bs="cs") + s(HuntDen_All_mean_tminus1, bs="cs") + s(CoyoteDen_mean, bs="cs") + s(WellDen_mean, bs="cs"), data=AllMeans)
gam_combinewellres <- residuals(gam_combinewell, type = "deviance")
acf(gam_combinewellres, na.action = na.pass,main = "8: WellDen")
# on each of the macrounits seperately
png("combinewell_acf.png", width=2200, height=1500)
par(mfrow=c(2,2),oma=c(10,10,10,10),mar=c(10, 10, 10, 10))
macrounits <- levels(AllMeans$macrounit)
parinfo <- data.frame("0-1" = numeric(5), "0-2" = numeric(5), "0-3" = numeric(5), "0-4" = numeric(5), row.names=c("p.AvrgWinterMinTemp", "p.HuntDen_All_mean_tminus1", "p.CoyoteDen_mean", "p.WellDen_mean", "AIC"))
for (i in 1:length(macrounits)){
cond = which(AllMeans$macrounit==macrounits[i])
gam_combinewell <- gam(MDperKMsqFall_mean ~ s(AvrgWinterMinTemp, bs="cs") + s(HuntDen_All_mean_tminus1, bs="cs") + s(CoyoteDen_mean, bs="cs") + s(WellDen_mean, bs="cs"), data=AllMeans[cond,])
parinfo[,i] <- c((summary(gam_combinewell)$s.table[,"p-value"]),AIC(gam_combinewell))
gam_combinewellres <- residuals(gam_combinewell, type = "deviance")
acf(gam_combinewellres, na.action = na.pass,main = macrounits[i],cex.main=4)
}
title("Autocorrelation model 8: WellDen", outer=TRUE, cex=5)
dev.off()
which(parinfo < 0.001,arr.ind = TRUE)
parinfo <- format(parinfo, scientific=FALSE)#after which beacuse otherwise which doesnt work anymore
parinfo
sum(as.numeric(parinfo[5,])) #sum of AIC318.051
summary(gam_combinewell)
AIC(gam_combinewell)
gam_combineffratio <- gam(MDperKMsqFall_mean ~ s(AvrgWinterMinTemp, bs="cs") + s(HuntDen_All_mean_tminus1, bs="cs") + s(CoyoteDen_mean, bs="cs") + s(FawnFemaleRatio_mean, bs="cs"), data=AllMeans)
gam_combineffratiores <- residuals(gam_combineffratio, type = "deviance")
acf(gam_combineffratiores, na.action = na.pass,main = "8: FFRatio")
# on each of the macrounits seperately
macrounits <- levels(AllMeans$macrounit)
parinfo <- data.frame("0-1" = numeric(5), "0-2" = numeric(5), "0-3" = numeric(5), "0-4" = numeric(5), row.names=c("p.AvrgWinterMinTemp", "p.HuntDen_All_mean_tminus1", "p.CoyoteDen_mean", "p.FawnFemaleRatio_mean", "AIC"))
for (i in 1:length(macrounits)){
cond = which(AllMeans$macrounit==macrounits[i])
gam_combineffratio <- gam(MDperKMsqFall_mean ~ s(AvrgWinterMinTemp, bs="cs") + s(HuntDen_All_mean_tminus1, bs="cs") + s(CoyoteDen_mean, bs="cs") + s(FawnFemaleRatio_mean, bs="cs"), data=AllMeans[cond,])
parinfo[,i] <- c((summary(gam_combineffratio)$s.table[,"p-value"]),AIC(gam_combineffratio))
}
which(parinfo < 0.001,arr.ind = TRUE)
parinfo <- format(parinfo, scientific=FALSE)#after which beacuse otherwise which doesnt work anymore
parinfo
sum(as.numeric(parinfo[5,])) #sum of AIC 360.9366
summary(gam_combineffratio)
AIC(gam_combineffratio)
#### combined gam based on Whole Area Means (equivalent go gam3)
gam_combine3 <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + s(AvrgWinterMinTemp, bs="cs") + s(HuntDen_All_mean_tminus1, bs="cs") + s(WellDen_mean, bs="cs") + s(WoodyVeg_mean, bs="cs"), data=WholeAreaMeans)
#gam_combinepred <- data.frame(year=AllMeans$year, macrounit=AllMeans$macrounit, CoyoteDen_meann=AllMeans$CoyoteDen_mean)
#gam_combinepred <- cbind(gam_combinepred, predict(gam_combine, se.fit=T, newdata=data.frame("year"=AllMeans$year, "macrounit"=AllMeans$macrounit, "CoyoteDen_mean"=AllMeans$CoyoteDen_mean), type="response"))
#macrounitplots(glmobject = gam_combinepred,xcol="CoyoteDen_mean",title="gam_combine fall - effect of Coyote Density",colour="red")
#macrounitplots(glmobject = gam_combinepred,title="gam_combine fall - effect of Coyote Density",colour="red")
summary(gam_combine3)
AIC(gam_combine3)
gam_combine3res <- residuals(gam_combine3, type = "deviance")
#plot(gam_combine3res ~AllMeans$year[which(!is.na(AllMeans$MDperKMsqFall_mean))]) #
acf(gam_combine3res, na.action = na.pass,main = "Auto-correlation plot for residuals Coyote Density")
gam.check(gam_combine)
###include Interactions
gam_coyoteoil <- gam(MDperKMsqFall_mean ~ te(CoyoteDen_mean,WellDen_mean,bs="cs"), data=AllMeans)
gam_coyoteoil <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + te(CoyoteDen_mean,WellDen_mean,bs="cs"), data=AllMeans)
gam_coyoteoil <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + te(CoyoteDen_mean,WellDen_mean,bs="cs", by=macrounit) + macrounit, data=AllMeans)
summary(gam_coyoteoil)
AIC(gam_coyoteoil)
plot(gam_coyoteoil)
gam.check(gam_coyoteoil)
gam_coyotetemp <- gam(MDperKMsqFall_mean ~ te(CoyoteDen_mean,AvrgWinterMinTemp,bs="cs"), data=AllMeans)
gam_coyotetemp <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + te(CoyoteDen_mean,AvrgWinterMinTemp,bs="cs"), data=AllMeans)
gam_coyotetemp <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + te(CoyoteDen_mean,AvrgWinterMinTemp,bs="cs", by=macrounit) + macrounit, data=AllMeans)
summary(gam_coyotetemp)
AIC(gam_coyotetemp)
plot(gam_coyotetemp)
gam_coyotehunt <- gam(MDperKMsqFall_mean ~ te(CoyoteDen_mean,HuntDen_All_mean,bs="cs"), data=AllMeans)
gam_coyotehunt <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + te(CoyoteDen_mean,HuntDen_All_mean,bs="cs"), data=AllMeans)
gam_coyotehunt <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + te(CoyoteDen_mean,HuntDen_All_mean,bs="cs", by=macrounit) + macrounit, data=AllMeans)
summary(gam_coyotehunt)
AIC(gam_coyotehunt)
plot(gam_coyotehunt)
gam_huntoil <- gam(MDperKMsqFall_mean ~ te(HuntDen_All_mean,WellDen_mean,bs="cs"), data=AllMeans)
gam_huntoil <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + te(HuntDen_All_mean,WellDen_mean,bs="cs"), data=AllMeans)
gam_huntoil <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + te(HuntDen_All_mean,WellDen_mean,bs="cs", by=macrounit) + macrounit, data=AllMeans)
summary(gam_huntoil)
AIC(gam_huntoil)
plot(gam_huntoil)
gam_hunttemp <- gam(MDperKMsqFall_mean ~ te(HuntDen_All_mean,AvrgWinterMinTemp,bs="cs"), data=AllMeans)
gam_hunttemp <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + te(HuntDen_All_mean,AvrgWinterMinTemp,bs="cs"), data=AllMeans)
gam_hunttemp <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + te(HuntDen_All_mean,AvrgWinterMinTemp,bs="cs", by=macrounit) + macrounit, data=AllMeans)
summary(gam_hunttemp)
AIC(gam_hunttemp)
plot(gam_hunttemp)
gam_oiltemp <- gam(MDperKMsqFall_mean ~ te(WellDen_mean,AvrgWinterMinTemp,bs="cs"), data=AllMeans)
gam_oiltemp <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + te(WellDen_mean,AvrgWinterMinTemp,bs="cs"), data=AllMeans)
gam_oiltemp <- gam(MDperKMsqFall_mean ~ s(year, bs="cs") + te(WellDen_mean,AvrgWinterMinTemp,bs="cs", by=macrounit) + macrounit, data=AllMeans)
summary(gam_oiltemp)
AIC(gam_oiltemp)
plot(gam_oiltemp)