-
Notifications
You must be signed in to change notification settings - Fork 0
/
regression.Rmd
186 lines (140 loc) · 5.39 KB
/
regression.Rmd
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
# Regression and Calibration-in-time
In this chapter, we will replicate the analysis of [@Boldt2015], performing age-uncertain calibration-in-time on a chlorophyll reflectance record from northern Alaska, using geoChronR.
The challenge of age-uncertain calibration-in-time is that age uncertainty affects both the calibration model (the relation between the proxy data and instrumental data) and the reconstruction (the timing of events in the reconstruction). geoChronR simplifies handling these issues.
Let's start by loading the packages we'll need.
```{r, results = FALSE, warning = FALSE, message= FALSE }
library(lipdR) #to read and write LiPD files
library(geoChronR) #of course
library(readr) #to load in the instrumental data we need
library(ggplot2) #for plotting
```
## Load the LiPD file
OK, we'll begin by loading in the Kurupa Lake record from [@Boldt2015].
```{r}
K <- lipdR::readLipd("http://lipdverse.org/geoChronR-examples/Kurupa.Boldt.2015.lpd")
```
### Check out the contents
```{r}
sp <- plotSummary(K,paleo.data.var = "RABD",summary.font.size = 6)
print(sp)
```
## Create an age model
```{r KurupaBacon,results="hide",fig.show='hide',message=FALSE,warning=FALSE,cache=TRUE}
K <- runBacon(K,
lab.id.var = 'labID',
age.14c.var = 'age14C',
age.14c.uncertainty.var = 'age14CUncertainty',
age.var = 'age',
age.uncertainty.var = 'ageUncertainty',
depth.var = 'depth',
reservoir.age.14c.var = NULL,
reservoir.age.14c.uncertainty.var = NULL,
rejected.ages.var = NULL,
bacon.acc.mean = 10,
bacon.thick = 7,
ask = FALSE,
bacon.dir = "~/Cores",
suggest = FALSE,
close.connection = FALSE)
```
:::: {.blackbox data-latex=""}
::: {.exercise #reg-ex-1}
In this chapter, the exercises will have conduct the analysis in a parallel universe, where you make different, but reasonable choices and see what happens.
First, create the best age model you can using either Bchron or Oxcal.
:::
::::
### And plot the ensemble output
```{r}
plotChron(K,age.var = "ageEnsemble",dist.scale = 0.2)
```
:::: {.blackbox data-latex=""}
::: {.exercise #reg-ex-2}
Plot your model. How does it compare to the Bacon model?
:::
::::
## Prepare the data
### Map the age ensemble to the paleodata table
This is to get ensemble age estimates for each depth in the paleoData measurement table
```{r}
K <- mapAgeEnsembleToPaleoData(K,age.var = "ageEnsemble")
```
### Select the paleodata age ensemble, and RABD data that we'd like to regress and calibrate
```{r}
kae <- selectData(K,"ageEnsemble")
rabd <- selectData(K,"RABD")
```
### Now load in the instrumental data
```{r}
kurupa.instrumental <- readr::read_csv("http://lipdverse.org/geoChronR-examples/KurupaInstrumental.csv")
```
### Check age/time units before proceeding
```{r}
kae$units
```
yep, we need to convert the units from BP to AD
```{r}
kae <- convertBP2AD(kae)
```
### Create a "variable list" for the instrumental data
```{r}
kyear <- list()
kyear$values <- kurupa.instrumental[,1]
kyear$variableName <- "year"
kyear$units <- "AD"
kinst <- list()
kinst$values <- kurupa.instrumental[,2]
kinst$variableName <- "Temperature"
kinst$units <- "deg (C)"
```
:::: {.blackbox data-latex=""}
::: {.exercise #reg-ex-3}
Repeat all of this prep work, including mapping the age uncertainties and extracting the variables.
:::
::::
### Calculate an ensemble correlation between the RABD and local summer temperature data
```{r,results="hide",warning=FALSE}
corout <- corEns(kae,rabd,kyear,kinst,bin.step=2,percentiles = c(.05,.5,.95 ))
```
:::: {.blackbox data-latex=""}
::: {.exercise #reg-ex-4}
Calculate the correlation ensemble, but you decide to use 5-year bins instead of 2-year bins.
:::
::::
### And plot the output
Note that here we use the "Effective-N" significance option as we mimic the Boldt et al. (2015) paper.
```{r}
plotCorEns(corout,significance.option = "eff-n")
```
Mixed results. But encouraging enough to move forward.
:::: {.blackbox data-latex=""}
::: {.exercise #reg-ex-5}
After reading Chapter \@ref(corr), you know that the isospectral method is usually more reliable. Use that instead.
:::
::::
## Perform ensemble regression
OK, you've convinced yourself that you want to use RABD to model temperature back through time. We can do this simply (perhaps naively) with regression, and lets do it with age uncertainty, both in the building of the model, and the reconstructing
```{r,results="hide",fig.keep="all"}
regout <- regressEns(time.x = kae,
values.x = rabd,
time.y =kyear,
values.y =kinst,
bin.step=3,
gaussianize = FALSE,
recon.bin.vec = seq(-4010,2010,by=20))
```
:::: {.blackbox data-latex=""}
::: {.exercise #reg-ex-6}
Again, use 5-year time steps, and also gaussianize to avoid the potential impact of skewed data
:::
::::
### And plot the output
```{r}
regPlots <- plotRegressEns(regout,alp = 0.01,font.size = 8)
```
This result is consistent with that produced by Boldt et al., (2015), and was much simpler to produce with geoChronR.
## Chapter project
:::: {.blackbox data-latex=""}
::: {.exercise #reg-ex-7}
Plot your results. How did making different, reasonable (perhaps even better?) choices affect the final outcome of the regression?
:::
::::