-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiegotyusmodels.R
More file actions
256 lines (151 loc) · 8 KB
/
diegotyusmodels.R
File metadata and controls
256 lines (151 loc) · 8 KB
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
# Exploration September 16th 2025
# Today we tested biology (spring migraiton and functional diversity) as well as the digital lxuury effect (number of obs and number of checklists)
# Next steps from Tyus ends:
# Make a water percent species association
# Get NDVI year round
# Diego in late november gets distance2coastline
# --- --- --- --- --- --- --- --- --- --- --- ---
# [1] Testing spring migration
# --- --- --- --- --- --- --- --- --- --- --- ---
# Spring migraiton model ####
# Spring migration is negatively associated
# Next steps: Show savannah and turn into a mixed effect model? What is the random effect?
spring_migration_model = lm(sp_migrate_mean ~imp_surf + medincome_mean+
pcnt_understory+pcnt_forest, # +nitelite_mean,
data = ebird_scaled)
library(corrplot)
predictors <- ebird_scaled[, c("sp_migrate_mean", "imp_surf", "medincome_mean",
"pcnt_understory", "pcnt_forest", "pcnt_urban")]
# Compute the correlation matrix
cor_matrix <- cor(predictors, use = "complete.obs")
# Make a corrplot
corrplot(cor_matrix, method = "color", type = "upper",
tl.col = "black", tl.srt = 45,
addCoef.col = "black", # adds correlation values
diag = FALSE)
tab_model(spring_migration_model)
# Interpretation:
# Spring migraiton abundance is positively significantly associated with areas with higher amounts of understory and forest specialists
# Negatively associated with impervious surface
plot_model(spring_migration_model, 'pred')
# [1] Focus on the spring migration model ####
# Next steps we look a step within the fucntional diversity of these birds
# --- --- --- --- --- --- --- --- --- --- --- ---
# [2] Testing functional diversity
# --- --- --- --- --- --- --- --- --- --- --- ---
# We expect urban birds to not be significantly associated with the luxury effect, but positively respond to impervious surface
urban_bird_model = lm(pcnt_urban ~imp_surf + medincome_mean * ndviwet_mean+elev_mean
, # +nitelite_mean,
data = ebird_scaled)
tab_model(urban_bird_model)
forest_birds_model = lm(pcnt_forest ~imp_surf + medincome_mean * ndviwet_mean+elev_mean, # +nitelite_mean,
data = ebird_scaled)
tab_model(forest_birds_model)
understory_birds_model = lm(pcnt_understory ~imp_surf + medincome_mean * ndviwet_mean+elev_mean, # +nitelite_mean,
data = ebird_scaled)
tab_model(understory_birds_model)
names(ebird_scaled)
# [2] Provide interpretation to the functional traits urban-forest-understory-water ####
# --- --- --- --- --- --- --- --- --- --- --- ---
# testing the digital luxury effect
# --- --- --- --- --- --- --- --- --- --- --- ---
# [3] Provide interpretation on the digital luxury effect being super complicated in a urban biodiversity hotspot thats not exclusively water limited ####
require(sjPlot)
require(lme4)
require(corrplot)
# --- --- --- --- --- --- --- --- --- --- --- ---
# All observations
# --- --- --- --- --- --- --- --- --- --- --- ---
# Lets model patterns of data, little to do with biology
# Testing the luxury effect in presence only data
# testing_luxury_eff = glm(num_bird_obvs ~elev_mean + imp_surf + medincome_mean + pop_density_mean,
# data = ebird_scaled)
testing_luxury_eff = gam(num_bird_obvs ~ s(elev_mean) + s(imp_surf) + s(medincome_mean) + s(ndvidry_mean),
data = ebird_scaled)
testing_luxury_eff = lm(num_bird_obvs ~elev_mean + imp_surf + medincome_mean * ndvidry_mean,
data = ebird_scaled)
tab_model(testing_luxury_eff)
plot_model(testing_luxury_eff, type = "pred")
# testing_luxury_eff = gam(num_bird_obvs ~elev_mean + imp_surf + medincome_mean + pop_density_mean,
# data = ebird_scaled)
ggplot(ebird_eastbay_tests,aes(x=medincome_mean,y=num_records))+geom_smooth()
# Number of checklists
require(mgcv)
# --- --- --- --- --- --- --- --- --- --- --- ---
# Complete checklists
# --- --- --- --- --- --- --- --- --- --- --- ---
test_luxur_eff_complete_checklists = gam(num_records ~elev_mean + imp_surf + pop_density_mean
+ ndviwet_mean + medincome_mean * nitelite_mean + bio1_temp_mean + bio12_rain_mean,
data = ebird_scaled)
tab_model(test_luxur_eff_complete_checklists)
# --- --- --- --- --- --- --- ---
# This is a solid chunck = End here
# --- --- --- --- --- --- --- ---
# Extra exploration graveyard #####
lm_model_luxury <- lm(num_records ~ ndviwet_mean + nitelite_mean +
housing_density_mean + bio1_temp_mean + nitelite_mean * medincome_mean, data = ebird_scaled)
AIC(test_luxur_eff_complete_checklists, lm_model_luxury)
tab_model(lm_model_luxury)
# Lets model biology
# Number of total species
num_species_model = lm(num_species ~elev_mean + imp_surf * medincome_mean + pop_density_mean,
data = ebird_scaled)
tab_model(num_species_model)
# Number of species / species richness
num_species_model = lm(num_species ~elev_mean + imp_surf + pop_density_mean+
ndviwet_mean * medincome_mean +
nitelite_mean + bio1_temp_mean + bio12_rain_mean,
data = ebird_scaled)
tab_model(num_species_model)
# Migration Full model
num_migration_model = lm(num_migr_sp ~elev_mean + imp_surf + pop_density_mean+
ndviwet_mean * medincome_mean +
nitelite_mean + bio1_temp_mean + bio12_rain_mean,
data = ebird_scaled)
# Migration Full model
num_migration_model = lm(num_migr_sp ~elev_mean + imp_surf +
ndviwet_mean * medincome_mean +
nitelite_mean + bio1_temp_mean + bio12_rain_mean,
data = ebird_scaled)
tab_model(num_migration_model)
# For now lets stick to bird migraiton intensity/biomass per Horton et al.
# Migration is a functional trait
num_migration_model_spring = lm(sp_migrate_mean ~elev_mean + imp_surf+
ndviwet_mean + medincome_mean + pcnt_understory + pcnt_forest +
nitelite_mean,
data = ebird_scaled)
tab_model(num_migration_model_spring)
plot_model(num_migration_model_spring, 'pred')
number_migratory_species = lm(num_migr_sp ~imp_surf+pcnt_understory+pcnt_forest+nitelite_mean
+ medincome_mean,
data = ebird_scaled)
tab_model(number_migratory_species)
plot_model(num_migration_model_spring, 'pred')
# medincome_mean
lm_model2 <- lm(num_migr_sp ~ ndviwet_mean + nitelite_mean +
housing_density_mean + bio1_temp_mean + sp_migrate_mean + nitelite_mean * medincome_mean, data = ebird_scaled)
AIC(num_migration_model,lm_model2 ) # compete against each other suckers
summary(lm_model2)
tab_model(lm_model2)
plot_model(lm_model2, 'pred')
# number of resident species full model
resident_birds <- gam(num_resid_sp ~ s(ndviwet_mean) + s(nitelite_mean) + s(medincome_mean) +
s(housing_density_mean) + s(bio1_temp_mean) + s(sp_migrate_mean), data = ebird_scaled)
summary(resident_birds)
tab_model(resident_birds)
plot_model(resident_birds, 'pred')
# make sure to scale the vars to reduce error #
scaled.vars = as.data.frame(scale(uwin_vars_anno[9:21], scale = TRUE)) # looks good
cor.matrix <- cor(ebird_scaled[,c(7:23)], use = "complete.obs", method = "pearson") # look at the correlation estimate
print(cor.matrix) # this looks much better, now in matrix format
# make the matrix plot
corrplot::corrplot(cor.matrix, method = "square",
type = "full",
addCoef.col = "black",
addCoefasPercent = FALSE,
outline = TRUE,
insig = "pch",
p.mat = NULL,
tl.col = "black",
tl.srt = 45) # this looks fine will improve later
names(ebird_scaled)