Skip to content

Commit

Permalink
Merge branch 'master' into here-be-dragons
Browse files Browse the repository at this point in the history
  • Loading branch information
Tess-LaCoil authored Dec 2, 2024
2 parents 12d197f + 8fe023f commit 03c5865
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 81 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ Suggests:
rmarkdown,
testthat (>= 3.0.0),
withr,
mnormt
mnormt,
here,
patchwork
VignetteBuilder: knitr
Config/testthat/edition: 3
LazyData: true
Binary file added inst/extdata/tree_canham_fit.rds
Binary file not shown.
29 changes: 13 additions & 16 deletions vignettes/canham.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ title: "Case study 3: Canham function growth with tree data from Barro Colorado
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{canham}
%\VignetteEncoding{UTF-8}
%\VignetteEngine{knitr::rmarkdown}
editor_options:
chunk_output_type: console
%\VignetteEncoding{UTF-8}
bibliography: vignette.bib
---

```{r, include = FALSE}
Expand All @@ -16,12 +15,6 @@ knitr::opts_chunk$set(
eval = TRUE
)
# job::job({
# knitr::knit("vignettes/3-canham.Rmd.orig", "vignettes/3-canham.Rmd")
# })
```

```{r}
options(rmarkdown.html_vignette.check_title = FALSE)
```

Expand All @@ -31,13 +24,13 @@ library(dplyr)
library(ggplot2)
```

Our final case study reproduces analysis from \cite{obrien2024allindividuals} with a small sample size for G. recondita in order to make the model tractable for a demonstration.
Our final case study reproduces analysis from @obrien2024allindividuals with a small sample size for G. recondita in order to make the model tractable for a demonstration.

The function we use here is based on \cite{canham2004neighborhood}, and is a three parameter non-linear ODE given by
The function we use here is based on @canham2004neighborhood, and is a three parameter non-linear ODE given by
$$g(S(t);\, g_{max}, S_{max}, k) = g_{max} \exp \Bigg(-\frac{1}{2}\bigg(\frac{\ln(S(t)/S_{max})}{k} \bigg)^2 \Bigg).$$
The Canham function, as we refer to it, describes hum-shaped growth that accelerates to a peak at $(S_{max}, g_{max})$ then declines to 0 at a rate controlled by $k$. The Canham function does not have an analytic solution the way that the previous function did, so we are unable to directly encode the sizes over time and must instead use a numerical method.

The Canham function has been used for a lot of growth analysis such as \cite{herault2011functional} and \cite{canham2006neighborhood} as well as our own previous work in \cite{obrien2024allindividuals} and [Paper 2]. The desirable features of the Canham growth model are that it has a period of increasing growth at small sizes, with a finite growth peak at $(S_{max}, g_{max})$, and then decay to near-zero growth. With different parameter combinations Canham can fit a range of growth behaviours to an observed interval: increasing growth, decreasing growth, a growth spike, or steady growth. The downside is that the Canham function is unimodal -- it can only fit a single peak and as such is not suitable to describe the full life history of species that are strongly responsive to their environment as seen in [Paper 2].
The Canham function has been used for a lot of growth analysis such as @herault2011functional and @canham2006neighborhood as well as our own previous work in @obrien2024allindividuals and [Paper 2]. The desirable features of the Canham growth model are that it has a period of increasing growth at small sizes, with a finite growth peak at $(S_{max}, g_{max})$, and then decay to near-zero growth. With different parameter combinations Canham can fit a range of growth behaviours to an observed interval: increasing growth, decreasing growth, a growth spike, or steady growth. The downside is that the Canham function is unimodal -- it can only fit a single peak and as such is not suitable to describe the full life history of species that are strongly responsive to their environment as seen in [Paper 2].

The next bit of code plots the Canham function for chosen parameter values. We have provided some, but encourage playing around with the parameters and seeing what happens to the function.
```{r}
Expand All @@ -60,7 +53,7 @@ ggplot() +
xlim=c(y_0, y_final))
```

The data we use for this demonstration comes from the Barro Colorado Island long term forest plot \cite{condit2019dataset}. We have a simple random sample without replacement of 50 individuals from [species], subject to the following inclusion criteria for individuals:
The data we use for this demonstration comes from the Barro Colorado Island long term forest plot @condit2019dataset. We have a simple random sample without replacement of 50 individuals from \textit{Garcinia recondita}, subject to the following inclusion criteria for individuals:
\begin{itemize}
\item 6 observations since the 1990 change in measurement precision,
\item Consistent stem and tree ID matching,
Expand All @@ -83,7 +76,7 @@ hist(Tree_Size_Data_Transformed$Delta_y_obs,
xlab = "Growth increment (cm)", main="")
```

Due to the complexity of the Canham model the sampling can take up to 3 hours. If you decide to run your own samples we recommend saving the model outputs using `saveRDS()` so you don't need to rerun your model every time. As is, the following block will not run by default as we provide a data set of estimates with the package in the `Tree_Size_Ests` data file which can be accessed directly.
Due to the complexity of the Canham model the sampling can take up to 3 hours. If you decide to run your own samples we recommend saving the model outputs using `saveRDS()` so you don't need to rerun your model every time. We provide a data set of estimates with the package in the `Tree_Size_Ests` data file which can be accessed directly.

```{r, eval=FALSE}
tree_canham_fit <- hmde_model("canham_multi_ind") |>
Expand All @@ -94,8 +87,8 @@ Tree_Size_Ests <- hmde_extract_estimates(model = "canham_multi_ind",
fit = tree_canham_fit,
input_measurement_data = Tree_Size_Data)
saveRDS(tree_canham_fit, "inst/extdata/tree_canham_fit.rds")
saveRDS(Tree_Size_Ests, "inst/extdata/Tree_Size_Ests.rds")
# saveRDS(tree_canham_fit, "tree_canham_fit.rds")
# saveRDS(tree_canham_estimates, "tree_canham_estimates.rds")
```

The model analysis follows the same workflow as the previous demonstrations: we look at how individual sizes over time and fitted growth functions behave, then examine evidence of relationships between parameter values at the individual level. We also look at the species-level parameter CIs and estimates.
Expand Down Expand Up @@ -243,3 +236,7 @@ print(paste0("95% CI for log spread parameter standard deviation: (",
Tree_Size_Ests$population_data$CI_lower[6], " , ",
Tree_Size_Ests$population_data$CI_upper[], ")")) #Raw CI
```


## References

Loading

0 comments on commit 03c5865

Please sign in to comment.