-
Notifications
You must be signed in to change notification settings - Fork 0
/
conditional_lambda.qmd
260 lines (233 loc) · 8.58 KB
/
conditional_lambda.qmd
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
# Conditional effect of covariates {#sec-cond-lambda}
In this chapter, we assessed the conditional effects of each covariate on the population growth rate ($\lambda$) for each species.
Specifically, we quantified how $\lambda$ varies with changes in competition intensity for both conspecific and heterospecific individuals.
Furthermore, we examined how $\lambda$ changes in response to variations in mean annual temperature and mean annual precipitation, spanning the range from the minimum to maximum observed values in the dataset.
This analysis is similar to the sensitivity analysis discussed in @sec-sensAnalysis.
However, due to the larger number of conditions for each covariate, we performed this analysis using only 50 replicates from the posterior distribution of the parameters.
For the competition effect analysis, we maintained temperature and precipitation at the optimal conditions defined by the average of the optimal climate conditions among the growth, survival, and recruitment models.
When assessing the effect of conspecific competition, heterospecific competition was set to null.
Conversely, when evaluating the effect of heterospecific competition, the conspecific competition was defined as a small population size of $N = 0.1$.
We evaluated the climate effect under two competition conditions: low competition, where conspecific population size was set to $N = 0.1$, and high conspecific competition, where population size was established at the 99th percentile distribution of plot basal area experienced by the species in the dataset.
When analyzing temperature, precipitation was held at its optimal condition, and vice versa.
```{r,include=FALSE,echo=FALSE}
Echo=FALSE
Eval=TRUE
Cache=FALSE
Warng=FALSE
Msg=FALSE
library(tidyverse)
library(ggdist)
library(ggpubr)
library(ggrepel)
library(ggiraph)
```
```{r loadPars,echo=Echo,eval=Eval,cache=Cache,warning=Warng,message=Msg}
data_path <- readLines('_data.path')
pars_path <- file.path(data_path, 'output_sim_processed')
## Species if info
spIds <- read_csv(
file.path(
data_path, 'species_id.csv'
)
) |>
mutate(
shade = factor(shade, levels = c('tolerant', 'intermediate', 'intolerant')),
shade_sylvics = factor(shade_sylvics, levels = c('very-tolerant',
'tolerant',
'intermediate',
'intolerant',
'very-intolerant'
)),
succession = factor(succession, levels = c('pioneer',
'intermediate',
'climax'))
) |>
filter(sp_to_analyze)
file_url <- 'https://github.com/willvieira/forest-IPM/raw/master/simulations/marginal_lambda/output_processed/lambdas.RDS'
lambdas <- readRDS(gzcon(url(file_url))) |>
filter(species_id %in% spIds$species_id_old)
# load data to unscale climate variables and function to scale climate back to original range
clim_scaleRange <- readRDS(file.path(data_path, 'climate_scaleRange.RDS')) |>
bind_cols()
unscaleClim <- function(
value,
# if value is temp or prec
clim,
# temp and prec range are vectors of format [min, max]
temp_rg = clim_scaleRange$bio_01_mean,
prec_rg = clim_scaleRange$bio_12_mean
) {
if(clim == 'temp') {
return( value * (temp_rg[2] - temp_rg[1]) + temp_rg[1] )
}else if(clim == 'prec') {
return( value * (prec_rg[2] - prec_rg[1]) + prec_rg[1] )
} else{
stop('Clim must be either `temp` or `prec` character.')
}
}
```
## Competition effect
```{r lambdaComp,echo=Echo,eval=Eval,cache=Cache,warning=Warng,message=Msg}
#| label: fig-lambdaComp
#| fig-width: 8
#| fig-height: 4.5
#| fig-cap: "The Average and 90% confidence interval values for the population growth rate ($\\lambda$) as a function of conspecific (left panel) and heterospecific (right panel) competition intensity."
lambdas |>
filter(sim == 'competition') |>
# return comp value back to numeric as climate sim got out
mutate(comp = as.numeric(comp)) |>
mutate(
lambda = log(lambda),
var = case_match(
var,
'cons' ~ 'Conspecific',
'het' ~ 'Heterospecific'
)
) |>
filter(species_id != '18032ABIBAL') |>
left_join(
spIds,
by = c('species_id' = 'species_id_old')
) |>
group_by(species_name, var, comp) |>
reframe(
mean_lambda = mean(lambda),
sd_lambda = sd(lambda),
ci_9 = mean_lambda + qt( c(0.9), n() - 1) * sd_lambda,
ci_1 = mean_lambda + qt( c(0.1), n() - 1) * sd_lambda
) |>
ggplot() +
aes(comp, mean_lambda) +
geom_ribbon_interactive(aes(ymin = ci_1, ymax = ci_9), alpha = 0.3,color=NA) +
geom_line_interactive() +
aes(tooltip = species_name, data_id = species_name) +
facet_wrap(~var) +
geom_hline(yintercept = 0, linetype = 2, alpha = 0.5) +
theme_classic() +
labs(
x = 'Plot basal area (m2/ha)',
y = expression('ln('~lambda~')')
) +
theme(legend.position = 'none') ->
p1
tooltip_css <- "background-color:#fc8d59;padding:5px;border-radius:3px;font-style:italic;"
girafe(
ggobj = p1,
options = list(
opts_tooltip(css = tooltip_css, opacity = 1),
opts_hover_inv(css = "opacity:0.1;"),
opts_hover(css = "stroke-width:2.5px;"),
opts_sizing(width = 1),
opts_toolbar(position = 'top', saveaspng = FALSE),
opts_zoom(max = 5)
)
)
```
## Climate effect
```{r lambdaClimData,echo=Echo,eval=Eval,cache=Cache,warning=Warng,message=Msg}
lambdas |>
filter(species_id %in% spIds$species_id_old) |>
filter(sim == 'climate') |>
mutate(
var = case_match(
var,
'temp' ~ 'Temperature',
'prec' ~ 'Precipitation'
),
comp = case_match(
comp,
'high' ~ 'High competition',
'low' ~ 'Low competition'
),
comp = factor(comp, levels = c('Low competition', 'High competition'))
) |>
filter(species_id != '18032ABIBAL') |>
left_join(
spIds,
by = c('species_id' = 'species_id_old')
) |>
group_by(species_name, var, comp, clim) |>
reframe(
mean_lambda = mean(log(lambda)),
sd_lambda = sd(lambda),
ci_9 = mean_lambda + qt( c(0.9), n() - 1) * sd_lambda,
ci_1 = mean_lambda + qt( c(0.1), n() - 1) * sd_lambda
) ->
clim_dt
```
### Mean annual temperature
```{r lambdaTempplot,echo=Echo,eval=Eval,cache=Cache,warning=Warng,message=Msg}
#| label: fig-lambdaTempplot
#| fig-width: 8
#| fig-height: 4.5
#| fig-cap: "The Average and 90% confidence interval values for the population growth rate ($\\lambda$) as a function of mean annual temperature for low (left panel) and high (right panel) competition intensity."
clim_dt |>
filter(var == 'Temperature') |>
mutate(
clim = unscaleClim(clim, 'temp')
) |>
ggplot() +
aes(clim, mean_lambda) +
geom_ribbon_interactive(aes(ymin = ci_1, ymax = ci_9), alpha = 0.3,color=NA) +
geom_line_interactive() +
aes(tooltip = species_name, data_id = species_name) +
facet_grid(~comp) +
geom_hline(yintercept = 0, linetype = 2, alpha = 0.5) +
theme_classic() +
labs(
x = 'Mean annual temperature',
y = expression('ln('~lambda~')')
) +
theme(legend.position = 'none') +
ylim(-0.05, 0.11) ->
p_temp
girafe(
ggobj = p_temp,
options = list(
opts_tooltip(css = tooltip_css, opacity = 1),
opts_hover_inv(css = "opacity:0.1;"),
opts_hover(css = "stroke-width:2.5px;"),
opts_sizing(width = 1),
opts_toolbar(position = 'top', saveaspng = FALSE),
opts_zoom(max = 5)
)
)
```
### Mean annual precipitation
```{r lambdaPrec,echo=Echo,eval=Eval,cache=Cache,warning=Warng,message=Msg}
#| label: fig-lambdaPrec
#| fig-width: 8
#| fig-height: 4.5
#| fig-cap: "The Average and 90% confidence interval values for the population growth rate ($\\lambda$) as a function of mean annual precipitation for low (left panel) and high (right panel) competition intensity."
clim_dt |>
filter(var == 'Precipitation') |>
mutate(
clim = unscaleClim(clim, 'prec')
) |>
ggplot() +
aes(clim, mean_lambda) +
geom_ribbon_interactive(aes(ymin = ci_1, ymax = ci_9), alpha = 0.3,color=NA) +
geom_line_interactive() +
aes(tooltip = species_name, data_id = species_name) +
facet_grid(~comp) +
geom_hline(yintercept = 0, linetype = 2, alpha = 0.5) +
theme_classic() +
labs(
x = 'Mean annual precipitation',
y = expression('ln('~lambda~')')
) +
theme(legend.position = 'none') +
ylim(-0.05, 0.11)->
p_prec
girafe(
ggobj = p_prec,
options = list(
opts_tooltip(css = tooltip_css, opacity = 1),
opts_hover_inv(css = "opacity:0.1;"),
opts_hover(css = "stroke-width:2.5px;"),
opts_sizing(width = 1),
opts_toolbar(position = 'top', saveaspng = FALSE),
opts_zoom(max = 5)
)
)
```