-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
428 lines (428 loc) · 17.1 KB
/
.Rhistory
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
intall.packages("ggplot2")
install.packages("ggplot2")
install.packages("rtools")
seven <- 7
seven
anything
anything <- 19
anything
anything and seven
anything + seven
mean(anything + seven)
mean(anything:seven)
anything:seven
mean(c(1,2,3,4,5))
13
89
Sys.which("make")
find_rtools()
find_rtools()
load("~/data-carpentry/data-carpentry.Rproj")
156/20
156/7
##############################################################################################
# LOADING LIBRARIES #
##############################################################################################
library(tidyverse)
##############################################################################################
# LOADING LIBRARIES #
##############################################################################################
library(tidyverse)
library(rcarbon)
##############################################################################################
# LOADING LIBRARIES #
##############################################################################################
library(tidyverse)
install.packages("broom", type="binary")
##############################################################################################
# LOADING LIBRARIES #
##############################################################################################
library(tidyverse)
##############################################################################################
# LOADING LIBRARIES #
##############################################################################################
library(tidyverse)
##############################################################################################
# LOADING LIBRARIES #
##############################################################################################
library(tidyverse)
##############################################################################################
# LOADING LIBRARIES #
##############################################################################################
library(tidyverse)
##############################################################################################
# LOADING LIBRARIES #
##############################################################################################
library(tidyverse)
library(rcarbon)
library(rnaturalearth)
library(rnaturalearthhires)
library(sf)
library(sp)
##############################################################################################
# PREPARING THE DATA #
##############################################################################################
#-----------------------------------------Creation and management of data frame for all radiocarbon dates
c14dates <- read.csv("data_raw/c14dates.csv") #reading the CSV file with radiocarbon dates
getwd()
dir("carib-model")
setwd("carib-model")
library(ggplot2)
library(rcarbon)
library(rnaturalearth)
library(rnaturalearthhires)
library(sf)
library(sp)
##############################################################################################
# PREPARING THE DATA #
##############################################################################################
#-----------------------------------------Creation and management of data frame for all radiocarbon dates
c14dates <- read.csv("data_raw/c14dates.csv") #reading the CSV file with radiocarbon dates
c14dates$site <- factor(c14dates$site) #converting the column 'dates' in a factor
c14dates$country_state <- factor(c14dates$country_state) #converting the column 'country_state' in a factor
c14dates$region <- factor(c14dates$region) #converting the column 'region' in a factor
c14dates$culture <- factor(c14dates$culture) #converting the column 'culture' in a factor
##############################################################################################
# CALIBRATING RADIOCARBON DATES #
##############################################################################################
#--------------------------Calibrating the radiocarbon dates with normalised parameter
c14calib_normal <- calibrate(
x = c14dates$age, #The radiocarbon age for each of the 135 radiocarbon dates
errors = c14dates$std, #Standard deviation of each radiocarbon date
method = "mixed", #Method for mixing the radiocarbon atmospheric curves
mixed.curves = TRUE, #Enabling the parameter for mixing the atmospheric curves
intcal20 = intcal20(), #Calling the IntCal20 atmospheric curve for Northern Hemisphere
shcal20 = shcal20(), #Calling the ShCal20 atmospheric curve for Southern Hemisphere
normalised = TRUE #Parameter for normalizing the data
)
#----------------------------Calibrating the radiocarbon dates with unnormalised parameter
c14calib_unormal <- calibrate(
x = c14dates$age, #The radiocarbon age for each of the 135 radiocarbon dates
errors = c14dates$std, #Standard deviation of each radiocarbon date
method = "mixed", #Method for mixing the radiocarbon atmospheric curves
mixed.curves = TRUE, #Enabling the argument for mixing the atmospheric curves
intcal20 = intcal20(), #Calling the IntCal20 atmospheric curve for Northern Hemisphere
shcal20 = shcal20(), #Calling the ShCal20 atmospheric curve for Southern Hemisphere
normalised = FALSE
)
#---------Creating a Time Range object for running the analyses
timeRange <- c(
2300, #Starting point on 2300 BP (BC 300)
300 #Ending point on 300 BP (AD 1700)
)
###############################################################################################
# # FIRST MODEL # #
# Summed Probability Distribution (SPD) and a Growth Model for all radiocarbon dates #
###############################################################################################
###############################################################################################
#--------------------------- Step 1 - Creating the SPD Model -------------------------------#
###############################################################################################
c14calib_spd <- spd( #Generation of an object for the SPD
c14calib_unormal, #Using the unnormalised radiocarbon calibrations
timeRange = timeRange #Time Range between 2200 BP to 100 BP
)
###############################################################################################
#--------------------------- Step 2 - Binning the SPD Model -----------------------------#
###############################################################################################
c14dates_bins <- binPrep( #Generation of an object for the bins
sites = c14dates$site, #Column for archaeological sites
ages = c14dates$age, #Column with the radiocarbon age values
h = 100 #Parameter for binning between an interval of 100 years
)
c14dates_binned_spd <- spd( #Generation of the final binned SPD model
c14calib_unormal, #Object with all the unnormalised radiocarbon dates
bins = c14dates_bins, #Object with the bins values for binning the model
timeRange = timeRange, #Time Range of the analysis frmo 2200 to 100 BP
)
###############################################################################################
#-------------- Step 3 - Generating a Kernel Density Estimation Model (KDE) ----------------#
###############################################################################################
C14randates <- sampleDates(
c14calib_unormal,
bins = c14dates_bins,
nsim = 100,
verbose = FALSE
)
c14dates_ckde <- ckde(
C14randates,
timeRange = timeRange,
bw = 100
)
###############################################################################################
#--------------------- Step 4 - Generating an Exponential Growth Model ----------------------- #
###############################################################################################
c14dates_expnull <- modelTest(
c14calib_unormal,
errors = c14dates$std,
bins = c14dates_bins,
nsim = 100,
timeRange = c(2500,0),
model = "exponential",
runm = 100
)
###############################################################################################
#------------------- Step 5 - Permutation Test of the SPD by Pottery ---------------------#
###############################################################################################
permc14dates_culture <- permTest(
x = c14calib_unormal,
marks = c14dates$culture,
timeRange = c(2300,100),
bins = c14dates_bins,
nsim = 100,
runm = 50
)
permc14_culture_stack_spd <- stackspd(
x = c14calib_unormal,
group = c14dates$culture,
timeRange = c(2300,0),
bins = c14dates_bins,
runm = 50,
verbose = FALSE
)
###############################################################################################
#------------------- Step 6 - Permutation Test of the SPD by region ----------------------#
###############################################################################################
permc14dates_region <- permTest(
x = c14calib_unormal,
marks = c14dates$region,
timeRange = c(2300,100),
bins = c14dates_bins,
nsim = 100,
runm = 50
)
permc14_region_stack_spd <- stackspd(
x = c14calib_unormal,
group = c14dates$region,
timeRange = c(2300,0),
bins = c14dates_bins,
runm = 50,
verbose = FALSE
)
######################################################################################################
#------------------------------- Step 7 - Spatial Permutation Test ----------------------------#
######################################################################################################
allsites <- unique(data.frame(id = c14dates$site, lat = c14dates$lat, long = c14dates$long))
allsites <- st_as_sf(allsites, coords = c('long','lat'), crs = 4326)
breaks <- seq(1100,500,-100)
timerange_spatialperm <- c(1100,500)
carib_spd <- spd(
x = c14calib_unormal,
bins = c14dates_bins,
timeRange = timerange_spatialperm
)
spatial_perm <- sptest(
calDates = c14calib_unormal,
bins = c14dates_bins,
timeRange = timerange_spatialperm,
locations = allsites,
locations.id.col = 'id',
h = 100,
kernel = 'gaussian',
permute = 'locations',
nsim = 100,
breaks = breaks,
ncores = 1,
verbose = FALSE
)
world <- ne_countries(scale = 'medium', type = 'map_units', returnclass = 'sf')
xrange <- st_bbox(allsites)[c(1,3)]
yrange <- st_bbox(allsites)[c(2,4)]
######################################################################################################
# # SECOND MODEL # #
# Generating a Summed Probability Distribution (SPD) only for Santarém pottery subset #
######################################################################################################
c14santarem <- subset(c14dates, culture == "Santarem") #Extracting a subset of Santarém Radiocaron dates
c14calib_santarem <- calibrate(
x = c14santarem$age, #The radiocarbon age for each of the 135 radiocarbon dates
errors = c14santarem$std, #Standard deviation of each radiocarbon date
method = "mixed", #Method for mixing the radiocarbon atmospheric curves
mixed.curves = TRUE, #Enabling the parameter for mixing the atmospheric curves
intcal20 = intcal20(), #Calling the IntCal20 atmospheric curve for Northern Hemisphere
shcal20 = shcal20(), #Calling the ShCal20 atmospheric curve for Southern Hemisphere
normalised = FALSE
)
#Plot 01 - Summed Probability Distribution (SPD) for all radiocarbon datings
plot(
c14calib_spd, #SPD object for all Radiocarbon dates
calendar = 'BCAD', #Plot the SPD Model in BC/AD years
main = "Summed Probability Distribution of Koriabo, Santarém and Konduri" #Label
)
plot( #Plotting the smoothing line with a bin value of 200 years
c14calib_spd, #SPD object for all radiocarbon dates
calendar = 'BCAD', #Calendar in BC/AD years
runm = 200, #Smoothed distribution with a binning of 200 years
add = TRUE, #Add the line
type = "simple", #Simple line
col = "red", #Line colour = Red
lwd = 2, #Line Thickness = 2
lty = 2
)
#Plot 02 - Binned Summed Probability Distribution (SPD) for all radiocarbon datings
plot(
c14dates_binned_spd, #SPD object for all Radiocarbon dates
calendar = 'BCAD', #Plot the SPD Model in BC/AD years
main = "Summed Probability Distribution of Koriabo, Santarém and Konduri" # Plot Title
)
plot( #Plotting the smoothing line with a bin value of 200 years
c14dates_binned_spd, #SPD object for all radiocarbon dates
calendar = 'BCAD', #Calendar in BC/AD years
runm = 200, #Smoothed distribution with a binning of 200 years
add = TRUE, #Add the line
type = "simple", #Simple line
col = "red", #Line colour = Red
lwd = 2, #Line Thickness = 2
lty = 2
)
#Plot XX - Kernel Density Estimation (KDE) for all dates
plot(
c14dates_ckde,
type = 'multiline',
main = "Kernel Density Estimation (KDE) for Koriabo, Konduri and Santarém"
)
#Plot XX - Exponential Growth Model for all dates
plot(c14dates_expnull,
calendar = 'BCAD',
main = "Exponential Growth Model (Koriabo, Konduri, Santarém)"
)
#Plot XX - Permutation Test for Koriabo, Santarém and Konduri cultures
par(mfrow = c(1,1))
plot(permc14dates_culture, focalm = 1, calendar = 'BCAD', main = "Koriabo")
plot(permc14dates_culture, focalm = 2, calendar = 'BCAD', main = "Santarém")
plot(permc14dates_culture, focalm = 3, calendar = 'BCAD', main = "Konduri")
par(mfrow=c(2,2))
plot(permc14_culture_stack_spd, type = 'stacked', calendar = 'BCAD')
plot(permc14_culture_stack_spd, type = 'lines', calendar = 'BCAD')
plot(permc14_culture_stack_spd, type = 'multipanel', calendar = 'BCAD')
plot(permc14_culture_stack_spd, type = 'proportion', calendar = 'BCAD')
#Plot XX - Permutation Test for 5 different Regions
par(mfrow = c(2,3))
plot(permc14dates_region, focalm = 1, calendar = 'BCAD', main = "Western Guiana")
plot(permc14dates_region, focalm = 2, calendar = 'BCAD', main = "Guiana Coast")
plot(permc14dates_region, focalm = 3, calendar = 'BCAD', main = "Amapa-Estuary")
plot(permc14dates_region, focalm = 4, calendar = 'BCAD', main = "Lower Amazon")
plot(permc14dates_region, focalm = 5, calendar = 'BCAD', main = "Xingu-Iriri Rivers")
par(mfrow=c(2,2))
plot(permc14_region_stack_spd, type = 'stacked', calendar = 'BCAD')
plot(permc14_region_stack_spd, type = 'lines', calendar = 'BCAD')
plot(permc14_region_stack_spd, type = 'multipanel', calendar = 'BCAD')
plot(permc14_region_stack_spd, type = 'proportion', calendar = 'BCAD')
#Plot XX - Block of Growth Rates
plot(spd2rc(carib_spd, breaks = breaks))
#Plot XX - Spatial Permutation Test
par(mar=c(2,2,2,2), mfrow=c(2,1))
#Plot1
plot(world$geometry,
col = "antiquewhite3",
border = "gray20",
xlim = xrange,
ylim = yrange,
main = "Growth Rate "
)
plot(spatial_perm,
index = 2,
option = "raw",
add = TRUE,
breakRange = c(-0.005,0.005),
breakLength = 7,
rd = 5,
legend = TRUE,
legSize = 0.7,
baseSize = 1.7,
location = "topright")
#Plot2
plot(world$geometry,
col = "antiquewhite3",
border = "gray20",
xlim = xrange,
ylim = yrange,
main = "Growth Rate "
)
plot(spatial_perm,
index = 3,
option = "raw",
add = TRUE,
breakRange = c(-0.005,0.005),
breakLength = 7,
rd = 5,
legend = TRUE,
legSize = 0.7,
baseSize = 1.7,
location = "topright")
#Plot3
plot(world$geometry,
col = "antiquewhite3",
border = "gray20",
xlim = xrange,
ylim = yrange,
main = "Growth Rate "
)
plot(spatial_perm,
index = 3,
option = "raw",
add = TRUE,
breakRange = c(-0.005,0.005),
breakLength = 7,
rd = 5,
legend = TRUE,
legSize = 0.7,
baseSize = 1.7,
location = "topright")
#Plot4
plot(world$geometry,
col = "antiquewhite3",
border = "gray20",
xlim = xrange,
ylim = yrange,
main = "Growth Rate "
)
plot(spatial_perm,
index = 4,
option = "raw",
add = TRUE,
breakRange = c(-0.005,0.005),
breakLength = 7,
rd = 5,
legend = TRUE,
legSize = 0.7,
baseSize = 1.7,
location = "topright")
#Plot5
plot(world$geometry,
col = "antiquewhite3",
border = "gray20",
xlim = xrange,
ylim = yrange,
main = "Growth Rate "
)
plot(spatial_perm,
index = 5,
option = "raw",
add = TRUE,
breakRange = c(-0.005,0.005),
breakLength = 7,
rd = 5,
legend = TRUE,
legSize = 0.7,
baseSize = 1.7,
location = "topright")
#Plot6
plot(world$geometry,
col = "antiquewhite3",
border = "gray20",
xlim = xrange,
ylim = yrange,
main = "Growth Rate "
)
plot(spatial_perm,
index = 6,
option = "raw",
add = TRUE,
breakRange = c(-0.005,0.005),
breakLength = 7,
rd = 5,
legend = TRUE,
legSize = 0.7,
baseSize = 1.7,
location = "topright")
install.packages("tidyverse")
library(tidyverse)