-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOLD_3.Linear_regression.R
More file actions
342 lines (269 loc) · 13.5 KB
/
OLD_3.Linear_regression.R
File metadata and controls
342 lines (269 loc) · 13.5 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
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
# Hannah-Marie Lamle
# LSAT habitat suitability modelling
# Simple linear regressions first
# Creation date of this document: 11/6/2025
# This document was created during cleanup of this project repository to better
# aid in data analyzation for the future.
library(tidyverse)
library(ggplot2)
library(readxl)
library(dplyr)
library(patchwork)
library(ggpubr)
library(grid)
# -------------------- Old code: not using ---------------------------------
#ggplot(rawdata25, aes(Turf_length, Sediment_depth))+ # modeling sediment depth (y) as
# geom_point()+ # function of turf length (x)
# geom_smooth(method = "lm", formula = y ~ x)
#model <- lm(Sediment_depth ~ Turf_length, data = Comparison_metrics_South_Canyon)
#summary(model)
#ggplot(Comparison_metrics_South_Canyon, aes(Turf_length, avg_slope))+ # modelling slope (y) as a function
# geom_point()+ # of turf legnth (x)
# geom_smooth(method = "lm", formula = y ~ x)
#model <- lm(avg_slope ~ Turf_length, data = Comparison_metrics_South_Canyon)
#summary(model)
#ggplot(Comparison_metrics_South_Canyon, aes(Turf_length, avg_rugosity))+ # modelling rugosity (y) as function
# geom_point()+ # of turf length (x)
# geom_smooth(method = "lm", formula = y ~ x)
#model <- lm(avg_rugosity ~ Turf_length, data = Comparison_metrics_South_Canyon)
#summary(model)
#ggplot(Comparison_metrics_South_Canyon, aes(avg_slope, avg_rugosity))+ # modelling rugosity (y) as function
# geom_point()+ # of turf length (x)
# geom_smooth(method = "lm", formula = y ~ x)
#model <- lm(avg_rugosity ~ avg_slope, data = Comparison_metrics_South_Canyon)
#summary(model)
# From Rolo: we are trying to see if microstructure taken from Viscore/GIS can
# reliably predict LSAT metrics (sediment depth, turf length).
# Therefore, need to flip the x and y axes and model LSAT as a function of complexity
# Feedback from Rolo incorporated, here is how microstructure ranges are altering
# turf depth and sediment depth:
# --------------------------- Linear Regressions: 25 ---------------------------
# regular rugosity vs turf length
rugo25_turf <- ggplot(rawdata25, aes(x = avg_rugo25, y = `turf_ length_mm`))+ # Modelling turf length (y) as function of rugosity (x)
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Rugosity")+
ggtitle("25cm Box")
model <- lm(`turf_ length_mm` ~ avg_rugo25, data = rawdata25)
summary(model)
rugo25_turf
# regular rugosity vs sediment depth
rugo25_sediment <- ggplot(rawdata25, aes(x = avg_rugo25, y = sed_depth_mm))+ # modelling sediment depth (y) as function
geom_point()+ # of rugosity (x)
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Rugosity")
model <- lm(sed_depth_mm ~ avg_rugo25, data = rawdata25)
summary(model)
rugo25_sediment
# 0-1 rugosity vs turf length
#ggplot(rawdata25, aes(rugo25_A, y = `Turf length (mm)`))+ # modelling sediment depth (y) as function
# geom_point()+ # of rugosity (x)
# geom_smooth(method = "lm", formula = y ~ x)+
# xlab("Rugosity on 0-1 scale")
#model <- lm(`Turf length (mm)` ~ rugo25_A, data = rawdata25)
#summary(model)
# 0-1 rugosity vs sediment depth
#ggplot(rawdata25, aes(rugo25_A, y = `Sediment depth (mm)`))+ # modelling sediment depth (y) as function
# geom_point()+ # of rugosity (x)
# geom_smooth(method = "lm", formula = y ~ x)+
# xlab("Rugosity on 0-1 scale")
#model <- lm(`Sediment depth (mm)` ~ rugo25_A, data = rawdata25)
#summary(model)
# slope vs turf length
slope25_turf <- ggplot(rawdata25, aes(slope, y = `turf_ length_mm`))+ # modelling turf length (y) as function
geom_point()+ # of slope
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Average Slope (degrees)")+
ggtitle("25cm Box")
model <- lm(`turf_ length_mm` ~ MEAN, data = rawdata25)
summary(model)
slope25_turf
# slope vs sediment depth
slope25_sediment <- ggplot(rawdata25, aes(slope, y = sed_depth_mm))+ # modelling sediment depth (y) as function
geom_point()+ # of slope (x)
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Average Slope (degrees)")
model <- lm(sed_depth_mm ~ MEAN, data = rawdata25)
summary(model)
slope25_sediment
# --------------------------- Linear Regressions: 50 ---------------------------
# regular rugosity vs turf length
rugo50_turf <- ggplot(rawdata50, aes(x = avg_rugo50, y = `turf_ length_mm`))+ # Modelling turf length (y) as function of rugosity (x)
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Rugosity")+
ggtitle("50cm Box")
model <- lm(`turf_ length_mm` ~ avg_rugo50, data = rawdata50)
summary(model)
# regular rugosity vs sediment depth
rugo50_sediment <- ggplot(rawdata50, aes(x = avg_rugo50, y = sed_depth_mm))+ # modelling sediment depth (y) as function
geom_point()+ # of rugosity (x)
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Rugosity")
model <- lm(sed_depth_mm ~ avg_rugo50, data = rawdata50)
summary(model)
# 0-1 rugosity vs turf length
#ggplot(rawdata50, aes(rugo50_A, y = `Turf length (mm)`))+ # modelling sediment depth (y) as function
# geom_point()+ # of rugosity (x)
# geom_smooth(method = "lm", formula = y ~ x)+
# xlab("Rugosity on 0-1 scale")
#model <- lm(`Turf length (mm)` ~ rugo50_A, data = rawdata50)
#summary(model)
# 0-1 rugosity vs sediment depth
#ggplot(rawdata50, aes(rugo50_A, y = `Sediment depth (mm)`))+ # modelling sediment depth (y) as function
# geom_point()+ # of rugosity (x)
# geom_smooth(method = "lm", formula = y ~ x)+
# xlab("Rugosity on 0-1 scale")
#model <- lm(`Sediment depth (mm)` ~ rugo50_A, data = rawdata50)
#summary(model)
# slope vs turf length
slope50_turf <- ggplot(rawdata50, aes(slope, y = `turf_ length_mm`))+ # modelling turf length (y) as function
geom_point()+ # of slope
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Average Slope (degrees)")+
ggtitle("50cm Box")
model <- lm(`turf_ length_mm` ~ MEAN, data = rawdata50)
summary(model)
# slope vs sediment depth
slope50_sediment <- ggplot(rawdata50, aes(slope, y = sed_depth_mm))+ # modelling sediment depth (y) as function
geom_point()+ # of slope (x)
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Average Slope (degrees)")
model <- lm(sed_depth_mm ~ MEAN, data = rawdata50)
summary(model)
# --------------------------- Linear Regressions: 100 ---------------------------
# regular rugosity vs turf length
rugo100_turf <- ggplot(rawdata100, aes(x = avg_rugo100, y = `turf_ length_mm`))+ # Modelling turf length (y) as function of rugosity (x)
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Rugosity")+
ggtitle("100cm Box")
model <- lm(`turf_ length_mm` ~ avg_rugo100, data = rawdata100)
summary(model)
# regular rugosity vs sediment depth
rugo100_sediment <- ggplot(rawdata100, aes(x = avg_rugo100, y = sed_depth_mm))+ # modelling sediment depth (y) as function
geom_point()+ # of rugosity (x)
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Rugosity")
model <- lm(sed_depth_mm ~ avg_rugo100, data = rawdata100)
summary(model)
# 0-1 rugosity vs turf length
#ggplot(rawdata100, aes(rugo100_A, y = `Turf length (mm)`))+ # modelling sediment depth (y) as function
# geom_point()+ # of rugosity (x)
# geom_smooth(method = "lm", formula = y ~ x)+
# xlab("Rugosity on 0-1 scale")
#model <- lm(`Turf length (mm)` ~ rugo100_A, data = rawdata100)
#summary(model)
# 0-1 rugosity vs sediment depth
#ggplot(rawdata100, aes(rugo100_A, y = `Sediment depth (mm)`))+ # modelling sediment depth (y) as function
# geom_point()+ # of rugosity (x)
# geom_smooth(method = "lm", formula = y ~ x)+
# xlab("Rugosity on 0-1 scale")
#model <- lm(`Sediment depth (mm)` ~ rugo100_A, data = rawdata100)
#summary(model)
# slope vs turf length
slope100_turf <- ggplot(rawdata100, aes(slope, y = `turf_ length_mm`))+ # modelling turf length (y) as function
geom_point()+ # of slope
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Average Slope (degrees)")+
ggtitle("100cm Box")
model <- lm(`turf_ length_mm` ~ MEAN, data = rawdata100)
summary(model)
# slope vs sediment depth
slope100_sediment <- ggplot(rawdata100, aes(slope, y = sed_depth_mm))+ # modelling sediment depth (y) as function
geom_point()+ # of slope (x)
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Average Slope (degrees)")
model <- lm(sed_depth_mm ~ MEAN, data = rawdata100)
summary(model)
# ---------------------------- Plotting figs ------------------------
## ------------ Rugosity metrics -----------------
p1 <- ggplot(rawdata25, aes(x = avg_rugo25, y = `Turf length (mm)`))+
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Rugosity")+
ggtitle("25cm microquadrat")+
theme_classic() <- ggplot(rawdata25, aes(x = avg_rugo25, y = `Turf length (mm)`))+
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Rugosity")+
ggtitle("25cm microquadrat")+
theme_classic()
p2 <- ggplot(rawdata25, aes(x = avg_rugo25, y = `Sediment depth (mm)`))+
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Rugosity")+
ggtitle("25cm microquadrat")+
theme_classic()
p3 <- ggplot(rawdata50, aes(x = avg_rugo50, y = `Turf length (mm)`))+ # Modelling turf length (y) as function of rugosity (x)
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Rugosity")+
ggtitle("50cm microquadrat")+
theme_classic()
p4 <- ggplot(rawdata50, aes(x = avg_rugo50, y = `Sediment depth (mm)`))+
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Rugosity")+
ggtitle("50cm microquadrat")+
theme_classic()
p5 <- ggplot(rawdata100, aes(x = avg_rugo100, y = `Turf length (mm)`))+ # Modelling turf length (y) as function of rugosity (x)
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Rugosity")+
ggtitle("100cm quadrat")+
theme_classic()
p6 <- ggplot(rawdata100, aes(x = avg_rugo100, y = `Sediment depth (mm)`))+
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Rugosity")+
ggtitle("100cm Quadrat")+
theme_classic()
(p1 | p2) / (p3 | p4) / (p5 | p6)
# use this instead, it just uses the graphs created above rather than rewriting them:
(rugo25_turf | rugo25_sediment) / (rugo50_turf | rugo50_sediment) / (rugo100_turf | rugo100_sediment) +
plot_annotation(
title = "Rugosity Results",
)
## ------------ Slope Metrics -----------------
p1 <- ggplot(rawdata25, aes(MEAN, y = `Turf length (mm)`))+
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Average Slope (degrees)")+
ggtitle("25cm microquadrat")+
theme_classic()
p2 <- ggplot(rawdata25, aes(MEAN, y = `Sediment depth (mm)`))+
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Average Slope (degrees)")+
ggtitle("25cm Quadrat")+
theme_classic()
p3 <- ggplot(rawdata50, aes(MEAN, y = `Turf length (mm)`))+
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Average Slope (degrees)")+
ggtitle("50cm microquadrat")+
theme_classic()
p4 <- ggplot(rawdata50, aes(MEAN, y = `Sediment depth (mm)`))+
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Average Slope (degrees)")+
ggtitle("50cm Quadrat")+
theme_classic()
p5 <- ggplot(rawdata100, aes(MEAN, y = `Turf length (mm)`))+
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Average Slope (degrees)")+
ggtitle("100cm Quadrat")+
theme_classic()
p6 <- ggplot(rawdata100, aes(MEAN, y = `Sediment depth (mm)`))+
geom_point()+
geom_smooth(method = "lm", formula = y ~ x)+
xlab("Average Slope (degrees)")+
theme_classic()
(p1 | p2) / (p3 | p4) / (p5 | p6)
# use this instead, it just uses the graphs created above rather than rewriting them:
(slope25_turf | slope25_sediment) / (slope50_turf | slope50_sediment) / (slope100_turf | slope100_sediment) +
plot_annotation(
title = "Slope Results",
)