├── _pkgdown.yml ├── LICENSE ├── data ├── shcal13.rda ├── shcal20.rda ├── intcal13.rda ├── intcal20.rda ├── marine13.rda ├── marine20.rda ├── intcal13_raw.rda ├── intcal20_raw.rda ├── marine13_raw.rda ├── shcal13_raw.rda └── shcal20_raw.rda ├── data-raw ├── intcal13.14c ├── intcal13_raw.xlsx ├── intcal20_raw.xlsx ├── marine13_raw.xlsx ├── shcal13_raw.xlsx └── shcal20_raw.xlsx ├── inst ├── extdata │ ├── rc_years_BP_named_columns.csv │ └── fraction_modern_named_columns.csv └── stan │ ├── gaussmix.stan │ └── gaussmix_masked.stan ├── man ├── figures │ └── README-pressure-1.png ├── pipe.Rd ├── load_calib_curve.Rd ├── extract_param.Rd ├── calc_quantiles.Rd ├── sample_trunc_exp.Rd ├── calc_trapez_weights.Rd ├── is_th_reduced_valid.Rd ├── plot_50_percent_quantile.Rd ├── do_bayesian_summary.Rd ├── calc_trunc_gauss_mix_neg_log_lik.Rd ├── sample_gauss_mix.Rd ├── set_calib_curve.Rd ├── plot_known_sim_density.Rd ├── plot_summed_density.Rd ├── phi2tau.Rd ├── plot_best_solution.Rd ├── shcal13_raw.Rd ├── shcal20_raw.Rd ├── marine13_raw.Rd ├── vis_calib_curve.Rd ├── make_blank_density_plot.Rd ├── intcal13_raw.Rd ├── add_shaded_quantiles.Rd ├── calc_calib_curve_frac_modern.Rd ├── calc_gauss_mix_pdf.Rd ├── draw_rc_meas_using_date.Rd ├── calc_gauss_mix_pdf_mat.Rd ├── shcal13.Rd ├── calc_calib_curve_equif_dates.Rd ├── marine20.Rd ├── shcal20.Rd ├── calc_tau_range.Rd ├── marine13.Rd ├── intcal13.Rd ├── intcal20_raw.Rd ├── init_trunc_gauss_mix.Rd ├── set_density_model.Rd ├── import_rc_data.Rd ├── intcal20.Rd ├── calc_meas_matrix.Rd ├── calc_half_life_from_peak.Rd ├── do_bayesian_inference.Rd ├── assess_calib_curve_equif.Rd ├── calc_relative_density.Rd ├── set_sim.Rd ├── set_rc_meas.Rd ├── summarize_trunc_gauss_mix_sample.Rd ├── simulate_rc_data.Rd ├── sample_theta.Rd ├── summarize_bayesian_inference.Rd └── fit_trunc_gauss_mix.Rd ├── docs ├── reference │ ├── figures │ │ └── README-pressure-1.png │ ├── pipe.html │ ├── bd_load_calib_curve.html │ ├── bd_norm_pdf_mat.html │ ├── bd_convert_gauss_mix_param_vect_to_list.html │ ├── bd_convert_gauss_mix_param_list_to_vect.html │ ├── load_calib_curve.html │ └── bd_plot_known_sim_density.html ├── pkgdown.yml ├── articles │ ├── standard_pipeline_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-14-1.png │ │ │ └── unnamed-chunk-29-1.png │ └── index.html ├── link.svg ├── bootstrap-toc.css ├── docsearch.js ├── pkgdown.js ├── bootstrap-toc.js ├── LICENSE-text.html ├── authors.html ├── 404.html └── LICENSE.html ├── setup.R ├── tests ├── testthat.R └── testthat │ └── test-function.R ├── .travis.yml ├── codecov.yml ├── R ├── utils-pipe.R ├── exponential_model_functions.R └── gaussian_mixture_model_functions.R ├── .Rbuildignore ├── baydem.Rproj ├── .gitignore ├── .pre-commit-config.yaml ├── LICENSE.md ├── DESCRIPTION ├── NAMESPACE ├── CODE_OF_CONDUCT.md ├── Dockerfile └── README.md /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | destination: docs 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2020 2 | COPYRIGHT HOLDER: Michael Holton Price 3 | -------------------------------------------------------------------------------- /data/shcal13.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data/shcal13.rda -------------------------------------------------------------------------------- /data/shcal20.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data/shcal20.rda -------------------------------------------------------------------------------- /data/intcal13.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data/intcal13.rda -------------------------------------------------------------------------------- /data/intcal20.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data/intcal20.rda -------------------------------------------------------------------------------- /data/marine13.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data/marine13.rda -------------------------------------------------------------------------------- /data/marine20.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data/marine20.rda -------------------------------------------------------------------------------- /data-raw/intcal13.14c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data-raw/intcal13.14c -------------------------------------------------------------------------------- /data/intcal13_raw.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data/intcal13_raw.rda -------------------------------------------------------------------------------- /data/intcal20_raw.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data/intcal20_raw.rda -------------------------------------------------------------------------------- /data/marine13_raw.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data/marine13_raw.rda -------------------------------------------------------------------------------- /data/shcal13_raw.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data/shcal13_raw.rda -------------------------------------------------------------------------------- /data/shcal20_raw.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data/shcal20_raw.rda -------------------------------------------------------------------------------- /data-raw/intcal13_raw.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data-raw/intcal13_raw.xlsx -------------------------------------------------------------------------------- /data-raw/intcal20_raw.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data-raw/intcal20_raw.xlsx -------------------------------------------------------------------------------- /data-raw/marine13_raw.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data-raw/marine13_raw.xlsx -------------------------------------------------------------------------------- /data-raw/shcal13_raw.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data-raw/shcal13_raw.xlsx -------------------------------------------------------------------------------- /data-raw/shcal20_raw.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/data-raw/shcal20_raw.xlsx -------------------------------------------------------------------------------- /inst/extdata/rc_years_BP_named_columns.csv: -------------------------------------------------------------------------------- 1 | rc_years_BP,rc_years_BP_error 2 | 900,20 3 | 800,400 4 | 850,70 5 | -------------------------------------------------------------------------------- /man/figures/README-pressure-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/man/figures/README-pressure-1.png -------------------------------------------------------------------------------- /inst/extdata/fraction_modern_named_columns.csv: -------------------------------------------------------------------------------- 1 | fraction_modern,fraction_modern_error 2 | .80,.001 3 | .75,.002 4 | .74,.002 5 | .82,.001 6 | -------------------------------------------------------------------------------- /docs/reference/figures/README-pressure-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/docs/reference/figures/README-pressure-1.png -------------------------------------------------------------------------------- /setup.R: -------------------------------------------------------------------------------- 1 | install.packages('devtools',dependencies=T) 2 | library(devtools) 3 | install_github('https://github.com/eehh-stanford/baydem',dependencies=T) 4 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: '2.5' 2 | pkgdown: 1.6.1 3 | pkgdown_sha: ~ 4 | articles: 5 | standard_pipeline: standard_pipeline.html 6 | last_built: 2021-11-07T16:58Z 7 | 8 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(baydem) 3 | 4 | test_check("baydem") 5 | list.files("analysis", 6 | full.names = TRUE, 7 | pattern = "FINAL" 8 | ) 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r 2 | 3 | language: R 4 | cache: packages 5 | 6 | after_success: 7 | - Rscript -e 'covr::codecov()' -------------------------------------------------------------------------------- /docs/articles/standard_pipeline_files/figure-html/unnamed-chunk-14-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/docs/articles/standard_pipeline_files/figure-html/unnamed-chunk-14-1.png -------------------------------------------------------------------------------- /docs/articles/standard_pipeline_files/figure-html/unnamed-chunk-29-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eehh-stanford/baydem/HEAD/docs/articles/standard_pipeline_files/figure-html/unnamed-chunk-29-1.png -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | patch: 10 | default: 11 | target: auto 12 | threshold: 1% 13 | -------------------------------------------------------------------------------- /R/utils-pipe.R: -------------------------------------------------------------------------------- 1 | #' Pipe operator 2 | #' 3 | #' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 4 | #' 5 | #' @name %>% 6 | #' @rdname pipe 7 | #' @keywords internal 8 | #' @export 9 | #' @importFrom magrittr %>% 10 | #' @usage lhs \%>\% rhs 11 | NULL 12 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^_pkgdown\.yml$ 4 | ^docs$ 5 | ^pkgdown$ 6 | ^README\.Rmd$ 7 | ^CODE_OF_CONDUCT\.md$ 8 | ^\.travis\.yml$ 9 | ^codecov\.yml$ 10 | ^data-raw$ 11 | ^LICENSE\.md$ 12 | ^\.pre-commit-config\.yaml$ 13 | ^codemeta\.json$ 14 | setup.R 15 | Dockerfile 16 | -------------------------------------------------------------------------------- /man/pipe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-pipe.R 3 | \name{\%>\%} 4 | \alias{\%>\%} 5 | \title{Pipe operator} 6 | \usage{ 7 | lhs \%>\% rhs 8 | } 9 | \description{ 10 | See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /baydem.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageRoxygenize: rd,collate,namespace 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac trash files 2 | .DS_Store 3 | */.DS_Store 4 | R/.DS_Store 5 | 6 | # History files 7 | .Rhistory 8 | .Rapp.history 9 | 10 | # Session Data files 11 | .RData 12 | 13 | # RStudio files 14 | .Rproj.user/ 15 | .Rproj.user 16 | 17 | # vi temp files 18 | *.swp 19 | *.swo 20 | 21 | .idea 22 | 23 | tests/testthat/Rplots.pdf 24 | Rplots.pdf 25 | 26 | *~ 27 | 28 | vignettes/rc_data.csv 29 | vignettes/rc_example.rds 30 | vignettes/sim_example.rds -------------------------------------------------------------------------------- /man/load_calib_curve.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/radiocarbon_functions.R 3 | \name{load_calib_curve} 4 | \alias{load_calib_curve} 5 | \title{Load Calibration Curve} 6 | \usage{ 7 | load_calib_curve(calib_curve) 8 | } 9 | \arguments{ 10 | \item{calib_curve}{Name of calibration curve. One of: "intcal20", "marine20", 11 | "shcal20", "intcal13", "marine13", or "shcal13"} 12 | } 13 | \value{ 14 | The calibration dataframe, with columns year_BP, uncal_year_BP, and 15 | uncal_year_BP_error 16 | } 17 | \description{ 18 | Parse and return the radiocarbon calibration curve stored in data. 19 | } 20 | -------------------------------------------------------------------------------- /man/extract_param.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bayesian_inference_functions.R 3 | \name{extract_param} 4 | \alias{extract_param} 5 | \title{Extract the Bayesian samples for a Gaussian mixture model generated by 6 | \code{sample_theta}} 7 | \usage{ 8 | extract_param(fit) 9 | } 10 | \arguments{ 11 | \item{fit}{The fit from stan, of class stanfit} 12 | } 13 | \value{ 14 | A matrix of samples with dimensions S by (3*K), where S is the number 15 | of non-warmup samples 16 | } 17 | \description{ 18 | The input fit is the result of a call to stan by 19 | \code{sample_theta}, of class stanfit. Return a matrix TH with 20 | dimensions S x (3*K), where S is the number of samples (across all chains, 21 | and excluding warmup), and K is the number of mixtures. 22 | } 23 | -------------------------------------------------------------------------------- /man/calc_quantiles.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bayesian_inference_functions.R 3 | \name{calc_quantiles} 4 | \alias{calc_quantiles} 5 | \title{Calculate the quantiles for an input matrix X} 6 | \usage{ 7 | calc_quantiles(X, probs = c(0.025, 0.5, 0.975)) 8 | } 9 | \arguments{ 10 | \item{X}{The matrix for which quantiles are calculated, with dimension S x G} 11 | 12 | \item{probs}{The probability values at which to calculate the quantiles 13 | (default: \code{c(0.025, 0.5, 0.975)})} 14 | } 15 | \value{ 16 | The quantiles, a matrix with dimension length(probs) x G 17 | } 18 | \description{ 19 | The input matrix X has dimensions S x G, where S is the number of samples and 20 | G the number of grid points at which X was evaluated. Calculate quantiles for 21 | each grid point, g = 1,2,..G. 22 | } 23 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # All available hooks: https://pre-commit.com/hooks.html 2 | # R specific hooks: https://github.com/lorenzwalthert/precommit 3 | repos: 4 | - repo: https://github.com/lorenzwalthert/precommit 5 | rev: v0.0.0.9027 6 | hooks: 7 | # any R project 8 | - id: style-files 9 | args: [--style_pkg=styler, --style_fun=tidyverse_style] 10 | # - id: lintr 11 | - id: parsable-R 12 | - id: no-browser-statement 13 | - id: readme-rmd-rendered 14 | # R package development 15 | - id: roxygenize 16 | # - id: use-tidy-description 17 | # - id: deps-in-desc 18 | - id: codemeta-description-updated 19 | - repo: https://github.com/pre-commit/pre-commit-hooks 20 | rev: v2.5.0 21 | hooks: 22 | - id: check-added-large-files 23 | args: ['--maxkb=50000'] 24 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /man/sample_trunc_exp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/exponential_model_functions.R 3 | \name{sample_trunc_exp} 4 | \alias{sample_trunc_exp} 5 | \title{Sample from a truncated exponential distribution} 6 | \usage{ 7 | sample_trunc_exp(N, r0, tau_min, tau_max) 8 | } 9 | \arguments{ 10 | \item{N}{The number of samples to make} 11 | 12 | \item{r0}{The rate parameter} 13 | 14 | \item{tau_min}{The lower limit for truncation} 15 | 16 | \item{tau_max}{The upper limit for truncation} 17 | } 18 | \value{ 19 | A vector of N samples between tau_min and tau_max 20 | } 21 | \description{ 22 | Make N samples from a truncated exponential distribution with the density 23 | function r0\emph{exp(r0}t). The rate r0 can be positive (growth) or negative 24 | (decay). The density function is normalized to integrate to 1 on the interval 25 | tau_min to tau_max. 26 | } 27 | -------------------------------------------------------------------------------- /man/calc_trapez_weights.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/radiocarbon_functions.R 3 | \name{calc_trapez_weights} 4 | \alias{calc_trapez_weights} 5 | \title{Calculate integration weights assuming the midpoint rule} 6 | \usage{ 7 | calc_trapez_weights(tau) 8 | } 9 | \arguments{ 10 | \item{tau}{A vector of locations where the function is sampled, possibly 11 | irregularly} 12 | } 13 | \value{ 14 | A vector of integration weights the same length as tau 15 | } 16 | \description{ 17 | tau is a vector of locations where a function to be integrated is evaluated 18 | (the function values, f, are not input). Let tau_g be the locations of 19 | integration and f_g the corresponding function values for g=1, 2, ... G. 20 | Assuming trapezoidal integration at the midpoints between elements of tau, 21 | the weights to use for integration are dtau_g = (tau_(g+1) - tau_(g-1)) / 2, 22 | where the conventions tau_0 = tau_1 and tau_(G+1) = tau_G are used. 23 | } 24 | -------------------------------------------------------------------------------- /man/is_th_reduced_valid.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/max_lik_fitting_functions.R 3 | \name{is_th_reduced_valid} 4 | \alias{is_th_reduced_valid} 5 | \title{A helper function to determine if the reduced form parameter vector is valid} 6 | \usage{ 7 | is_th_reduced_valid(th_reduced, s_min = 0) 8 | } 9 | \arguments{ 10 | \item{th_reduced}{The paramater vector without the first mixture weight} 11 | 12 | \item{s_min}{A minimum value for the mixture standard deviations 13 | (default: 0)} 14 | } 15 | \value{ 16 | TRUE or FALSE 17 | } 18 | \description{ 19 | The paramater vector is invalid if: 20 | 21 | (a) Any mixture weight does not lie between 0 and 1 22 | (b) mu is not ordered from small to large values 23 | (c) A standard deviation is lower than s_min 24 | 25 | Neither bounds on the values of the means or the upper values of the standard 26 | deviations are checked, but they are enforced in the optimization in 27 | fit_trunc_gauss_mix. 28 | } 29 | -------------------------------------------------------------------------------- /man/plot_50_percent_quantile.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotting_functions.R 3 | \name{plot_50_percent_quantile} 4 | \alias{plot_50_percent_quantile} 5 | \title{Plot the 50 percent quantile curve} 6 | \usage{ 7 | plot_50_percent_quantile(bayesian_summary, add = F, ...) 8 | } 9 | \arguments{ 10 | \item{bayesian_summary}{A list-like object of class 11 | \code{bd_bayesian_summary} with information on the quantiles of the density 12 | function and growth rate (see \code{summarize_bayesian_inference}).} 13 | 14 | \item{add}{Whether to make a new plot or add to the active plot (default: 15 | FALSE).} 16 | 17 | \item{...}{Additional parameters to pass to plot / lines} 18 | } 19 | \description{ 20 | The input, bayesian_summary, is the result of a call to 21 | \code{summarize_bayesian_inference}. By default, a new plot is made, but 22 | if \code{add = TRUE} the curve is added to the active plot. 23 | } 24 | \seealso{ 25 | \code{\link[=summarize_bayesian_inference]{summarize_bayesian_inference()}} 26 | } 27 | -------------------------------------------------------------------------------- /man/do_bayesian_summary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_io_functions.R 3 | \name{do_bayesian_summary} 4 | \alias{do_bayesian_summary} 5 | \title{Summarize the best model sampled by do_bayesian_inference} 6 | \usage{ 7 | do_bayesian_summary(data_dir, analysis_name) 8 | } 9 | \arguments{ 10 | \item{data_dir}{The directory in which to store analysis data.} 11 | 12 | \item{analysis_name}{A unique name for a given analysis in data_dir.} 13 | 14 | \item{plot_file_name}{An optional file name for saving the file} 15 | } 16 | \description{ 17 | This is one of a set of helper functions for undertaking a typical analysis 18 | of radiocarbon dates. For details on the overall framework for these helper 19 | function, see set_rc_meas. 20 | 21 | Call summarize_bayesian_inference for the best model created by 22 | do_bayesian_inference (the previous step in the standard pipeline). Store the 23 | result in the save file. 24 | } 25 | \seealso{ 26 | \code{\link[=do_bayesian_inference]{do_bayesian_inference()}} 27 | } 28 | -------------------------------------------------------------------------------- /man/calc_trunc_gauss_mix_neg_log_lik.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/max_lik_fitting_functions.R 3 | \name{calc_trunc_gauss_mix_neg_log_lik} 4 | \alias{calc_trunc_gauss_mix_neg_log_lik} 5 | \title{Calculate the negative log-likelihood of a truncuated Gaussian mixture fit} 6 | \usage{ 7 | calc_trunc_gauss_mix_neg_log_lik(th_reduced, M, tau, s_min = 0) 8 | } 9 | \arguments{ 10 | \item{th_reduced}{The paramater vector without the first mixture weight} 11 | 12 | \item{M}{The measurement matrix (see calc_meas_matrix)} 13 | 14 | \item{tau}{The sampling grid} 15 | 16 | \item{s_min}{A minimum value for the mixture standard deviations 17 | (default: 0)} 18 | } 19 | \value{ 20 | The negative log-likelihood 21 | } 22 | \description{ 23 | The input parameter vector is the parameter vector without the first mixture 24 | weight. The minimum and maximum calendar dates are assumed to be the minumum 25 | and maximum values of the sampling grid, tau. 26 | } 27 | \seealso{ 28 | \code{\link[=calc_meas_matrix]{calc_meas_matrix()}} 29 | } 30 | -------------------------------------------------------------------------------- /man/sample_gauss_mix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation_functions.R 3 | \name{sample_gauss_mix} 4 | \alias{sample_gauss_mix} 5 | \title{Sample from a possibly truncated Gaussian mixture} 6 | \usage{ 7 | sample_gauss_mix(N, th, tau_min = NA, tau_max = NA) 8 | } 9 | \arguments{ 10 | \item{N}{Number of samples} 11 | 12 | \item{th}{Parameterization vector for the Gaussian mixture} 13 | 14 | \item{tau_min}{(Optional) Lower bound for samples} 15 | 16 | \item{tau_max}{(Optional) Upper bound for samples} 17 | } 18 | \value{ 19 | N samples from the Gaussian mixture 20 | } 21 | \description{ 22 | \code{N} is the number of samples to draw and \code{th} specifies the Gaussian mixture 23 | with the ordering (pi_1,...,pi_K,mu_1,...,mu_K,s_1,...,s_K), where \code{K} is the 24 | number of mixture components. Optionally, the samples are drawn on the 25 | truncated interval \code{tau_min} to \code{tau_max}. Because of limitations in the 26 | package \code{distr}, the maximum number of mixture components suppored is K=4. 27 | } 28 | -------------------------------------------------------------------------------- /man/set_calib_curve.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_io_functions.R 3 | \name{set_calib_curve} 4 | \alias{set_calib_curve} 5 | \title{Set the radiocarbon calibration curve for an analysis} 6 | \usage{ 7 | set_calib_curve(data_dir, analysis_name, calibration_curve) 8 | } 9 | \arguments{ 10 | \item{data_dir}{The directory in which to store analysis data} 11 | 12 | \item{analysis_name}{A unique name for a given analysis in data_dir} 13 | 14 | \item{calibration_curve}{Either the name of a calibration curve or a data 15 | frame specifying the calibration curve (see load_calib_curve for format and 16 | choices).} 17 | } 18 | \description{ 19 | This is one of a set of helper functions for undertaking a typical analysis 20 | of radiocarbon dates. For details on the overall framework for these helper 21 | function, see set_rc_meas. 22 | } 23 | \seealso{ 24 | \itemize{ 25 | \item \code{\link[=set_sim]{set_sim()}} for an overview of the "standard pipeline" 26 | \item \code{\link[=load_calib_curve]{load_calib_curve()}} for the format of \code{calib_df} 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /man/plot_known_sim_density.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotting_functions.R 3 | \name{plot_known_sim_density} 4 | \alias{plot_known_sim_density} 5 | \title{Plot the known simulation density} 6 | \usage{ 7 | plot_known_sim_density(bayesian_summary, add = F, ...) 8 | } 9 | \arguments{ 10 | \item{bayesian_summary}{A list-like object of class 11 | \code{bd_bayesian_summary} with information on the quantiles of the density 12 | function and growth rate (see \code{summarize_bayesian_inference}).} 13 | 14 | \item{add}{Whether to make a new plot or add to the active plot (default: 15 | FALSE).} 16 | 17 | \item{...}{Additional parameters to pass to plot / lines} 18 | } 19 | \description{ 20 | The input, bayesian_summary, is the result of a call to 21 | \code{summarize_bayesian_inference}. By default, a new plot is made, but 22 | if \code{add = TRUE} the curve is added to the active plot. By default, a 23 | new plot is made, but if add = TRUE the curve is added to the active plot. 24 | } 25 | \seealso{ 26 | \code{\link[=summarize_bayesian_inference]{summarize_bayesian_inference()}} 27 | } 28 | -------------------------------------------------------------------------------- /man/plot_summed_density.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotting_functions.R 3 | \name{plot_summed_density} 4 | \alias{plot_summed_density} 5 | \title{Plot the summed probability density function (SPDF)} 6 | \usage{ 7 | plot_summed_density(bayesian_summary, add = F, ...) 8 | } 9 | \arguments{ 10 | \item{bayesian_summary}{A list-like object of class 11 | \code{bd_bayesian_summary} with information on the quantiles of the density 12 | function and growth rate (see \code{summarize_bayesian_inference}).} 13 | 14 | \item{add}{Whether to make a new plot or add to the active plot (default: 15 | FALSE).} 16 | 17 | \item{...}{Additional parameters to pass to plot / lines} 18 | } 19 | \description{ 20 | The input, bayesian_summary, is the result of a call to 21 | \code{summarize_bayesian_inference}. By default, a new plot is made, but 22 | if \code{add = TRUE} the curve is added to the active plot. By default, a 23 | new plot is made, but if add = TRUE the curve is added to the active plot. 24 | } 25 | \seealso{ 26 | \code{\link[=summarize_bayesian_inference]{summarize_bayesian_inference()}} 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2020 Michael Holton Price 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /man/phi2tau.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/radiocarbon_functions.R 3 | \name{phi2tau} 4 | \alias{phi2tau} 5 | \title{Find the calendar date from the fraction modern value given known bounding 6 | indices} 7 | \usage{ 8 | phi2tau(tau_curve, phi_curve, phi_known, ii_lo, ii_hi) 9 | } 10 | \arguments{ 11 | \item{tau_curve}{Calibration curve calendar dates} 12 | 13 | \item{phi_curve}{Calibration curve fraction moderns} 14 | 15 | \item{phi_known}{Known fraction modern value} 16 | 17 | \item{ii_lo}{Lower bounding index} 18 | 19 | \item{ii_hi}{Upper bounding index} 20 | } 21 | \value{ 22 | The calendar date corresponding to the input phi_known 23 | } 24 | \description{ 25 | tau_curve and phi_curve give the calendar date and fraction modern of the 26 | radiocarbon calibration curve. It is known that the calendar date lies 27 | between \code{tau_curve[ii_lo]} and \code{tau_curve[ii_hi]}. Interpolate to find the 28 | calendar date corresponding to the input phi_known. This function is called 29 | by \code{assess_calib_curve_equif}. 30 | } 31 | \seealso{ 32 | \code{\link[=assess_calib_curve_equif]{assess_calib_curve_equif()}} 33 | } 34 | -------------------------------------------------------------------------------- /R/exponential_model_functions.R: -------------------------------------------------------------------------------- 1 | #' @title 2 | #' Sample from a truncated exponential distribution 3 | #' 4 | #' @description 5 | #' Make N samples from a truncated exponential distribution with the density 6 | #' function r0*exp(r0*t). The rate r0 can be positive (growth) or negative 7 | #' (decay). The density function is normalized to integrate to 1 on the interval 8 | #' tau_min to tau_max. 9 | #' 10 | #' @param N The number of samples to make 11 | #' @param r0 The rate parameter 12 | #' @param tau_min The lower limit for truncation 13 | #' @param tau_max The upper limit for truncation 14 | #' 15 | #' @return A vector of N samples between tau_min and tau_max 16 | #' 17 | #' @export 18 | sample_trunc_exp <- function(N, r0, tau_min, tau_max) { 19 | # Call RGeode::rexptr for the sampling. rexptr cannot be used direclty 20 | # because it does not support r0 being zero or negative. The input to rexptr 21 | # is -r0. 22 | if (r0 > 0) { 23 | return(tau_max - RGeode::rexptr(N, r0, range = c(0, tau_max - tau_min))) 24 | } else if (r0 == 0) { 25 | return(stats::runif(N, tau_min, tau_max)) 26 | } else { 27 | return(RGeode::rexptr(N, -r0, range = c(tau_min, tau_max))) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /man/plot_best_solution.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_io_functions.R 3 | \name{plot_best_solution} 4 | \alias{plot_best_solution} 5 | \title{Plot the best model created by do_bayesian_inference} 6 | \usage{ 7 | plot_best_solution( 8 | data_dir, 9 | analysis_name, 10 | plot_file_name = NA, 11 | add_known_density = FALSE 12 | ) 13 | } 14 | \arguments{ 15 | \item{data_dir}{The directory in which to store analysis data.} 16 | 17 | \item{analysis_name}{A unique name for a given analysis in data_dir.} 18 | 19 | \item{plot_file_name}{An optional file name for saving the file} 20 | } 21 | \description{ 22 | Plot the best model among those for which Bayesian inference was done with 23 | the standard pipeline. The plot is a standard plot shows the 50\% and +/- 2.5\% 24 | quantiles. If an output file name is provided (plot_file_name), the plot is 25 | written to file. The format is detected from the extension (e.g., if 26 | plot_file_name is "analysis.pdf", a PDF file is written. If the extension is 27 | not one of pdf or png an error is thrown. 28 | } 29 | \seealso{ 30 | \code{\link[=do_bayesian_inference]{do_bayesian_inference()}} 31 | } 32 | -------------------------------------------------------------------------------- /man/shcal13_raw.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bd_data.R 3 | \docType{data} 4 | \name{shcal13_raw} 5 | \alias{shcal13_raw} 6 | \title{The raw data for constructing the SHCal13 Southern Hemisphere atmospheric calibration curve} 7 | \format{ 8 | An object of class \code{list} of length 3. 9 | } 10 | \source{ 11 | http://intcal.qub.ac.uk/shcal13/query/query.php 12 | } 13 | \usage{ 14 | shcal13_raw 15 | } 16 | \description{ 17 | A \code{base::list} of \code{tibble::tibble} objects containing the data for calculating the 18 | SHCal13 Southern Hemisphere atmospheric radiocarbon calibration curve. 19 | } 20 | \details{ 21 | These data are as available from the IntCal webservice 22 | hosted at Queen's University, Belfast. Details on the structure of the data can be found at 23 | \url{http://intcal.qub.ac.uk/shcal13/query/}. 24 | } 25 | \references{ 26 | Alan G Hogg, Quan Hua, Paul G Blackwell, Caitlin E Buck, Thomas P Guilderson, 27 | Timothy J Heaton, Mu Niu, Jonathan G Palmer, Paula J Reimer, Ron W Reimer, 28 | Christian S M Turney, Susan R H Zimmerman 29 | \emph{Radiocarbon} 55(4). DOI: \href{https://doi.org/10.2458/azu_js_rc.55.16783}{10.2458/azu_js_rc.55.16783} 30 | } 31 | \keyword{datasets} 32 | -------------------------------------------------------------------------------- /man/shcal20_raw.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bd_data.R 3 | \docType{data} 4 | \name{shcal20_raw} 5 | \alias{shcal20_raw} 6 | \title{The raw data for constructing the SHCal20 Southern Hemisphere atmospheric calibration curve} 7 | \format{ 8 | An object of class \code{list} of length 3. 9 | } 10 | \source{ 11 | http://intcal.org/JS/JSshcal20/query/query.php 12 | } 13 | \usage{ 14 | shcal20_raw 15 | } 16 | \description{ 17 | A \code{base::list} of \code{tibble::tibble} objects containing the data for calculating the 18 | SHCal20 Southern Hemisphere atmospheric radiocarbon calibration curve. 19 | } 20 | \details{ 21 | These data are as available from the IntCal webservice 22 | hosted at Queen's University, Belfast. Details on the structure of the data can be found at 23 | \url{http://intcal.org/JS/JSshcal20/query/}. 24 | } 25 | \references{ 26 | Hogg, A. G., Heaton, T. J., Hua, Q., Palmer, J. G., Turney, C. S. M., 27 | Southon, J., Bayliss, A., Blackwell, P. G., Boswijk, G., Bronk Ramsey, C., 28 | Pearson, C., Petchey, F., Reimer, P., Reimer, R. and Wacker, L. (2020) 29 | “SHCal20 SOUTHERN HEMISPHERE CALIBRATION, 0–55,000 YEARS CAL BP,” 30 | Radiocarbon. Cambridge University Press, pp. 1–20. 31 | DOI: \href{https://doi.org/10.1017/RDC.2020.59}{10.1017/RDC.2020.59} 32 | } 33 | \keyword{datasets} 34 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Type: Package 2 | Package: baydem 3 | Title: Bayesian Tools for Reconstructing Past and Present Demography 4 | Version: 1.0.0 5 | Authors@R: 6 | c(person(given = c("Michael", "Holton"), 7 | family = "Price", 8 | role = c("aut", "cre"), 9 | email = "michaelholtonprice@sgmail.com"), 10 | person(given = c("R.", "Kyle"), 11 | family = "Bocinsky", 12 | role = "ctb", 13 | email = "bocinsky@gmail.com")) 14 | Description: Bayesian tools for reconstructing past and present 15 | demography. 16 | License: MIT + file LICENSE 17 | URL: https://github.com/eehh-stanford/baydem 18 | BugReports: https://github.com/eehh-stanford/baydem/issues 19 | Depends: 20 | magrittr, 21 | R (>= 3.5.0) 22 | Imports: 23 | base, 24 | Bchron, 25 | dfoptim, 26 | distr, 27 | doParallel, 28 | dplyr, 29 | evd, 30 | foreach, 31 | graphics, 32 | loo, 33 | MCMCpack, 34 | miscTools, 35 | parallel, 36 | RGeode, 37 | rstan, 38 | stats, 39 | tibble, 40 | utils, 41 | Suggests: 42 | devtools, 43 | covr, 44 | knitr, 45 | pkgdown, 46 | testthat, 47 | usethis 48 | VignetteBuilder: 49 | knitr 50 | Encoding: UTF-8 51 | LazyData: true 52 | Roxygen: list(markdown = TRUE) 53 | RoxygenNote: 7.1.1 54 | -------------------------------------------------------------------------------- /man/marine13_raw.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bd_data.R 3 | \docType{data} 4 | \name{marine13_raw} 5 | \alias{marine13_raw} 6 | \title{The raw data for constructing the Marine13 calibration curve} 7 | \format{ 8 | An object of class \code{list} of length 5. 9 | } 10 | \source{ 11 | http://intcal.qub.ac.uk/marine/query/query.php 12 | } 13 | \usage{ 14 | marine13_raw 15 | } 16 | \description{ 17 | A \code{base::list} of \code{tibble::tibble} objects containing the data for calculating the 18 | Marine13 marine radiocarbon calibration curve. 19 | } 20 | \details{ 21 | These data are as available from the IntCal webservice 22 | hosted at Queen's University, Belfast. Details on the structure of the data can be found at 23 | \url{http://intcal.qub.ac.uk/marine/query/}. 24 | } 25 | \references{ 26 | Reimer PJ, Bard E, Bayliss A, Beck JW, Blackwell PG, Bronk Ramsey C, Buck CE, 27 | Cheng H, Edwards RL, Friedrich M, Grootes PM, Guilderson TP, Haflidason H, 28 | Hajdas I, Hatté C, Heaton TJ, Hogg AG, Hughen KA, Kaiser KF, Kromer B, 29 | Manning SW, Niu M, Reimer RW, Richards DA, Scott EM, Southon JR, Turney CSM, 30 | van der Plicht J. IntCal13 and MARINE13 radiocarbon age calibration curves 0-50000 years calBP. 31 | \emph{Radiocarbon} 55(4). DOI: \href{https://doi.org/10.2458/azu_js_rc.55.16947}{10.2458/azu_js_rc.55.16947} 32 | } 33 | \keyword{datasets} 34 | -------------------------------------------------------------------------------- /man/vis_calib_curve.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotting_functions.R 3 | \name{vis_calib_curve} 4 | \alias{vis_calib_curve} 5 | \title{Visualize the calibration curve with equifinal and non-equifinal time spans} 6 | \usage{ 7 | vis_calib_curve( 8 | tau_min, 9 | tau_max, 10 | calib_df, 11 | invert_col = "gray90", 12 | point_col = "black", 13 | point_pch = 19, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{tau_min}{The minimum calendar date for plotting (AD)} 19 | 20 | \item{tau_max}{The maximum calendar date for plotting (AD)} 21 | 22 | \item{calib_df}{The calibration data frame, with columns year_BP, 23 | uncal_year_BP, and uncal_year_BP_error} 24 | 25 | \item{invert_col}{The color for shading invertible regions 26 | (default: \code{gray90})} 27 | 28 | \item{point_col}{The color for calibration curve points (default: \code{black})} 29 | 30 | \item{point_pch}{The symbol for calibration curve points (default: \code{19})} 31 | 32 | \item{...}{Additional inputs to plots} 33 | } 34 | \description{ 35 | Vizualize the input calibration curve, calib_df, on the interval tau_min to 36 | tau_max. This involves plotting the curve itself and shading invertible 37 | (non-equifinal) and non-invertible (equifinal) regions. 38 | } 39 | \seealso{ 40 | \code{\link[=load_calib_curve]{load_calib_curve()}} for the format of \code{calib_df} 41 | } 42 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export("%>%") 4 | export(add_shaded_quantiles) 5 | export(assess_calib_curve_equif) 6 | export(calc_calib_curve_equif_dates) 7 | export(calc_calib_curve_frac_modern) 8 | export(calc_gauss_mix_pdf) 9 | export(calc_gauss_mix_pdf_mat) 10 | export(calc_half_life_from_peak) 11 | export(calc_meas_matrix) 12 | export(calc_quantiles) 13 | export(calc_relative_density) 14 | export(calc_tau_range) 15 | export(calc_trapez_weights) 16 | export(calc_trunc_gauss_mix_neg_log_lik) 17 | export(do_bayesian_inference) 18 | export(do_bayesian_summary) 19 | export(draw_rc_meas_using_date) 20 | export(extract_param) 21 | export(fit_trunc_gauss_mix) 22 | export(import_rc_data) 23 | export(init_trunc_gauss_mix) 24 | export(is_th_reduced_valid) 25 | export(load_calib_curve) 26 | export(make_blank_density_plot) 27 | export(phi2tau) 28 | export(plot_50_percent_quantile) 29 | export(plot_best_solution) 30 | export(plot_known_sim_density) 31 | export(plot_summed_density) 32 | export(sample_gauss_mix) 33 | export(sample_theta) 34 | export(sample_trunc_exp) 35 | export(set_calib_curve) 36 | export(set_density_model) 37 | export(set_rc_meas) 38 | export(set_sim) 39 | export(simulate_rc_data) 40 | export(summarize_bayesian_inference) 41 | export(summarize_trunc_gauss_mix_sample) 42 | export(vis_calib_curve) 43 | import(doParallel) 44 | import(foreach) 45 | importFrom(magrittr,"%>%") 46 | -------------------------------------------------------------------------------- /man/make_blank_density_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotting_functions.R 3 | \name{make_blank_density_plot} 4 | \alias{make_blank_density_plot} 5 | \title{Prepare a blank plot for showing densities} 6 | \usage{ 7 | make_blank_density_plot( 8 | bayesian_summary, 9 | xlim = NA, 10 | ylim = NA, 11 | xlab = "Calendar Date [AD]", 12 | ylab = "Density", 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{bayesian_summary}{A list-like object of class 18 | \code{bd_bayesian_summary} with information on the quantiles of the density 19 | function and growth rate (see \code{summarize_bayesian_inference}).} 20 | 21 | \item{xlim}{Numeric vector of length 2, giving the x coordinate range.} 22 | 23 | \item{ylim}{Numeric vector of length 2, giving the y coordinate range.} 24 | 25 | \item{xlab}{x-axis label.} 26 | 27 | \item{ylab}{y-axis label.} 28 | 29 | \item{...}{Additional parameters to pass to plot.} 30 | } 31 | \description{ 32 | The input, bayesian_summary, is the result of a call to 33 | \code{summarize_bayesian_inference}. Prepare a blank plot for adding density 34 | information, e.g. by calling \code{plot_50_percent_quantile} and 35 | \code{add_shaded_quantiles}. If the axis labels and limits are not specified, 36 | sensible defaults are used. 37 | } 38 | \seealso{ 39 | \code{\link[=summarize_bayesian_inference]{summarize_bayesian_inference()}} 40 | } 41 | -------------------------------------------------------------------------------- /man/intcal13_raw.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bd_data.R 3 | \docType{data} 4 | \name{intcal13_raw} 5 | \alias{intcal13_raw} 6 | \title{The raw data for constructing the IntCal13 calibration curve} 7 | \format{ 8 | An object of class \code{list} of length 4. 9 | } 10 | \source{ 11 | http://intcal.qub.ac.uk/intcal13/query/query.php 12 | } 13 | \usage{ 14 | intcal13_raw 15 | } 16 | \description{ 17 | A \code{base::list} of \code{tibble::tibble} objects containing the data for calculating the IntCal13 Northern Hemisphere 18 | atmospheric radiocarbon calibration curve. 19 | } 20 | \details{ 21 | These data are as available from the IntCal webservice 22 | hosted at Queen's University, Belfast. Details on the structure of the data can be found at 23 | \url{http://intcal.qub.ac.uk/intcal13/query/}. 24 | } 25 | \references{ 26 | Reimer PJ, Bard E, Bayliss A, Beck JW, Blackwell PG, Bronk Ramsey C, Buck CE, 27 | Cheng H, Edwards RL, Friedrich M, Grootes PM, Guilderson TP, Haflidason H, 28 | Hajdas I, Hatté C, Heaton TJ, Hogg AG, Hughen KA, Kaiser KF, Kromer B, 29 | Manning SW, Niu M, Reimer RW, Richards DA, Scott EM, Southon JR, Turney CSM, 30 | van der Plicht J. IntCal13 and MARINE13 radiocarbon age calibration curves 0-50000 years calBP. 31 | \emph{Radiocarbon} 55(4). DOI: \href{https://doi.org/10.2458/azu_js_rc.55.16947}{10.2458/azu_js_rc.55.16947} 32 | } 33 | \keyword{datasets} 34 | -------------------------------------------------------------------------------- /man/add_shaded_quantiles.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotting_functions.R 3 | \name{add_shaded_quantiles} 4 | \alias{add_shaded_quantiles} 5 | \title{Add a shaded region showing the min/max quantiles} 6 | \usage{ 7 | add_shaded_quantiles( 8 | bayesian_summary, 9 | col = grDevices::adjustcolor("grey", alpha.f = 0.5), 10 | ... 11 | ) 12 | } 13 | \arguments{ 14 | \item{bayesian_summary}{A list-like object of class 15 | \code{bd_bayesian_summary} with information on the quantiles of the density 16 | function and growth rate (see \code{summarize_bayesian_inference}).} 17 | 18 | \item{col}{The color of the shaded region (default: 19 | \code{grDevices::adjustcolor("grey",alpha.f = 0.5)}.} 20 | 21 | \item{...}{Additional parameters to pass to \code{graphics::polygon}.} 22 | } 23 | \description{ 24 | Add a shaded region showing the min/max quantiles (usually +/-2.5\%) to a 25 | plot. The input, bayesian_summary, is the result of a call to 26 | \code{summarize_bayesian_inference}, which is a list-like object of class 27 | bd_bayesian_summary with information on the quantiles of the density function 28 | and growth rate. Typically, the min/max quantiles are 2.5\% and 97.5\%, but 29 | this can be changed via the input lev in the call to 30 | \code{summarize_bayesian_inference}. 31 | } 32 | \seealso{ 33 | \code{\link[=summarize_bayesian_inference]{summarize_bayesian_inference()}} 34 | } 35 | -------------------------------------------------------------------------------- /man/calc_calib_curve_frac_modern.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/radiocarbon_functions.R 3 | \name{calc_calib_curve_frac_modern} 4 | \alias{calc_calib_curve_frac_modern} 5 | \title{Calculation the calibration curve fraction modern value for the input 6 | calendar dates.} 7 | \usage{ 8 | calc_calib_curve_frac_modern(calib_df, tau = NA, is_BP = FALSE) 9 | } 10 | \arguments{ 11 | \item{calib_df}{The calibration data frame, with columns year_BP, 12 | uncal_year_BP, and uncal_year_BP_error.} 13 | 14 | \item{tau}{The calendar dates tau (if not input, calib_df$uncal_year_BP is 15 | used).} 16 | 17 | \item{is_BP}{Whether the input dates are before present (BP), as opposed to 18 | AD (default: \code{FALSE}).} 19 | } 20 | \value{ 21 | The vector of calibration curve fraction modern values 22 | } 23 | \description{ 24 | The input calibration data frame has three columns: year_BP, uncal_year_BP, 25 | and uncal_year_BP_error. For each input calendar date, tau, use the 26 | calibration curve information to estimate the fraction modern of the 27 | calibration curve. If tau is not specified, calib_df$uncal_year_BP is used as 28 | the dates for the calculation. By default, dates are assumed to be AD (more 29 | precisely: 1950 - years BP), but this can be changed using the optional input 30 | is_BP, which is FALSE by default. 31 | } 32 | \seealso{ 33 | \code{\link[=load_calib_curve]{load_calib_curve()}} for the format of \code{calib_df}' 34 | } 35 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (https://www.contributor-covenant.org), version 1.0.0, available at 25 | https://contributor-covenant.org/version/1/0/0/. 26 | -------------------------------------------------------------------------------- /man/calc_gauss_mix_pdf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gaussian_mixture_model_functions.R 3 | \name{calc_gauss_mix_pdf} 4 | \alias{calc_gauss_mix_pdf} 5 | \title{Caculate the density of a possibly truncated Gaussian mixture} 6 | \usage{ 7 | calc_gauss_mix_pdf(th, tau, tau_min = NA, tau_max = NA, type = "density") 8 | } 9 | \arguments{ 10 | \item{th}{A vector-like object that parameterizes the distribution} 11 | 12 | \item{tau}{Vector of locations at which to calculate the density} 13 | 14 | \item{tau_min}{Minimum truncation bound} 15 | 16 | \item{tau_max}{Maximum truncation bound} 17 | 18 | \item{type}{(default density) An optional input specifying whether to 19 | calculate the density, cumulative distribution, derivative of the 20 | density, or rate} 21 | } 22 | \value{ 23 | The output vector with length G 24 | } 25 | \description{ 26 | \code{calc_gauss_mix_pdf} calculates the probability density for a possibly 27 | truncated Gaussian mixture. The density, f', and rate, f'/f, can also be 28 | calculated by specifying the input \code{type}, which is 'density' by 29 | default, but can also be 'cumulative', 'derivative', or 'rate'. The parameter 30 | vector th has the ordering (pi_k, mu_k, s_k), where pi_k, mu_k, and s_k are 31 | the weight, mean, and standard deviation of the k-th mixture. There are K 32 | total mixtures. The truncation boundaries tau_min and tau_max are optional. 33 | If provided, the density is normalized to integrate to 1 on that interval. 34 | } 35 | -------------------------------------------------------------------------------- /man/draw_rc_meas_using_date.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation_functions.R 3 | \name{draw_rc_meas_using_date} 4 | \alias{draw_rc_meas_using_date} 5 | \title{Simulate radiocarbon measurements from input calendar dates} 6 | \usage{ 7 | draw_rc_meas_using_date(t_e, calib_df, error_spec, is_AD = F) 8 | } 9 | \arguments{ 10 | \item{t_e}{A vector of event dates (calBP by default)} 11 | 12 | \item{calib_df}{The calibration dataframe, with columns year_BP, 13 | uncal_year_BP, and uncal_year_BP_error} 14 | 15 | \item{error_spec}{A list with entries type and parameter values specifying 16 | how to add uncertainty to the simulated measurement. Currently, only type = 17 | "unif_fm" is supported, for which the parameters min and max must be in 18 | error_spec.} 19 | 20 | \item{is_AD}{Whether t_e is cal_BP or AD (optional; default: \code{FALSE})} 21 | } 22 | \description{ 23 | Given input calendar dates t_e, simulate the radiocarbon measurement process 24 | to yield a fraction modern and uncertainty. error_spec is a list with named 25 | type and additional fields specifying the parameters. Currently only type 26 | unif_fm (for uniform fraction modern) is supported, which makes a uniform 27 | draw on the interval min to max for the uncertainty of the fraction modern 28 | value, where min and max are fields in error_spec giving the boundaries of 29 | the uniform draw. By default, t_e is assumed to be calBP, but can be AD (more 30 | more precisely, 1950 - BP value) if is_AD is True. 31 | } 32 | -------------------------------------------------------------------------------- /man/calc_gauss_mix_pdf_mat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gaussian_mixture_model_functions.R 3 | \name{calc_gauss_mix_pdf_mat} 4 | \alias{calc_gauss_mix_pdf_mat} 5 | \title{Calculate the density of a possibly truncated Gaussian mixture for a matrix 6 | of samples} 7 | \usage{ 8 | calc_gauss_mix_pdf_mat(TH, tau, tau_min = NA, tau_max = NA, type = "density") 9 | } 10 | \arguments{ 11 | \item{TH}{A matrix of samples with dimensions S x P} 12 | 13 | \item{tau}{A vector of points for the density calculation with length G} 14 | 15 | \item{tau_min}{(optional) The mininum time-value for truncation} 16 | 17 | \item{tau_max}{(optional) The maximum time-value for truncation} 18 | 19 | \item{type}{(optional) The type of calculation: density (default), 20 | cumulative, derivative, or rate} 21 | } 22 | \value{ 23 | The output matrix with dimensions S x G 24 | } 25 | \description{ 26 | TH is a matrix of samples of a possibly truncated Gaussian mixture with 27 | dimensions S x P, where S is the number of samples and P is the number of 28 | parameters. Repeatedly call \code{calc_gauss_mix_pdf} to calculate the 29 | density function for each sample at the points in the vector tau, which has 30 | length G. The output density matrix, f_mat, has dimensions S x G. 31 | \code{calc_gauss_mix_pdf_mat} supports the same optional inputs as 32 | \code{calc_gauss_mix_pdf}: tau_min / tau_max to specify the boundaries of 33 | truncation and type to set whether the density, cumulative distribution, 34 | derivative, or rate is calculated. 35 | } 36 | -------------------------------------------------------------------------------- /man/shcal13.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bd_data.R 3 | \docType{data} 4 | \name{shcal13} 5 | \alias{shcal13} 6 | \title{The SHCal13 Southern Hemisphere atmospheric radiocarbon calibration curve} 7 | \format{ 8 | An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 5141 rows and 5 columns. 9 | } 10 | \source{ 11 | http://www.radiocarbon.org/IntCal13/ 12 | } 13 | \usage{ 14 | shcal13 15 | } 16 | \description{ 17 | A \code{tibble::tibble} containing the SHCal13 Southern Hemisphere atmospheric radiocarbon calibration curve. 18 | } 19 | \details{ 20 | \code{shcal13} is a \link[tibble:tbl_df-class]{tibble::tbl_df} object with the following fields: 21 | \itemize{ 22 | \item \strong{CAL BP} --- The calibrated year before present 23 | \item \strong{14C age} --- The un-calibrated 14C age of the sample, in years before present 24 | \item \strong{Error} --- The measurement error of the 14C age, in years before present 25 | \item \strong{Delta 14C} --- The normalized delta 14C (Δ14C) measurement for the sample, in per mil (‰) 26 | \item \strong{Sigma} --- The standard deviation (σ) of the Δ14C measurement, in per mil (‰) 27 | } 28 | } 29 | \references{ 30 | Alan G Hogg, Quan Hua, Paul G Blackwell, Caitlin E Buck, Thomas P Guilderson, 31 | Timothy J Heaton, Mu Niu, Jonathan G Palmer, Paula J Reimer, Ron W Reimer, 32 | Christian S M Turney, Susan R H Zimmerman 33 | \emph{Radiocarbon} 55(4). DOI: \href{https://doi.org/10.2458/azu_js_rc.55.16783}{10.2458/azu_js_rc.55.16783} 34 | } 35 | \keyword{datasets} 36 | -------------------------------------------------------------------------------- /man/calc_calib_curve_equif_dates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/identifiability_functions.R 3 | \name{calc_calib_curve_equif_dates} 4 | \alias{calc_calib_curve_equif_dates} 5 | \title{Calculate equifinal dates for each point in the calibration curve} 6 | \usage{ 7 | calc_calib_curve_equif_dates(calib_df) 8 | } 9 | \arguments{ 10 | \item{calib_df}{The calibration data frame, with columns year_BP, 11 | uncal_year_BP, and uncal_year_BP_error} 12 | } 13 | \value{ 14 | A list of equifinality information for each point in the calibration 15 | curve (see details) 16 | } 17 | \description{ 18 | Calculate equifinal dates for each point in the calibration curve 19 | } 20 | \details{ 21 | The input calibration data frame has three columns: year_BP, uncal_year_BP, 22 | and uncal_year_BP_error. For each date in the column year_BP, determine all 23 | other dates with the same fraction modern. These dates are equifinal since, 24 | in the absence of additional information, there is no way to determine which 25 | year a sample came from. Typically the actual equifinal date lies between two 26 | observations in year_BP, so linear interpolation is used to estimate the 27 | decimal year. A list of length nrow(calib_df) is returned with, for each 28 | point in the calibration curve, the following information: 29 | 30 | ind_base -- The row index in calib_df of the point 31 | tau_base -- The calendar date (AD) of the point 32 | ind_equi -- The row index/indices in calib-df of the equifinal points 33 | tau_equi -- The calendar date(s) (AD) of the equifinal points 34 | } 35 | -------------------------------------------------------------------------------- /man/marine20.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bd_data.R 3 | \docType{data} 4 | \name{marine20} 5 | \alias{marine20} 6 | \title{The Marine20 calibration curve} 7 | \format{ 8 | An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 5500 rows and 5 columns. 9 | } 10 | \source{ 11 | http://intcal.org/curves/marine20.14c 12 | } 13 | \usage{ 14 | marine20 15 | } 16 | \description{ 17 | A \link[tibble:tibble]{tibble} containing the Marine20 marine radiocarbon calibration curve. 18 | } 19 | \details{ 20 | \code{marine20} is a \link[tibble:tbl_df-class]{tibble::tbl_df} object with the following fields: 21 | \itemize{ 22 | \item \strong{CAL BP} --- The calibrated year before present 23 | \item \strong{14C age} --- The un-calibrated 14C age of the sample, in years before present 24 | \item \strong{Error} --- The measurement error of the 14C age, in years before present 25 | \item \strong{Delta 14C} --- The normalized delta 14C (Δ14C) measurement for the sample, in per mil (‰) 26 | \item \strong{Sigma} --- The standard deviation (σ) of the Δ14C measurement, in per mil (‰) 27 | } 28 | } 29 | \references{ 30 | Heaton, T. J., Köhler, P., Butzin, M., Bard, E., Reimer, R. W., 31 | Austin, W. E. N., Bronk Ramsey, C., Grootes, P. M., Hughen, K. A., 32 | Kromer, B., Reimer, P. J., Adkins, J., Burke, A., Cook, M. S., 33 | Olsen, J. and Skinner, L. C. (2020) “MARINE20—THE MARINE RADIOCARBON AGE 34 | CALIBRATION CURVE (0–55,000 CAL BP),” Radiocarbon. Cambridge University 35 | Press, pp. 1–42. DOI: \href{https://doi.org/10.1017/RDC.2020.68}{10.1017/RDC.2020.68} 36 | } 37 | \keyword{datasets} 38 | -------------------------------------------------------------------------------- /man/shcal20.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bd_data.R 3 | \docType{data} 4 | \name{shcal20} 5 | \alias{shcal20} 6 | \title{The SHCal20 Southern Hemisphere atmospheric radiocarbon calibration curve} 7 | \format{ 8 | An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 9500 rows and 5 columns. 9 | } 10 | \source{ 11 | http://intcal.org/curves/shcal20.14c 12 | } 13 | \usage{ 14 | shcal20 15 | } 16 | \description{ 17 | A \code{tibble::tibble} containing the SHCal20 Southern Hemisphere 18 | atmospheric radiocarbon calibration curve. 19 | } 20 | \details{ 21 | \code{shcal20} is a \link[tibble:tbl_df-class]{tibble::tbl_df} object with the following fields: 22 | \itemize{ 23 | \item \strong{CAL BP} --- The calibrated year before present 24 | \item \strong{14C age} --- The un-calibrated 14C age of the sample, in years before present 25 | \item \strong{Error} --- The measurement error of the 14C age, in years before present 26 | \item \strong{Delta 14C} --- The normalized delta 14C (Δ14C) measurement for the sample, in per mil (‰) 27 | \item \strong{Sigma} --- The standard deviation (σ) of the Δ14C measurement, in per mil (‰) 28 | } 29 | } 30 | \references{ 31 | Hogg, A. G., Heaton, T. J., Hua, Q., Palmer, J. G., Turney, C. S. M., 32 | Southon, J., Bayliss, A., Blackwell, P. G., Boswijk, G., Bronk Ramsey, C., 33 | Pearson, C., Petchey, F., Reimer, P., Reimer, R. and Wacker, L. (2020) 34 | “SHCal20 SOUTHERN HEMISPHERE CALIBRATION, 0–55,000 YEARS CAL BP,” 35 | Radiocarbon. Cambridge University Press, pp. 1–20. 36 | DOI: \href{https://doi.org/10.1017/RDC.2020.59}{10.1017/RDC.2020.59} 37 | } 38 | \keyword{datasets} 39 | -------------------------------------------------------------------------------- /man/calc_tau_range.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_io_functions.R 3 | \name{calc_tau_range} 4 | \alias{calc_tau_range} 5 | \title{Calculate a calendar date range that spans the input radiocarbon measurements} 6 | \usage{ 7 | calc_tau_range(rc_meas, calibration_curve = "intcal20", dtau = 1) 8 | } 9 | \arguments{ 10 | \item{rc_meas}{The radiocarbon measurements (see import_rc_data for the 11 | expected format)} 12 | 13 | \item{calibration_curve}{The name of the calibration curve to use (default: 14 | intcal20)} 15 | 16 | \item{dtau}{An integer to round to in extending the calendar range on either 17 | end (default: 1, which has no effect)} 18 | } 19 | \value{ 20 | A list containing the minimum and maximum calendar dates, tau_min and 21 | tau_max 22 | } 23 | \description{ 24 | To determine the calendar dates, first Bchron::BchronCalibrate is called to 25 | calibrate the individual dates, which yields a date range for each date. The 26 | maximum range across dates is identified (BchronCalibrate adopts a spacing of 27 | one year), then (if necessary) the range is slightly extended to multiples of 28 | dtau. If intcal20 is being used, dtau should likely be 5, since that is the 29 | spacing at which the calibration curve is specified. If dtau is not an 30 | integer, it is ignored and a warning is thrown. If dtau is 1 (the default), 31 | no rounding is done since that is already the spacing returned by Bchron. 32 | } 33 | \seealso{ 34 | \itemize{ 35 | \item \code{\link[=set_sim]{set_sim()}} for an overview of the "standard pipeline" 36 | \item \code{\link[=import_rc_data]{import_rc_data()}} for the format of \code{rc_meas}' 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /man/marine13.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bd_data.R 3 | \docType{data} 4 | \name{marine13} 5 | \alias{marine13} 6 | \title{The Marine13 calibration curve} 7 | \format{ 8 | An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 4801 rows and 5 columns. 9 | } 10 | \source{ 11 | http://www.radiocarbon.org/IntCal13/ 12 | } 13 | \usage{ 14 | marine13 15 | } 16 | \description{ 17 | A \link[tibble:tibble]{tibble} containing the Marine13 marine radiocarbon calibration curve. 18 | } 19 | \details{ 20 | \code{marine13} is a \link[tibble:tbl_df-class]{tibble::tbl_df} object with the following fields: 21 | \itemize{ 22 | \item \strong{CAL BP} --- The calibrated year before present 23 | \item \strong{14C age} --- The un-calibrated 14C age of the sample, in years before present 24 | \item \strong{Error} --- The measurement error of the 14C age, in years before present 25 | \item \strong{Delta 14C} --- The normalized delta 14C (Δ14C) measurement for the sample, in per mil (‰) 26 | \item \strong{Sigma} --- The standard deviation (σ) of the Δ14C measurement, in per mil (‰) 27 | } 28 | } 29 | \references{ 30 | Reimer PJ, Bard E, Bayliss A, Beck JW, Blackwell PG, Bronk Ramsey C, Buck CE, 31 | Cheng H, Edwards RL, Friedrich M, Grootes PM, Guilderson TP, Haflidason H, 32 | Hajdas I, Hatté C, Heaton TJ, Hogg AG, Hughen KA, Kaiser KF, Kromer B, 33 | Manning SW, Niu M, Reimer RW, Richards DA, Scott EM, Southon JR, Turney CSM, 34 | van der Plicht J. IntCal13 and MARINE13 radiocarbon age calibration curves 0-50000 years calBP. 35 | \emph{Radiocarbon} 55(4). DOI: \href{https://doi.org/10.2458/azu_js_rc.55.16947}{10.2458/azu_js_rc.55.16947} 36 | } 37 | \keyword{datasets} 38 | -------------------------------------------------------------------------------- /man/intcal13.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bd_data.R 3 | \docType{data} 4 | \name{intcal13} 5 | \alias{intcal13} 6 | \title{The IntCal13 calibration curve} 7 | \format{ 8 | An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 5141 rows and 5 columns. 9 | } 10 | \source{ 11 | http://www.radiocarbon.org/IntCal13/ 12 | } 13 | \usage{ 14 | intcal13 15 | } 16 | \description{ 17 | A \link[tibble:tibble]{tibble} containing the IntCal13 Northern Hemisphere 18 | atmospheric radiocarbon calibration curve. 19 | } 20 | \details{ 21 | \code{intcal13} is a \link[tibble:tbl_df-class]{tibble::tbl_df} object with the following fields: 22 | \itemize{ 23 | \item \strong{CAL BP} --- The calibrated year before present 24 | \item \strong{14C age} --- The un-calibrated 14C age of the sample, in years before present 25 | \item \strong{Error} --- The measurement error of the 14C age, in years before present 26 | \item \strong{Delta 14C} --- The normalized delta 14C (Δ14C) measurement for the sample, in per mil (‰) 27 | \item \strong{Sigma} --- The standard deviation (σ) of the Δ14C measurement, in per mil (‰) 28 | } 29 | } 30 | \references{ 31 | Reimer PJ, Bard E, Bayliss A, Beck JW, Blackwell PG, Bronk Ramsey C, Buck CE, 32 | Cheng H, Edwards RL, Friedrich M, Grootes PM, Guilderson TP, Haflidason H, 33 | Hajdas I, Hatté C, Heaton TJ, Hogg AG, Hughen KA, Kaiser KF, Kromer B, 34 | Manning SW, Niu M, Reimer RW, Richards DA, Scott EM, Southon JR, Turney CSM, 35 | van der Plicht J. IntCal13 and MARINE13 radiocarbon age calibration curves 0-50000 years calBP. 36 | \emph{Radiocarbon} 55(4). DOI: \href{https://doi.org/10.2458/azu_js_rc.55.16947}{10.2458/azu_js_rc.55.16947} 37 | } 38 | \keyword{datasets} 39 | -------------------------------------------------------------------------------- /man/intcal20_raw.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bd_data.R 3 | \docType{data} 4 | \name{intcal20_raw} 5 | \alias{intcal20_raw} 6 | \title{The raw data for constructing the IntCal20 calibration curve} 7 | \format{ 8 | An object of class \code{list} of length 4. 9 | } 10 | \source{ 11 | http://intcal.org/JS/JSintcal20/query/query.php 12 | } 13 | \usage{ 14 | intcal20_raw 15 | } 16 | \description{ 17 | A \code{base::list} of \code{tibble::tibble} objects containing the data for 18 | calculating the IntCal20 Northern Hemisphere 19 | atmospheric radiocarbon calibration curve. 20 | } 21 | \details{ 22 | These data are as available from the IntCal webservice 23 | hosted at Queen's University, Belfast. 24 | Details on the structure of the data can be found at 25 | \url{http://intcal.org/JS/JSintcal20/query/}. 26 | } 27 | \references{ 28 | Reimer, P. J., Austin, W. E. N., Bard, E., Bayliss, A., Blackwell, P. G., 29 | Bronk Ramsey, C., Butzin, M., Cheng, H., Edwards, R. L., Friedrich, M., 30 | Grootes, P. M., Guilderson, T. P., Hajdas, I., Heaton, T. J., Hogg, A. G., 31 | Hughen, K. A., Kromer, B., Manning, S. W., Muscheler, R., Palmer, J. G., 32 | Pearson, C., van der Plicht, J., Reimer, R. W., Richards, D. A., 33 | Scott, E. M., Southon, J. R., Turney, C. S. M., Wacker, L., Adolphi, F., 34 | Büntgen, U., Capano, M., Fahrni, S. M., Fogtmann-Schulz, A., Friedrich, R., 35 | Köhler, P., Kudsk, S., Miyake, F., Olsen, J., Reinig, F., Sakamoto, M., 36 | Sookdeo, A. and Talamo, S. (2020) “THE INTCAL20 NORTHERN HEMISPHERE 37 | RADIOCARBON AGE CALIBRATION CURVE (0–55 CAL kBP),” Radiocarbon. 38 | Cambridge University Press, pp. 1–33. 39 | DOI: \href{https://doi.org/10.1017/RDC.2020.41}{10.1017/RDC.2020.41} 40 | } 41 | \keyword{datasets} 42 | -------------------------------------------------------------------------------- /man/init_trunc_gauss_mix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/max_lik_fitting_functions.R 3 | \name{init_trunc_gauss_mix} 4 | \alias{init_trunc_gauss_mix} 5 | \title{Do random number draws to initialize a truncated Gaussian mixture} 6 | \usage{ 7 | init_trunc_gauss_mix( 8 | K, 9 | num_draws, 10 | tau_min, 11 | tau_max, 12 | s_min = 0, 13 | input_seed = NA 14 | ) 15 | } 16 | \arguments{ 17 | \item{K}{The number of mixture components} 18 | 19 | \item{num_draws}{The number of draws to make (if more than one, a matrix is 20 | returned rather than a vector)} 21 | 22 | \item{tau_min}{The minimum calendar date (AD) for the sampling grid} 23 | 24 | \item{tau_max}{The maximum calendar date (AD) for the sampling grid} 25 | 26 | \item{s_min}{The minimum value for the mixture standard deviations (default: 27 | 0)} 28 | 29 | \item{input_seed}{A single integer for initializing the random number seed 30 | prior to making draws (default: NA, no seed set)} 31 | } 32 | \value{ 33 | A matrix of parameter vectors with dimensions 3\emph{K by num_draws. If 34 | \code{num_draws=1}, a vector with length 3}K is returned rather than a matrix. 35 | } 36 | \description{ 37 | Do random number draws to initialize a truncated Gaussian mixture 38 | } 39 | \details{ 40 | The parameter vector, theta (th), has the ordering 41 | th = (pi_1,...,pi_K,mu_1,..mu_K,s_1,...s_K), where K is the number of 42 | mixture components and pi_k / mu_k / s_k are, respectively, the weighting / 43 | mean / standard deviation of the k-th mixture. The mixture proportions are 44 | drawn from a Dirichlet distribution with \code{rep(1,K)} used for the dispersion 45 | parameter. The means are drawn from a uniform distribution on the interval 46 | tau_min to tau_max. The standard deviations are drawn from a uniform 47 | distribution on the interval s_min to tau_max - tau_min. By default, s_min is 48 | 0. 49 | } 50 | -------------------------------------------------------------------------------- /man/set_density_model.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_io_functions.R 3 | \name{set_density_model} 4 | \alias{set_density_model} 5 | \title{Set the density model (density_model) for an analysis} 6 | \usage{ 7 | set_density_model(data_dir, analysis_name, density_model) 8 | } 9 | \arguments{ 10 | \item{data_dir}{The directory in which to store analysis data} 11 | 12 | \item{analysis_name}{A unique name for a given analysis in data_dir} 13 | 14 | \item{density_model}{A list object specifying the density model} 15 | } 16 | \description{ 17 | This is one of a set of helper functions for undertaking a typical analysis 18 | of radiocarbon dates. For details on the overall framework for these helper 19 | function, see set_rc_meas. 20 | 21 | set_density_model sets the parametric model to use for the density function 22 | assumed to give rise to the set of radiocarbon dates (rc_meas). The input 23 | variable density_model is a list in which the field "type" specifies the 24 | type of parametric model and additional named fields are type-specific. 25 | Currently, only one type is supported: "trunc_gauss_mix", which stands for 26 | truncated Gaussian mixture. For type = "trunc_gauss_mix", the following 27 | named fields must also be specified in density_model: 28 | 29 | tau_min The minimum calendar year for truncation (in AD or, more precisely, 30 | 1950 - years BP) 31 | tau_max The maximum calendar year for truncation (in AD or, more precisely, 32 | 1950 - years BP) 33 | K The number of mixture components. K must be an integer greater than 34 | or equal to 2, and can further be a vector of such integers rather 35 | than a single integer (a vector should be specified if model 36 | selection on the number of mixtures will subsequently be done) 37 | and can be a vector 38 | } 39 | \seealso{ 40 | \code{\link[=set_sim]{set_sim()}} for an overview of the "standard pipeline" 41 | } 42 | -------------------------------------------------------------------------------- /inst/stan/gaussmix.stan: -------------------------------------------------------------------------------- 1 | functions { 2 | row_vector calc_logh(int N, int G, int K, vector pi, vector s, vector mu, vector tau, real dtau, matrix Mt) { 3 | row_vector[N] h; 4 | row_vector[N] logh; 5 | row_vector[G] f; 6 | row_vector[G] logf; 7 | vector[K] logpi = log(pi); 8 | 9 | logf = to_row_vector(rep_vector(0,G)); 10 | for (g in 1:G) { 11 | vector[K] lse = logpi; 12 | for (k in 1:K) { 13 | lse[k] += normal_lpdf(tau[g]|mu[k],s[k]); 14 | } 15 | logf[g] = log_sum_exp(lse); 16 | } 17 | f = exp(logf); 18 | 19 | // The following line truncates the distribution by normalizing the density to 20 | // integrate to 1 on the interval of tau, which is assumed to run from tau_min 21 | // to tau_max. 22 | f = f / sum(f) / dtau; 23 | h = f * Mt; 24 | logh = log(h); 25 | return logh; 26 | } 27 | } 28 | 29 | data { 30 | int N; // Number of observations 31 | int G; // Number of grid pints 32 | int K; // Number of mixtures 33 | matrix[G,N] Mt; // Measurement matrix (transposed) 34 | vector[G] tau; // Calendar grid points for the measurement matrix calculation 35 | real dtau; // Grid spacing (not error checked for consistency with tau) 36 | real alpha_d; // Concentration parameter for pi prior 37 | real tau_min; // Lower calendar date. Same as min(tau) 38 | real tau_max; // Upper calendar date. Same as max(tau) 39 | real alpha_s; // shape parameter of gamma distribution for s 40 | real alpha_r; // rate parameter of gamma distribution for s 41 | } 42 | 43 | parameters { 44 | simplex[K] pi; 45 | ordered[K] mu; 46 | vector[K] s; 47 | } 48 | 49 | transformed parameters { 50 | row_vector[N] logh; 51 | logh = calc_logh(N, G, K, pi, s, mu, tau, dtau, Mt); 52 | } 53 | 54 | model { 55 | pi ~ dirichlet(rep_vector(alpha_d,K)); 56 | s ~ gamma(alpha_s,alpha_r); 57 | mu ~ uniform(tau_min,tau_max); 58 | target += sum(logh); 59 | } 60 | -------------------------------------------------------------------------------- /man/import_rc_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_io_functions.R 3 | \name{import_rc_data} 4 | \alias{import_rc_data} 5 | \title{Import radiocarbon data from a .csv file} 6 | \usage{ 7 | import_rc_data( 8 | file_name, 9 | trc_m_col = NA, 10 | sig_trc_m_col = NA, 11 | phi_m_col = NA, 12 | sig_m_col = NA, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{file_name}{The file name of the input .csv file (or full path to the 18 | file if not located in the current directory)} 19 | 20 | \item{trc_m_col}{The column containing the radiocarbon years values 21 | (optional, but see details).} 22 | 23 | \item{phi_m_col}{The column containing the fraction modern values (optional, 24 | but see details).} 25 | 26 | \item{sig_m_col}{The column containing the error for the radiocarbon year 27 | values (optional, but see details)} 28 | 29 | \item{...}{Additional arguments to pass to read.csv (e.g., skip=2 would skip 30 | the first two lines when reading the .csv file)} 31 | } 32 | \value{ 33 | A list with four named entries, each a vector equal to the number of 34 | samples: phi_m, the fraction modern values; sig_m, the error for phi_m; 35 | trc_m, a vector of uncalibrated radiocarbon years; and sig_trc_m, the error 36 | for trc_m. 37 | } 38 | \description{ 39 | Use read.csv to load the file specified by the input file_name (file_name can 40 | also be the full path to the file). The inputs phi_m_col, sig_m_col, 41 | trc_m_col, and sig_trc_m_col specify which columns contain the radiocarbon 42 | data. All are optional, but only three patterns of inputs are valid: 43 | 44 | (1) If none of the column specifiers are given, it is assumed that the first 45 | column in the .csv file contains trc_m and the second column contains 46 | sig_trc_m. 47 | (2) If trc_m_col and sig_trc_m_col are given, phi_m_col and sig_m_col 48 | must not be given. 49 | (3) If phi_m_col and sig_m_col are given, trc_m_col and sig_trc_m_col must 50 | not be given. 51 | } 52 | -------------------------------------------------------------------------------- /man/intcal20.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bd_data.R 3 | \docType{data} 4 | \name{intcal20} 5 | \alias{intcal20} 6 | \title{The IntCal20 calibration curve} 7 | \format{ 8 | An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 9500 rows and 5 columns. 9 | } 10 | \source{ 11 | http://intcal.org/curves/intcal20.14c 12 | } 13 | \usage{ 14 | intcal20 15 | } 16 | \description{ 17 | A \link[tibble:tibble]{tibble} containing the IntCal20 Northern Hemisphere 18 | atmospheric radiocarbon calibration curve. 19 | } 20 | \details{ 21 | \code{intcal20} is a \link[tibble:tbl_df-class]{tibble::tbl_df} object with the following fields: 22 | \itemize{ 23 | \item \strong{CAL BP} --- The calibrated year before present 24 | \item \strong{14C age} --- The un-calibrated 14C age of the sample, in years before present 25 | \item \strong{Error} --- The measurement error of the 14C age, in years before present 26 | \item \strong{Delta 14C} --- The normalized delta 14C (Δ14C) measurement for the sample, in per mil (‰) 27 | \item \strong{Sigma} --- The standard deviation (σ) of the Δ14C measurement, in per mil (‰) 28 | } 29 | } 30 | \references{ 31 | Reimer, P. J., Austin, W. E. N., Bard, E., Bayliss, A., Blackwell, P. G., 32 | Bronk Ramsey, C., Butzin, M., Cheng, H., Edwards, R. L., Friedrich, M., 33 | Grootes, P. M., Guilderson, T. P., Hajdas, I., Heaton, T. J., Hogg, A. G., 34 | Hughen, K. A., Kromer, B., Manning, S. W., Muscheler, R., Palmer, J. G., 35 | Pearson, C., van der Plicht, J., Reimer, R. W., Richards, D. A., 36 | Scott, E. M., Southon, J. R., Turney, C. S. M., Wacker, L., Adolphi, F., 37 | Büntgen, U., Capano, M., Fahrni, S. M., Fogtmann-Schulz, A., Friedrich, R., 38 | Köhler, P., Kudsk, S., Miyake, F., Olsen, J., Reinig, F., Sakamoto, M., 39 | Sookdeo, A. and Talamo, S. (2020) “THE INTCAL20 NORTHERN HEMISPHERE 40 | RADIOCARBON AGE CALIBRATION CURVE (0–55 CAL kBP),” Radiocarbon. 41 | Cambridge University Press, pp. 1–33. 42 | DOI: \href{https://doi.org/10.1017/RDC.2020.41}{10.1017/RDC.2020.41} 43 | } 44 | \keyword{datasets} 45 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /man/calc_meas_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/radiocarbon_functions.R 3 | \name{calc_meas_matrix} 4 | \alias{calc_meas_matrix} 5 | \title{Calculate the measurement matrix given N observations and G grid points} 6 | \usage{ 7 | calc_meas_matrix( 8 | tau, 9 | phi_m, 10 | sig_m, 11 | calib_df, 12 | add_calib_unc = T, 13 | use_trapez = F 14 | ) 15 | } 16 | \arguments{ 17 | \item{tau}{A vector of calendar dates indexed by g} 18 | 19 | \item{phi_m}{A vector of fraction moderns indexed by i} 20 | 21 | \item{sig_m}{A vector of standard deviations for phi_m indexed by i} 22 | 23 | \item{calib_df}{Calibration curve (see load_calib_curve)} 24 | 25 | \item{add_calib_unc}{Whether to add calibration uncertainty (default: \code{TRUE})} 26 | 27 | \item{use_trapez}{Whether to use the trapezoidal rule for integration 28 | (default: \code{FALSE})} 29 | } 30 | \value{ 31 | The measurement matrix, which has dimensions N x G 32 | } 33 | \description{ 34 | tau is a vector of calendar dates indexed from g = 1,2,...,G. phi_m is a 35 | vector of n = 1,2,...,N radiocarbon determinations (fraction modern) with 36 | associated uncertainties sig_m. Calculate the measurement matrix M, which 37 | has dimensions N x G and for which each element is M_ig = p(phi_m,i|tau_g). 38 | The total uncertainty of the measurement comes from measurement error (SIG_M, 39 | calculated using the measurement error for each measurement) and the 40 | calibration curve error (SIG_c, calculated using the uncertainty for the 41 | calibration curve at each grid point). These uncertainties (and the 42 | associated measurements) should already be "projected" to 1950 equivalents. 43 | By default the measurement matrix, M, is multiplied by dtau so that M * f is 44 | an approximation to the integral over p(t|th) * p(phi|t) using a Riemann sum 45 | with the density calculated at the points tau and the width for each point 46 | being dtau. Alternatively, the trapezoidal rule can be used (for details see 47 | calc_trapez_weights). If the spacing of tau is irregular, the trapezoidal 48 | rule must be used. An error is thrown if tau is irregularly spaced and the 49 | trapezoidal rule is not used 50 | } 51 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Steps to clone the baydem github repository and run the baydem tests inside 2 | # a Docker container. Really, the only reason the first clone command is needed 3 | # is to obtain this Dockerfile and setup.R. When running the Docker container, 4 | # a mirrored directory is used, which is not necessary for just running the 5 | # tests, but is usually necessary for running analyses. Modify the Docker 6 | # commands to fit your situation. 7 | # 8 | # git clone https://github.com/eehh-stanford/baydem 9 | # cd baydem 10 | # docker build -t michaelholtonprice/baydem . 11 | # docker run --name baydem -itv //c/mirrored_baydem_data:/data michaelholtonprice/baydem 12 | # git clone https://github.com/eehh-stanford/baydem 13 | # cd baydem 14 | # R 15 | # library(devtools) 16 | # test() 17 | 18 | FROM ubuntu:20.04 19 | 20 | # Set the following environmental variable to avoid interactively setting the 21 | # timezone with tzdata when installing R 22 | ENV DEBIAN_FRONTEND=noninteractive 23 | 24 | # Install R version 4 25 | RUN apt-get update && \ 26 | apt-get install -y gnupg2 &&\ 27 | apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 && \ 28 | apt-get install -y software-properties-common && \ 29 | add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/' && \ 30 | apt-get update && \ 31 | apt-get install -y r-base &&\ 32 | apt-get install -y vim && \ 33 | apt-get install -y git && \ 34 | # apt-get install apt-transport-https && \ 35 | # apt-get install software-properties-common && \ 36 | apt-get clean 37 | 38 | # Install the tools needed for subsequent R package installations 39 | RUN apt-get install -y libssl-dev && \ 40 | apt-get install -y libxml2-dev && \ 41 | apt-get install -y libcurl4-openssl-dev && \ 42 | apt-get install -y libfontconfig1-dev && \ 43 | apt-get install -y libharfbuzz-dev && \ 44 | apt-get install -y libfribidi-dev && \ 45 | apt-get install -y libfreetype6-dev && \ 46 | apt-get install -y libpng-dev && \ 47 | apt-get install -y libtiff5-dev && \ 48 | apt-get install -y libjpeg-dev && \ 49 | apt-get install -y libv8-dev 50 | 51 | # The following line can be copied at the command line to install the preceding 52 | # requirements: 53 | # sudo apt-get install libssl-dev libxml2-dev libcurl4-openssl-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev libv8-dev 54 | 55 | COPY setup.R . 56 | RUN Rscript setup.R 57 | 58 | -------------------------------------------------------------------------------- /tests/testthat/test-function.R: -------------------------------------------------------------------------------- 1 | # Functional tests for baydem functions. These tests are slow and should 2 | # primarily be run before pushing updates back to github. 3 | 4 | # Use multiple cores to speed up processing. Always reserve two cores that are 5 | # not used. 6 | cores_to_use <- parallel::detectCores() - 2 7 | 8 | # ------------------------------------------------------------------------------ 9 | # (1) Do functional tests for maximum likelihood fitting 10 | # 11 | # ------------------------------------------------------------------------------ 12 | 13 | # Simulate a (truncated) Gaussian mixture with N=20000 samples and ensure that 14 | # the original simulation parameter vector is recovered with the maximum 15 | # likelihood fit. Do this num_sims=4 times with a tolerance on the relative 16 | # error of 2%. 17 | 18 | N <- 20000 19 | maximum_relative_error <- rep(.02,6) 20 | 21 | th_sim <- 22 | c( 23 | pi1 = 0.4, 24 | pi2 = 0.6, 25 | mu1 = 1000, 26 | mu2 = 1250, 27 | s1 = 45, 28 | s2 = 35 29 | ) 30 | 31 | tau_min <- 700 32 | tau_max <- 1500 33 | dtau <- 1 34 | tau <- seq(tau_min,tau_max,by=dtau) 35 | 36 | calib_df <- load_calib_curve("intcal20") 37 | 38 | # Explicitly create a vector of random seeds for the simulations 39 | set.seed(135066) 40 | num_sims <- 4 41 | seed_vect <- sample.int(1000000,4) 42 | 43 | for(n_s in 1:num_sims) { 44 | sim_spec <- list(model_spec= 45 | list(density_type = "trunc_gauss_mix", 46 | th=c(th_sim,tau_min,tau_max), 47 | error_spec=list(type="unif_fm",min=.0021,max=.0028), 48 | is_AD=T), 49 | N=N, 50 | calib_curve="intcal20", 51 | seed=seed_vect[n_s]) 52 | sim <- simulate_rc_data(sim_spec) 53 | expect_error( 54 | max_lik_fit <- fit_trunc_gauss_mix(2, 55 | sim$data$rc_meas$phi_m, 56 | sim$data$rc_meas$sig_m, 57 | tau_min, 58 | tau_max, 59 | 1, 60 | calib_df, 61 | num_restarts=20, 62 | maxfeval=10000, 63 | num_cores=cores_to_use), 64 | NA 65 | ) 66 | relative_error <- (max_lik_fit$th - th_sim)/th_sim 67 | expect_equal( 68 | all(abs(relative_error) <= maximum_relative_error), 69 | TRUE 70 | ) 71 | # Make sure memory is free by doing garbage collection 72 | dummy <- gc(verbose=F) 73 | } 74 | -------------------------------------------------------------------------------- /man/calc_half_life_from_peak.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bayesian_inference_functions.R 3 | \name{calc_half_life_from_peak} 4 | \alias{calc_half_life_from_peak} 5 | \title{For each sample, calculate the time it takes for the density to decrease by 6 | half from the peak (or by another use-provided ratio)} 7 | \usage{ 8 | calc_half_life_from_peak( 9 | bayesian_soln, 10 | density_model, 11 | rc_meas = list(), 12 | calib_df = list(), 13 | prop_change = 0.5, 14 | bayesian_summary = NA, 15 | peak_range = NA 16 | ) 17 | } 18 | \arguments{ 19 | \item{bayesian_soln}{The solution, a list-like object of class 20 | bd_bayesian_soln (see sample_theta).} 21 | 22 | \item{density_model}{The density model (see set_density_model).} 23 | 24 | \item{rc_meas}{The radiocarbon measurements (see import_rc_data; optional: 25 | if not provided, bayesian_summary must be provided).} 26 | 27 | \item{calib_df}{The calibration data frame (see load_calib_curve; optional: 28 | if not provided, bayesian_summary must be provided).} 29 | 30 | \item{prop_change}{The relative decrease in density to use for the duration 31 | calculation (default: 0.5).} 32 | 33 | \item{bayesian_summary}{The result of a call to summarize_bayesian_inference. 34 | (optional; if not provided, it is calculated, which requires that rc_meas 35 | and calib_df be provided).} 36 | 37 | \item{peak_range}{A range over which to search for the peak of the density 38 | function (default: NA, which means that tau_min to tau_max is used for the 39 | range).} 40 | } 41 | \value{ 42 | A vector of "half-lives" (proportional change set by prop_change) 43 | } 44 | \description{ 45 | For each sample, calculate the time it takes for the density to decrease by 46 | half from the peak (or by another use-provided ratio) 47 | } 48 | \details{ 49 | For each sample, calculate the time it takes for the density to decrease by 50 | half from the peak. Optionally, a different proportion can be used than the 51 | default prop_change = 0.5. For example, with prop_change = 0.1 the time it 52 | takes for the density to decrease by 10\% is used. If the relative density is 53 | not reached, the half life for the sample is set to NA. If there is no 54 | interior peak in the range peak_range, which is tau_min to tau_max by 55 | default, the half life is set to NA. 56 | } 57 | \seealso{ 58 | \itemize{ 59 | \item \code{\link[=import_rc_data]{import_rc_data()}} for the format of \code{rc_meas} 60 | \item \code{\link[=set_density_model]{set_density_model()}} for the format of \code{density_model} 61 | \item \code{\link[=load_calib_curve]{load_calib_curve()}} for the format of \code{calib_df} 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /man/do_bayesian_inference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_io_functions.R 3 | \name{do_bayesian_inference} 4 | \alias{do_bayesian_inference} 5 | \title{Do Bayesian inference given a set of radiocarbon measurements (rc_meas) and 6 | a density model (density_model).} 7 | \usage{ 8 | do_bayesian_inference( 9 | data_dir, 10 | analysis_name, 11 | hp, 12 | input_seed = NA, 13 | control = list() 14 | ) 15 | } 16 | \arguments{ 17 | \item{data_dir}{The directory in which to store analysis data.} 18 | 19 | \item{analysis_name}{A unique name for a given analysis in data_dir.} 20 | 21 | \item{hp}{Hyperparameters for the priors and to specify the spacing of the 22 | Riemann sum that approximates the integral for the likelihood (see 23 | sample_theta).} 24 | 25 | \item{input_seed}{An optional seed that can be used to make results 26 | reproducible. The input_seed must be either (1) NA / not provided (the 27 | default), (2) a single integer, or (3) a matrix with dimensions 28 | \code{num_models} by 2 (see description for further details).} 29 | 30 | \item{Control}{arguments to pass to the Bayesian inference function (see 31 | sample_theta).} 32 | } 33 | \description{ 34 | This is one of a set of helper functions for undertaking a typical analysis 35 | of radiocarbon dates. For details on the overall framework for these helper 36 | function, see set_rc_meas. 37 | 38 | #' To ensure reproducibility, the input seed can be provided. The input seed 39 | should either be (1) NA \link{the default}, (2) a single integer, or (3) a matrix 40 | with dimensions \code{num_models} by 2, where 41 | \code{num_models = length(analysis$density_model$K)}. If no seed is provided, one 42 | is drawn and treated as if it (a single integer) was input. If a single 43 | integer is provided, it is used to generate a matrix of integers with 44 | dimensions \code{num_models} by 2. The first column of the matrix provides the 45 | seeds for initializing the parameter vector and the second column provides 46 | the seeds for stan. 47 | 48 | The best model is identified based on the Pareto smoothed importance 49 | sampling (PSIS) approximation of the leave-one-out (loo) cross-validation 50 | (CV), PSIS-LOO CV (just loo in the code). The corresponding index (in 51 | density_model$K) and K-value are stored in, respectively, m_K_best and 52 | K_best (currently, only a truncated Gaussian mixture is supported for the 53 | density model specification). The vector of loo values is stored in 54 | loo_vect. The model with the highest loo is prefered. WAIC values are also 55 | calculated and stored in waic_vect. 56 | } 57 | \seealso{ 58 | \code{\link[=set_sim]{set_sim()}} for an overview of the "standard pipeline" 59 | } 60 | -------------------------------------------------------------------------------- /man/assess_calib_curve_equif.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/identifiability_functions.R 3 | \name{assess_calib_curve_equif} 4 | \alias{assess_calib_curve_equif} 5 | \title{Assess the equifinality or time spans in the input radiocarbon 6 | calibration curve} 7 | \usage{ 8 | assess_calib_curve_equif(calib_df, equi_list = NA) 9 | } 10 | \arguments{ 11 | \item{calib_df}{The calibration data frame, with columns year_BP, 12 | uncal_year_BP, and uncal_year_BP_error} 13 | 14 | \item{equi_list}{(Optional) The result of a call to 15 | calc_calib_curve_equif_dates} 16 | } 17 | \value{ 18 | A list of with named variables can_invert and inv_span_list (see 19 | details) 20 | } 21 | \description{ 22 | Assess the equifinality or time spans in the input radiocarbon 23 | calibration curve 24 | } 25 | \details{ 26 | The input calibration data frame has three columns: year_BP, uncal_year_BP, 27 | and uncal_year_BP_error. A time span is equifinal if, for each date in the 28 | span, there is at least one other date in the radiocarbon calibration curve 29 | with the same fraction modern value. Conversely, a time span is not equifinal 30 | if this is not true (all dates in the time span correspond to a unique 31 | fraction modern value). Thus, the calibration curve is divided into 32 | alternating equifinal and non-equifinal spans. This function identifies these 33 | regions for the input calibration data frame, calib_df. 34 | 35 | Although calib_df uses year BP, all calculations and returned data use AD. 36 | 37 | A list is returned with two named variables: can_invert and inv_span_list 38 | (inv = invert, which is conceptually identical to non-equifinal). 39 | 40 | can_invert is a boolean that indicates whether each entry (row) in the 41 | calibration data frame, calib_df, is inside or outside an invertible region. 42 | 43 | inv_span_list is a list summarizing information about all the invertible 44 | (non-equifinal) time spans. It contains the following named variables: 45 | 46 | ind -- Indices (rows) of calib_df following within the invertible time 47 | span 48 | tau_left -- Calendar date (AD) of the left (earlier) boundary of the 49 | invertible time span 50 | phi_left -- Fraction modern value of the left (earlier) boundary of the 51 | invertible time span 52 | tau_right -- Calendar date (AD) of the right (later) boundary of the 53 | invertible time span 54 | phi_right -- Fraction modern value of the right (later) boundary of the 55 | invertible time span 56 | ii_prev -- The index (row) of the calib_df earlier than the invertible 57 | region with closest fraction modern value 58 | ii_next -- The index (row) of the calib_df later than the invertible 59 | region with closest fraction modern value 60 | } 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # baydem 2 | The R package baydem (for bayESIAN demOGRAPHY) provides tools for reconstructing past and present demography. 3 | 4 | # Quickstart 5 | Use of the two options below to install baydem and its dependencies, then read the vignette for the standard pipeline: 6 | 7 | TODO: add vignettte link 8 | 9 | # Installation 10 | There are two options for installing and using the package: 11 | 12 | (1) Install on an existing computer with necessary dependencies 13 | (2) Build a Docker image using the Dockerfile 14 | 15 | ## Option 1: Install on an existing computer with necessary dependencies 16 | Details will vary based on the machine and operating system since certain R packages on which baydem depends require the installation of tools outside R. The following should be sufficient: 17 | 18 | (a) Install devtools with its dependencies 19 | https://www.rdocumentation.org/packages/devtools 20 | 21 | (b) Install rstan with its dependencies 22 | http://mc-stan.org/rstan/ 23 | 24 | (c) Install baydem 25 | 26 | Having completed the preceding steps, install baydem with the following commands in R: 27 | 28 | ```bash 29 | library(devtools) 30 | install_github("eehh-stanford/baydem") 31 | ``` 32 | 33 | ## Option 2: Build a Docker image using the Dockerfile 34 | First, clone the database and build the Docker image (rather than cloning the entire directory, one can also just download Dockerfile and setup.R from the github repository and place them in the working directory). 35 | 36 | To force all docker material to be (re)downloaded prior to creating the Docker image -- a step you should be certain you want to take -- use: "docker system prune -a" 37 | 38 | ```bash 39 | git clone https://github.com/eehh-stanford/baydem 40 | cd baydem 41 | docker build -t michaelholtonprice/baydem . 42 | ``` 43 | 44 | Start a container. Use the -v tag to mirror a directory for passing files between the host machine and the Docker container. The directory to the left of the semicolon is for the host machine and the directory to the right of the semicolon is for the Docker container. The path for the host machine will need to be modified for your situation. 45 | 46 | ```bash 47 | docker run --name baydem -itv //c/mirrored_baydem_data:/data michaelholtonprice/baydem 48 | ``` 49 | 50 | The Docker container already has baydem installed, and it is likely the latest version. However, the latest version can be (re)installed by cloning the github repository inside the Docker container and using devtools::install_local. Following this, the test scripts can be run to check the installation (they will take perhaps 30 minutes to complete): 51 | 52 | ```bash 53 | git clone https://github.com/eehh-stanford/baydem 54 | cd baydem 55 | R 56 | library(devtools) 57 | install_local(".",force=T,dep=F) 58 | test() 59 | ``` -------------------------------------------------------------------------------- /man/calc_relative_density.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bayesian_inference_functions.R 3 | \name{calc_relative_density} 4 | \alias{calc_relative_density} 5 | \title{Calculate the relative density at two dates (or a range of dates / the peak)} 6 | \usage{ 7 | calc_relative_density( 8 | bayesian_soln, 9 | density_model, 10 | spec1, 11 | spec2, 12 | rc_meas = list(), 13 | calib_df = list(), 14 | ind = NA, 15 | bayesian_summary = NA 16 | ) 17 | } 18 | \arguments{ 19 | \item{bayesian_soln}{The result of a call to sample_theta} 20 | 21 | \item{density_model}{The density model (see set_density_model).} 22 | 23 | \item{spec1}{The specification for the first density (see details)} 24 | 25 | \item{spec2}{The specification for the second density (see details)} 26 | 27 | \item{rc_meas}{The radiocarbon measurements (see import_rc_data; optional: 28 | if not provided, bayesian_summary must be provided).} 29 | 30 | \item{calib_df}{The calibration data frame (see load_calib_curve; optional: 31 | if not provided, bayesian_summary must be provided).} 32 | 33 | \item{ind}{Indices at which to do the calculation (optional; by default, all 34 | the samples in bayesian_summary are used).} 35 | 36 | \item{bayesian_summary}{The result of a call to summarize_bayesian_inference. 37 | (optional; if not provided, it is calculated, which requires that rc_meas 38 | and calib_df be provided).} 39 | } 40 | \value{ 41 | A vector of relative densities (f_spec1 / f_spec2) 42 | } 43 | \description{ 44 | Calculate the relative density for two dates or, more generally, for two 45 | different specifications of the density aside from a simple date. The 46 | additional specifications that are supported are the peak value and the mean 47 | density on an interval. For a simple date, spec1/spec2 should be scalar 48 | real numbers. For a date range, spec1/spec2 should be real vectors with a 49 | length of 2. For the peak, spec1/spec2 should be the string 'peak'. 50 | 51 | By default, this calculation is done for all the Bayesian samples in 52 | bayesian_soln which is the result of a call to \code{sample_theta}. 53 | Optionally, a subset can be specified via the input ind, which should be a 54 | vector of integer indices at which to do the calculation. To save computation 55 | if either spec1 or spec2 is 'peak', the result of a call to 56 | \code{summarize_bayesian_inference} for which \code{do_summary} was TRUE can 57 | be input. 58 | } 59 | \seealso{ 60 | \itemize{ 61 | \item \code{\link[=import_rc_data]{import_rc_data()}} for the format of \code{rc_meas} 62 | \item \code{\link[=set_density_model]{set_density_model()}} for the format of \code{density_model} 63 | \item \code{\link[=load_calib_curve]{load_calib_curve()}} for the format of \code{calib_df} 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /man/set_sim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_io_functions.R 3 | \name{set_sim} 4 | \alias{set_sim} 5 | \title{Use the results of a simulation to set the radiocarbon measurements (rc_meas) 6 | for an analysis (and store the settings used to do the simulation)} 7 | \usage{ 8 | set_sim(data_dir, analysis_name, sim) 9 | } 10 | \arguments{ 11 | \item{data_dir}{The directory in which to store analysis data} 12 | 13 | \item{analysis_name}{A unique name for a given analysis in data_dir} 14 | 15 | \item{sim}{The simulation object (see simulate_rc_data)} 16 | } 17 | \description{ 18 | This is one of a set of helper functions for undertaking a typical analysis 19 | of radiocarbon dates. As the analysis proceeds, results are stored in a save 20 | file called analysis_name.rds in the folder data_dir. Where results are 21 | non-deterministic, random number seeds are set and stored to ensure that, 22 | even if processing is interrupted, results are fully reproducible. 23 | 24 | There are, in fact, two distinct pipelines for (a) simulations and (b) 25 | analyses that use existing radiocarbon measurements saved in a .csv file. 26 | Since this is the first helper function used in the standard pipeline for 27 | simulations, that pipeline is described here. See set_rc_meas for the 28 | pipeline when using an input .csv file. 29 | 30 | The standard pipeline for simulations is (see the vignette standard_pipeline 31 | for additional details): 32 | 33 | (0) simulate_rc_data 34 | Define the simulation parameters and create simulated data using 35 | simulate_rc_data. 36 | 37 | (1) set_sim 38 | Set the simulated data for the analysis 39 | 40 | (2) calc_tau_range 41 | Determine the range of calendar dates that span the radiocarbon 42 | measurements (or specify the range directly) 43 | 44 | (3) set_density_model 45 | Set the parametric model to be used for Bayesian inference. Currently, 46 | only a truncated Gaussian mixture is supported, which requires setting 47 | the calendar date range for truncation (likely using the result from step 48 | (3)) and choosing the number of mixture components, K. If K is a vector, 49 | Bayesian inference will be done for each element of the vector during 50 | step (4), do_bayesian_inference. 51 | 52 | (4) do_bayesian_inference 53 | Call sample_theta to do the Bayesian inference for each model to check. 54 | (Unlike the other pipeline that starts with an input .csv file, 55 | set_calib_curve does not need to be called prior to this step since the 56 | calibration curve is set with set_sim.) 57 | 58 | (5) do_bayesian_summary 59 | Calculate summary statistics for the best model sampled by calling 60 | do_bayesian_inference (the best model is the one with the best WAIC). 61 | 62 | (6) plot_best_solution 63 | Create a plot of the best solution. 64 | } 65 | -------------------------------------------------------------------------------- /man/set_rc_meas.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data_io_functions.R 3 | \name{set_rc_meas} 4 | \alias{set_rc_meas} 5 | \title{Set the radiocarbon measurements (rc_meas) for an analysis} 6 | \usage{ 7 | set_rc_meas(data_dir, analysis_name, rc_meas) 8 | } 9 | \arguments{ 10 | \item{data_dir}{The directory in which to store analysis data} 11 | 12 | \item{analysis_name}{A unique name for a given analysis in data_dir} 13 | 14 | \item{rc_meas}{The radiocarbon measurements to use for this analysis (the 15 | format of rc_meas is as output by import_rc_data)} 16 | } 17 | \description{ 18 | This is one of a set of helper functions for undertaking a typical analysis 19 | of radiocarbon dates. As the analysis proceeds, results are stored in a save 20 | file called analysis_name.rds in the folder data_dir. Where results are 21 | non-deterministic, random number seeds are set and stored to ensure that, 22 | even if processing is interrupted, results are fully reproducible. 23 | 24 | There are, in fact, two distinct pipelines for (a) simulations and (b) 25 | analyses that use existing radiocarbon measurements saved in a .csv file. 26 | Since this is the first helper function used in the standard pipeline for 27 | using an input .csv file, that pipeline is described here. See set_sim for 28 | the pipeline when doing a simulation. 29 | 30 | The standard pipeline for analyses that use an input data stored in a .csv 31 | file (see the vignette standard_pipeline for additional details): 32 | 33 | (0) import_rc_data 34 | Import data from a .csv file using import_rc_data. 35 | 36 | (1) set_rc_meas 37 | Use the data from the previous step to set the radiocarbon measurements 38 | to be used for this analysis 39 | 40 | (2) calc_tau_range 41 | Determine the range of calendar dates that span the radiocarbon 42 | measurements (or specify the range directly) 43 | 44 | (3) set_density_model 45 | Set the parametric model to be used for Bayesian inference. Currently, 46 | only a truncated Gaussian mixture is supported, which requires setting 47 | the calendar date range for truncation (likely using the result from step 48 | (3)) and choosing the number of mixture components, K. If K is a vector, 49 | Bayesian inference will be done for each element of the vector during 50 | step (5), do_bayesian_inference. 51 | 52 | (4) set_calib_curve 53 | Set the calibration curve to be used for subsequent steps. 54 | 55 | (5) do_bayesian_inference 56 | Call sample_theta to do the Bayesian inference for each model to check. 57 | 58 | (6) do_bayesian_summary 59 | Calculate summary statistics for the best model sampled by calling 60 | do_bayesian_inference (the best model is the one with the best WAIC). 61 | 62 | (7) plot_best_solution 63 | Create a plot of the best solution. 64 | } 65 | \seealso{ 66 | \code{\link[=import_rc_data]{import_rc_data()}} for the format of \code{rc_meas}' 67 | } 68 | -------------------------------------------------------------------------------- /man/summarize_trunc_gauss_mix_sample.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bayesian_inference_functions.R 3 | \name{summarize_trunc_gauss_mix_sample} 4 | \alias{summarize_trunc_gauss_mix_sample} 5 | \title{Identify growth periods and the peak value for a truncated Gaussian mixture} 6 | \usage{ 7 | summarize_trunc_gauss_mix_sample(th, tau_min, tau_max, N = 1000) 8 | } 9 | \arguments{ 10 | \item{th}{The Gaussian mixture parameterization} 11 | 12 | \item{tau_min}{The lower truncation value} 13 | 14 | \item{tau_max}{The upper truncation value} 15 | 16 | \item{N}{The number of points use for identifying slope changes 17 | (default: 1000)} 18 | } 19 | \value{ 20 | A list consisting of: 21 | \itemize{ 22 | \item{\code{periods}} 23 | {A data-frame where the columns t_lo/t_hi indicate the starting and 24 | ending calendars dates of periods and slope is negative if the growth 25 | rate is negative over that time period and positive if it is positive.} 26 | \item{\code{ind_peak}} 27 | {The index of the period in the data-frame \code{periods} with the peak 28 | value of the density.} 29 | \item{\code{t_peak}} 30 | {The calendar date of the peak value of the density.} 31 | \item{\code{f_peak}} 32 | {The value of the density function at the peak calendar date.} 33 | \item{\code{pattern}} 34 | {A unique pattern that summaries the periods of growth/decary and 35 | relative locaiton of the peak (see Description).} 36 | } 37 | } 38 | \description{ 39 | The input vector th parameterizes a Gaussian mixture, and tau_min / tau_max 40 | give the limits of truncation. Summarize the sample by identifying growth / 41 | decay periods and the peak value using the following procedure. 42 | 43 | (1) Calculate the derivative, f'(t), at the points t = 44 | seq(tau_min,tau_max,len=N), where N is 1000 by default. 45 | 46 | (2) Identify points where f'(t) changes sign, then numerically estimate the 47 | crossing point between the two t values where there was a sign change. 48 | 49 | (3) Create a vector of critical points, t_crit, which includes 50 | tau_min / tau_max as well as the crossing points found in the preceding 51 | step. 52 | 53 | (4) Calculate the density at the critical points to identify the peak value, 54 | f_peak, and corresponding calendar date, t_peak, as well as the index of 55 | the peak in t_crit, ind_peak. 56 | 57 | (5) For each time period (the length(t_peak)-1 durations defined by t_peak) 58 | determine the sign of the density function, f(t), and create a character 59 | vector, slope, that has the value 'pos' if f(t) is positive and 'neg' if 60 | f(t) is negative. 61 | 62 | (6) Finally, create a character vector, pattern, that appends the index of 63 | the peak in t_crit (converted to a character) to the character vector 64 | slope. This defines a unique pattern of the sample that takes into 65 | account periods of growth / decline and the relative location of the 66 | peak. 67 | } 68 | -------------------------------------------------------------------------------- /man/simulate_rc_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/simulation_functions.R 3 | \name{simulate_rc_data} 4 | \alias{simulate_rc_data} 5 | \title{Create simulated radiocarbon data} 6 | \usage{ 7 | simulate_rc_data(sim_spec) 8 | } 9 | \arguments{ 10 | \item{sim_spec}{A simulation specification (see Description)} 11 | } 12 | \value{ 13 | A list consisting of the input sim_spec and data (see Description) 14 | } 15 | \description{ 16 | The input is a multi-tiered list specifying all aspects of the simulation. In 17 | particular, sim_spec (for simulation specification) consists of three 18 | required fields and one optional field: model_spec (model specification), 19 | N (number of samples), calib_curve (calibration curve), and seed (an optional 20 | random number seed). model_spec, in turn, is a list than consists of three 21 | required fields: density_type (the type of parametric model to use for the 22 | target density), th (the parameter vector for the target density), is_AD (a 23 | boolean variable indicating whether the target density is for years AD or 24 | BP), and error_spec (a specification for how to model the measurement 25 | errors). Currently, two model types are supported for the target density, 26 | gauss_mix = a Gaussian mixture and trunc_gauss_mix = a truncated Gaussian 27 | mixture. Currently, one specification of the error_spec (a list) is 28 | supported: unif_fm = a uniform draw for the error of the fraction modern 29 | value. For unif_fm, error_spec must contain the fields min and max (the 30 | minimum and maximum values for the uniform draw). 31 | 32 | The output is a list with the fields dates and rc_meas. Dates is a length N 33 | vector of dates (on non-simulated data, cannot be directly known). rc_meas 34 | is a list consisting of four length N vectors: phi_m, the fracture modern, 35 | sig_m, the uncertainty of the fraction modern, trc_m, trc_m, the measurement 36 | in uncalibrated radiocarbon years, and sig_trc_m, the error for trc_m. The 37 | following hierarchical summary may be easier to digest: 38 | 39 | sim_spec A full specification of the simulation 40 | model_spec A specification for the model used to generate the 41 | data 42 | density_type The model type to use for the target density (e.g., a 43 | a truncated Gaussian mixture) 44 | th The parameter vector for the target density 45 | is_AD A boolean indicating whether the parameter vector 46 | assumes AD or BP (AD is 1950 - BP, which allows 47 | negative dates) 48 | error_spec A specification for the measurement errors 49 | N The number of random samples to make 50 | calib_curve The calibration curve (currently, must be a named intcal 51 | curve, but support for arbitrary curves could be added 52 | in the future) 53 | seed An optional random number seed to use to ensure 54 | reproducibility 55 | 56 | data The simulated data 57 | dates A vector of original dates for the samples 58 | rc_meas A list with the radiocarbon measurements 59 | phi_m A vector of simulated fraction moderns 60 | sig_m A vector of simulated standard deviations for 61 | phi_m 62 | trc_m A vector of simulated uncalibrated radiocarbon 63 | years (BP) 64 | sig_trc_m A vector of simulated uncertainties for trc_m 65 | } 66 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $(".examples, div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent; 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /man/sample_theta.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bayesian_inference_functions.R 3 | \name{sample_theta} 4 | \alias{sample_theta} 5 | \title{Sample from the posterior of a density model for a set of radiocarbon 6 | measurements} 7 | \usage{ 8 | sample_theta( 9 | rc_meas, 10 | density_model, 11 | hp, 12 | calib_df, 13 | th0 = NA, 14 | init_seed = NA, 15 | stan_seed = NA, 16 | calibration_curve = "intcal20", 17 | control = list() 18 | ) 19 | } 20 | \arguments{ 21 | \item{rc_meas}{The radiocarbon measurements (see import_rc_data).} 22 | 23 | \item{density_model}{The density model (see set_density_model).} 24 | 25 | \item{hp}{Hyperparameters for the priors and to specify the spacing of the 26 | Riemann sum that approximates the integral for the likelihood.} 27 | 28 | \item{calib_df}{The calibration data frame (see load_calib_curve).} 29 | 30 | \item{th0}{An optional parameter vector to initialize the Stan chains. If not 31 | provided, it is set by calling init_trunc_gauss_mix.} 32 | 33 | \item{init_seed}{An optional random number seed for determining the starting 34 | parameter vector using a maximum likelihood fit. If not provided, it is 35 | drawn. It should not be provided if th0 is provided.} 36 | 37 | \item{stan_seed}{An optional random number seed for the call to Stan. If not 38 | provided, it is drawn.} 39 | 40 | \item{calibration_curve}{The calibration curve to use for masking (only used 41 | control$mask is TRUE). The default is "intcal20". Other options are 42 | "shcal20" and "marine20". For further options see Bchron::BchronCalibrate.} 43 | } 44 | \value{ 45 | \code{bayesian_soln}, a list-like object of class bd_bayesian_soln with the 46 | following fields: 47 | \itemize{ 48 | \item{\code{fit}} 49 | {The result of the call to stan} 50 | \item{\code{final_th0}} 51 | {The final \code{th0} value; i.e., never NA.} 52 | \item{\code{final_init_seed}} 53 | {The final init_seed value; i.e., never NA unless \code{th0} is 54 | provided.} 55 | \item{\code{final_stan_seed}} 56 | {The final \code{stan_seed} value; i.e., never NA.} 57 | \item{\code{final_control}} 58 | {The final control parameters used; i.e., if a parameter is not 59 | provided.} 60 | \item{\code{optional_inputs}} 61 | {A record of the actual input values for the optional inputs, which are 62 | \code{th0}, \code{init_seed}, \code{stan_seed}, and \code{control}.} 63 | } 64 | } 65 | \description{ 66 | This is the core function that implements the Bayesian inference. Currently, 67 | the only supported density model is a truncated Gaussian mixture. If a 68 | starting parameter vector (\code{th0}) is not provided, it is set by calling 69 | init_trunc_gauss_mix; the same vector is used for all sampling chains. Named 70 | elements of the variable control must consist of one of the following four 71 | options (defaults in parentheses): 72 | 73 | \itemize{ 74 | \item{\code{num_chains}} 75 | 76 | The calibration_curve to use for masking is separately input to maintain 77 | 78 | consistency with previous versions of baydem. 79 | {Number of chains (4)} 80 | \item{\code{samps_per_chain}} 81 | {Number of samples per chain (2000)} 82 | \item{\code{warmup}} 83 | {Number of warmup samples (\code{samps_per_chain/2})} 84 | \item{\code{stan_control}} 85 | {Additional control parameters to pass to stan (\code{list()})} 86 | \item{\code{mask}} 87 | {Whether to mask the likelihood sum based on individual calibration 88 | (FALSE)} 89 | } 90 | 91 | The calibration_curve to use for masking is separately input to maintain 92 | consistency with previous versions of baydem. 93 | } 94 | \seealso{ 95 | \itemize{ 96 | \item \code{\link[=import_rc_data]{import_rc_data()}} for the format of \code{rc_meas} 97 | \item \code{\link[=set_density_model]{set_density_model()}} for the format of \code{density_model} 98 | \item \code{\link[=load_calib_curve]{load_calib_curve()}} for the format of \code{calib_df} 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /man/summarize_bayesian_inference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bayesian_inference_functions.R 3 | \name{summarize_bayesian_inference} 4 | \alias{summarize_bayesian_inference} 5 | \title{Calculate some key summary measures using the result of a call to 6 | \code{sample_theta}} 7 | \usage{ 8 | summarize_bayesian_inference( 9 | bayesian_soln, 10 | rc_meas, 11 | density_model, 12 | calib_df, 13 | dtau = 5, 14 | th_sim = NA, 15 | lev = 0.025, 16 | rate_prop = NA, 17 | do_sample_summaries = T 18 | ) 19 | } 20 | \arguments{ 21 | \item{bayesian_soln}{The solution, a list-like object of class 22 | bd_bayesian_soln (see sample_theta).} 23 | 24 | \item{rc_meas}{The radiocarbon measurements (see import_rc_data).} 25 | 26 | \item{density_model}{The density model (see set_density_model).} 27 | 28 | \item{calib_df}{The calibration data frame (see load_calib_curve).} 29 | 30 | \item{dtau}{The spacing of the sampling grid (default: 5).} 31 | 32 | \item{th_sim}{The known parameters used to create simulation data (default: 33 | NA, not provided).} 34 | 35 | \item{lev}{The level to use for the quantile bands (default: 0.025).} 36 | 37 | \item{rate_prop}{The cumulative density needed to define rate growth bands 38 | (default: NA, not used).} 39 | 40 | \item{do_sample_summaries}{Whether to calculate some summary information for 41 | each sampled curve (Default: TRUE).} 42 | } 43 | \value{ 44 | A list with information on the quantiles of the density function and 45 | growth rate (and sample summaries) 46 | } 47 | \description{ 48 | \code{sample_theta} calls Stan to do Bayesian inference by 49 | generating a sample of parameters from the posterior of theta (or \code{th}). 50 | \code{sample_theta} analyzes the result of that inference. Notably, 51 | it calculates the quantiles of the density function and the growth rate. 52 | } 53 | \details{ 54 | \code{bayesian_soln} is the result of a call to 55 | \code{sample_theta}. It contains posterior samples for the density 56 | model. The primary thing \code{summarize_bayesian_inference} does is 57 | calculate quantiles of both the parameterized density and growth rate. For 58 | example, for a calendar date tau_g each sample yields a density and growth 59 | rate. The quantile is the value of the density or growth rate such that a 60 | given proportion of samples are smaller than that value. The probabilities 61 | used to calculate these quantiles are \code{probs = c(lev, 0.5, 1-lev)}, where 62 | \code{lev} is the level (0.025 by default, so that 95\% of the observations lie 63 | between the first and last quantile bands). 64 | 65 | In addition, \code{summarize_bayesian_inference} identifies calendar dates 66 | for which the growth rate quantiles defined by \code{lev} and \code{1 - lev} do not 67 | contain zero. This indicates significant positive or negative growth for the 68 | density curve. The output vector \code{growth_state} codes calendar dates by 69 | growth state as 'negative', 'zero', and 'positive'. For the Gaussian mixture 70 | parameterization of the density, the rate is not typically meaningful near 71 | the calendar date boundaries where it increases linearly as the calendar date 72 | goes to positive or negative infinity. The parameter \code{rate_prop} provides 73 | control on how calendar dates are classified by growth rate near these 74 | boundaries. In particular, the calendar dates with a cumulative density (50\% 75 | quantile) below \code{rate_prop} (for the lower boundary) or above \code{1 - rate_prop} 76 | (for the upper boundary) are classified as 'missing' in \code{growth_state}. By 77 | default, \code{rate_prop} is NA and no calendar dates are classified as missing. 78 | 79 | By default, a summary is done for each sample by calling summarize_sample. 80 | This is not done if do_summary is FALSE. 81 | } 82 | \seealso{ 83 | \itemize{ 84 | \item \code{\link[=import_rc_data]{import_rc_data()}} for the format of \code{rc_meas} 85 | \item \code{\link[=set_density_model]{set_density_model()}} for the format of \code{density_model} 86 | \item \code{\link[=load_calib_curve]{load_calib_curve()}} for the format of \code{calib_df} 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /inst/stan/gaussmix_masked.stan: -------------------------------------------------------------------------------- 1 | functions { 2 | 3 | int bin_search(real x, int min_val, int max_val){ 4 | // This assumes that min_val >= 0 is the minimum integer in range, 5 | // max_val > min_val, 6 | // and that x has already been rounded. 7 | // It should find the integer equivalent to x. 8 | int range = (max_val - min_val+1)/2; // We add 1 to make sure that truncation doesn't exclude a number 9 | int mid_pt = min_val + range; 10 | int out; 11 | while(range > 0) { 12 | if(x == mid_pt){ 13 | out = mid_pt; 14 | range = 0; 15 | } else { 16 | // figure out if range == 1 17 | range = (range+1)/2; 18 | mid_pt = x > mid_pt ? mid_pt + range: mid_pt - range; 19 | } 20 | } 21 | return out; 22 | } 23 | 24 | vector calc_logh(int N, int K, int G, 25 | vector pi, vector s, vector mu, vector tau, real dtau, 26 | vector stacked_log_M, 27 | vector subset_length, 28 | int subset_length_min, int subset_length_max, 29 | vector M_offset, 30 | int M_offset_min, int M_offset_max, 31 | vector tau_offset, 32 | int tau_offset_min, int tau_offset_max) { 33 | vector[N] logh; // Log-likelihood 34 | vector[G] logf; // log density 35 | vector[G] f; // density 36 | vector[K] logpi = log(pi); // log(pi), used for the log_sum_exp calculation 37 | real log_norm_factor; 38 | 39 | // Calculate the density as well as the normalization factor for the density 40 | logf = rep_vector(0,G); 41 | for (g in 1:G) { 42 | vector[K] lse = logpi; 43 | for (k in 1:K) { 44 | lse[k] += normal_lpdf(tau[g]|mu[k],s[k]); 45 | } 46 | logf[g] = log_sum_exp(lse); 47 | } 48 | f = exp(logf); 49 | log_norm_factor = log(sum(f)) + log(dtau); 50 | 51 | // Iterate over observations to calculate the log-likelihood, logh 52 | for (n in 1:N) { 53 | // Grid length for this sample 54 | int G_n = bin_search(subset_length[n], subset_length_min, subset_length_max); 55 | int M_offset_n = bin_search(M_offset[n], M_offset_min, M_offset_max); 56 | int tau_offset_n = bin_search(tau_offset[n], tau_offset_min, tau_offset_max); 57 | 58 | vector[G_n] lse = rep_vector(0, G_n); // Initialize the log-sum-exp vector 59 | // Iterate over grid points for this observation 60 | for (g in 1:G_n) { 61 | lse[g] = logf[tau_offset_n + g] + stacked_log_M[M_offset_n + g] - log_norm_factor; 62 | } 63 | logh[n] = log_sum_exp(lse); 64 | } 65 | return logh; 66 | } 67 | } 68 | 69 | 70 | data { 71 | int N; // Number of observations 72 | int G; // Number of grid pints 73 | int K; // Number of mixtures 74 | int stacked_log_M_length; // Length of stacked log M vector 75 | vector[stacked_log_M_length] stacked_log_M; // Stacked measurement matrix 76 | vector[G] tau; // Full calendar dates grid 77 | vector[N] subset_length; // Length of subset for each observation 78 | int subset_length_min; // Minimum value of subset_length 79 | int subset_length_max; // Maximum value of subset_length 80 | vector[N] M_offset; // Offset in stacked_log_M for each observation 81 | int M_offset_min; // Minimum M_offset value 82 | int M_offset_max; // Maximum M_offset value 83 | vector[N] tau_offset; // Offset in tau for each observation 84 | int tau_offset_min; // Minimum value of tau_offset 85 | int tau_offset_max; // Maximum value of tau_offset 86 | int tau_min; // Minimum calendar date 87 | int tau_max; // Maximum calendar date 88 | real dtau; // Grid spacing (not error checked for consistency with tau) 89 | real alpha_d; // Concentration parameter for pi prior 90 | real alpha_s; // shape parameter of gamma distribution for s 91 | real alpha_r; // rate parameter of gamma distribution for s 92 | } 93 | 94 | parameters { 95 | simplex[K] pi; 96 | ordered[K] mu; 97 | vector[K] s; 98 | } 99 | 100 | transformed parameters { 101 | vector[N] logh; 102 | logh = calc_logh(N, K, G, 103 | pi, s, mu, tau, dtau, 104 | stacked_log_M, 105 | subset_length, 106 | subset_length_min, subset_length_max, 107 | M_offset, 108 | M_offset_min, M_offset_max, 109 | tau_offset, 110 | tau_offset_min, tau_offset_max); 111 | } 112 | 113 | model { 114 | pi ~ dirichlet(rep_vector(alpha_d,K)); 115 | s ~ gamma(alpha_s,alpha_r); 116 | mu ~ uniform(tau_min,tau_max); 117 | target += sum(logh); 118 | } 119 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /R/gaussian_mixture_model_functions.R: -------------------------------------------------------------------------------- 1 | #' @title 2 | #' Calculate the density of a possibly truncated Gaussian mixture for a matrix 3 | #' of samples 4 | #' 5 | #' @description 6 | #' TH is a matrix of samples of a possibly truncated Gaussian mixture with 7 | #' dimensions S x P, where S is the number of samples and P is the number of 8 | #' parameters. Repeatedly call \code{calc_gauss_mix_pdf} to calculate the 9 | #' density function for each sample at the points in the vector tau, which has 10 | #' length G. The output density matrix, f_mat, has dimensions S x G. 11 | #' \code{calc_gauss_mix_pdf_mat} supports the same optional inputs as 12 | #' \code{calc_gauss_mix_pdf}: tau_min / tau_max to specify the boundaries of 13 | #' truncation and type to set whether the density, cumulative distribution, 14 | #' derivative, or rate is calculated. 15 | #' 16 | #' @param TH A matrix of samples with dimensions S x P 17 | #' @param tau A vector of points for the density calculation with length G 18 | #' @param tau_min (optional) The mininum time-value for truncation 19 | #' @param tau_max (optional) The maximum time-value for truncation 20 | #' @param type (optional) The type of calculation: density (default), 21 | #' cumulative, derivative, or rate 22 | #' 23 | #' @return The output matrix with dimensions S x G 24 | #' 25 | #' @export 26 | 27 | calc_gauss_mix_pdf_mat <- function(TH,tau, 28 | tau_min=NA,tau_max=NA,type="density") { 29 | S <- dim(TH)[1] # number of samples 30 | G <- length(tau) # number of time-values (usually grid points) 31 | f_mat <- matrix(NA, S, G) 32 | 33 | # Iterate over samples to fill fMat 34 | for (s in 1:S) { 35 | f_mat[s, ] <- calc_gauss_mix_pdf(TH[s, ], 36 | tau, 37 | tau_min = tau_min, 38 | tau_max = tau_max, type = type) 39 | } 40 | return(f_mat) 41 | } 42 | 43 | #' @title 44 | #' Caculate the density of a possibly truncated Gaussian mixture 45 | #' 46 | #' @description 47 | #' \code{calc_gauss_mix_pdf} calculates the probability density for a possibly 48 | #' truncated Gaussian mixture. The density, f', and rate, f'/f, can also be 49 | #' calculated by specifying the input \code{type}, which is 'density' by 50 | #' default, but can also be 'cumulative', 'derivative', or 'rate'. The parameter 51 | #' vector th has the ordering (pi_k, mu_k, s_k), where pi_k, mu_k, and s_k are 52 | #' the weight, mean, and standard deviation of the k-th mixture. There are K 53 | #' total mixtures. The truncation boundaries tau_min and tau_max are optional. 54 | #' If provided, the density is normalized to integrate to 1 on that interval. 55 | #' 56 | #' @param th A vector-like object that parameterizes the distribution 57 | #' @param tau Vector of locations at which to calculate the density 58 | #' @param tau_min Minimum truncation bound 59 | #' @param tau_max Maximum truncation bound 60 | #' @param type (default density) An optional input specifying whether to 61 | #' calculate the density, cumulative distribution, derivative of the 62 | #' density, or rate 63 | #' 64 | #' @return The output vector with length G 65 | #' 66 | #' @export 67 | calc_gauss_mix_pdf <- function(th, 68 | tau, 69 | tau_min = NA, 70 | tau_max = NA, 71 | type = "density") { 72 | # First, determine whether taumin and taumax are input 73 | do_norm <- !is.na(tau_min) 74 | 75 | # Determine number of mixtures (and also do error checking on length(th)) 76 | if (length(th) %% 3 == 0) { 77 | # Correct length 78 | K <- length(th) / 3 79 | } else { 80 | stop("Unsupported length of parameter vector th") 81 | } 82 | 83 | # Check that type is valid 84 | if (!type %in% c("density", "cumulative", "derivative", "rate")) { 85 | stop("type must be density, cumulative, derivative, or rate") 86 | } 87 | 88 | # If type is rate, no normalization is needed. 89 | # Hence, if type is rate then taumin and taumax are ignored if they are input. 90 | if (type == "rate") { 91 | do_norm <- F 92 | } 93 | 94 | # Replicate the inputs for efficient calculations 95 | G <- length(tau) 96 | tau_rep <- rep(tau, K) 97 | pi_rep <- as.vector(t(matrix(th[1:K], G, nrow = K))) 98 | mu_rep <- as.vector(t(matrix(th[(K + 1):(2 * K)], G, nrow = K))) 99 | s_rep <- as.vector(t(matrix(th[(2 * K + 1):(3 * K)], G, nrow = K))) 100 | 101 | # Do the calculation 102 | if (type == "density") { 103 | output <- rowSums(matrix( 104 | stats::dnorm(tau_rep, mu_rep, s_rep) * pi_rep, ncol = K)) 105 | } else if (type == "cumulative") { 106 | output <- rowSums(matrix( 107 | stats::pnorm(tau_rep, mu_rep, s_rep) * pi_rep, ncol = K)) 108 | } else if (type == "derivative") { 109 | output <- rowSums(matrix( 110 | miscTools::ddnorm(tau_rep, mu_rep, s_rep) * pi_rep, ncol = K)) 111 | } else if (type == "rate") { 112 | # the numerator 113 | output1 <- rowSums(matrix( 114 | miscTools::ddnorm(tau_rep, mu_rep, s_rep) * pi_rep, ncol = K)) 115 | output2 <- rowSums(matrix( 116 | # the denominator 117 | stats::dnorm(tau_rep, mu_rep, s_rep) * pi_rep, ncol = K)) 118 | output <- output1 / output2 119 | } else { # This should not be reached. Throw an error just in case 120 | stop("type must be density, cumulative, derivative, or rate") 121 | } 122 | if (do_norm) { 123 | norm_fact <- diff(calc_gauss_mix_pdf(th, c(tau_min, tau_max), type = "cumulative")) 124 | output <- output / norm_fact 125 | } 126 | return(output) 127 | } -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | License • baydem 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 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
    62 |
    63 | 114 | 115 | 116 | 117 |
    118 | 119 |
    120 |
    121 | 124 | 125 |
    YEAR: 2020
    126 | COPYRIGHT HOLDER: Michael Holton Price
    127 | 
    128 | 129 |
    130 | 131 | 136 | 137 |
    138 | 139 | 140 | 141 |
    142 | 145 | 146 |
    147 |

    Site built with pkgdown 1.6.1.

    148 |
    149 | 150 |
    151 |
    152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Authors • baydem 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 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
    62 |
    63 | 114 | 115 | 116 | 117 |
    118 | 119 |
    120 |
    121 | 124 | 125 |
      126 |
    • 127 |

      Michael Holton Price. Author, maintainer. 128 |

      129 |
    • 130 |
    • 131 |

      R. Kyle Bocinsky. Contributor. 132 |

      133 |
    • 134 |
    135 | 136 |
    137 | 138 |
    139 | 140 | 141 | 142 |
    143 | 146 | 147 |
    148 |

    Site built with pkgdown 1.6.1.

    149 |
    150 | 151 |
    152 |
    153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Page not found (404) • baydem 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 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
    62 |
    63 | 114 | 115 | 116 | 117 |
    118 | 119 |
    120 |
    121 | 124 | 125 | Content not found. Please use links in the navbar. 126 | 127 |
    128 | 129 | 134 | 135 |
    136 | 137 | 138 | 139 |
    140 | 143 | 144 |
    145 |

    Site built with pkgdown 1.6.1.

    146 |
    147 | 148 |
    149 |
    150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Articles • baydem 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 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
    62 |
    63 | 114 | 115 | 116 | 117 |
    118 | 119 |
    120 |
    121 | 124 | 125 |
    126 |

    All vignettes

    127 |

    128 | 129 |
    130 |
    Summarizing sets of radiocarbon dates using baydem's standard pipeline
    131 |
    132 |
    133 |
    134 |
    135 |
    136 | 137 | 138 |
    139 | 142 | 143 |
    144 |

    Site built with pkgdown 1.6.1.

    145 |
    146 | 147 |
    148 |
    149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /man/fit_trunc_gauss_mix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/max_lik_fitting_functions.R 3 | \name{fit_trunc_gauss_mix} 4 | \alias{fit_trunc_gauss_mix} 5 | \title{Fit a truncated Gaussian mixture to radiocarbon data using the Hooke-Jeeves 6 | algorithm with multiple restarts} 7 | \usage{ 8 | fit_trunc_gauss_mix( 9 | K, 10 | phi_m, 11 | sig_m, 12 | tau_min, 13 | tau_max, 14 | dtau, 15 | calib_df, 16 | r_max = Inf, 17 | num_restarts = 100, 18 | maxfeval = (K - 1) * 10000, 19 | num_cores = NA, 20 | input_seed = NA 21 | ) 22 | } 23 | \arguments{ 24 | \item{K}{The number of mixture components to use for the fit} 25 | 26 | \item{phi_m}{A vector of fraction moderns} 27 | 28 | \item{sig_m}{A vector of standard deviations for phi_m} 29 | 30 | \item{tau_min}{The minimum calendar date (AD) for the sampling grid} 31 | 32 | \item{tau_max}{The maximum calendar date (AD) for the sampling grid} 33 | 34 | \item{dtau}{The spacing of the sampling grid} 35 | 36 | \item{calib_df}{Calibration curve (see load_calib_curve)} 37 | 38 | \item{r_max}{Maximum value for the instantaneous growth rate of the density 39 | function (default: Inf, no constraint)} 40 | 41 | \item{num_restarts}{Number of restarts to use (default: 100)} 42 | 43 | \item{maxfeval}{Maximum number of function evaluations for each restart 44 | (default: (K-1)*10000)} 45 | 46 | \item{num_cores}{The number of cores to use for parallelization (default: NA, 47 | do not parallelize)} 48 | 49 | \item{input_seed}{Either a single integer or a vector of integers of length 50 | 1 + num_restarts that is used to ensure reproducilibity (default: NA, a 51 | the base seed will be generated and saved).} 52 | } 53 | \value{ 54 | A list containing: 55 | \itemize{ 56 | \item{\code{th}} 57 | {The best fit parameter vector} 58 | \item{\code{neg_log_lik}} 59 | {The value of the negative log-likelihood for the best fit parameter 60 | vector.} 61 | \item{\code{tau}} 62 | {The sampling grid used for the Riemann sum in the likelihood 63 | calculation.} 64 | \item{\code{tau}} 65 | {The probability density given \code{th} evaluated at the points in 66 | \code{tau}.} 67 | \item{\code{aic}} 68 | {The Akaike information criterion value.} 69 | \item{\code{bic}} 70 | {the Bayesian information criterion value.} 71 | \item{\code{hjkb_fit_list}} 72 | {A list containing the fits for each restart.} 73 | \item{\code{input_seed}} 74 | {The value of the input parameter seed.} 75 | \item{\code{base_seed}} 76 | {The value of the base seed, which is NA if \code{input_seed} is a 77 | vector.} 78 | \item{\code{seed_vect}} 79 | {The vector of seed integers with length 1 + \code{num_restarts}.} 80 | } 81 | } 82 | \description{ 83 | The radiocarbon data are specified by phi_m, the vector of fraction modern 84 | values, and sig_m, the vector of associated standard deviations (both indexed 85 | by i). The likelihood involves an integral over calendar dates that is 86 | calculated using a Riemann integral at the points in the "sampling grid", 87 | tau, which ranges from tau_min to tau_max and has a spacing of dtau (tau is 88 | indexed by the variable g). 89 | 90 | Constraints on parameters: The parameter vector, theta (th), has the ordering 91 | th = (pi_1,...,pi_K,mu_1,..mu_K,s_1,...s_K), where K is the number of 92 | mixture components and pi_k / mu_k / s_k are, respectively, the weighting / 93 | mean / standard deviation of the k-th mixture. Optimization is actually done 94 | using a "reduced" vector from which pi_1 has been removed, th = (pi_2,...), 95 | since the mixture weights must add to 1. Constraints are placed on each 96 | variable in the parameter vector. All the weightings must lie between 0 and 97 | 1, including pi_1 (even though it is not in th_reduced). The means must lie 98 | between tau_min and tau_max. Since a numerical integral with a defined 99 | spacing is used to calculate the likelihood, the standard deviations of the 100 | mixture components cannot be too small, and are constrained to be greater 101 | than 10*dtau; they are also constrained to be less than tau_max-tau_min. In 102 | summary:\preformatted{ 0 < pi_k < 1 103 | } 104 | 105 | tau_min < mu_k < tau_max 106 | 10*dtau < s_k < tau_max-tau_min. 107 | 108 | The bounded Hooke-Jeeves algorithm in the dfoptim R package (dfoptim::hjkb) 109 | is used to do the optimization. The Hooke-Jeeves algorithm is perhaps the 110 | best known varient of derivative free pattern-searches. Using multiple 111 | restarts helps identify the global optimum (rather than a local optimum). 112 | 113 | To ensure reproducibility, the input_seed can be specified in one of two 114 | ways. (1) input_seed is a single integer; if so, set the base_seed equal to 115 | equal to input_seed (see below for how base_seed is used). (2) A vector of 116 | integers of length 1 + num_restarts is specified; no base seed is needed if a 117 | vector is provided. If no input_seed is provided (input_seed = NA), the base 118 | seed is randomly generated and stored. (1) If a base_seed is used, the 119 | command set.seed(base_seed) is run, then a vector of integers is drawn to 120 | populate seed_vect. (2) If a vector is given for input_seed, seed_vect is set 121 | equal to it. The first entry in seed_vect is used with set.seed() prior to 122 | drawing the starting parameter vectors for the restarts. The subsequent 123 | entries are used with set.seed() prior to calling the bounded Hooke-Jeeves 124 | optimization algorithm for each restart. These additional seeds are necessary 125 | to ensure reproducibility is achieved when multiple cores are used to do the 126 | optimizations in a parallel for loop. 127 | 128 | It can be desirable to regularize the probability density function so that 129 | it does not have periods of very fast decay or growth, which can be done 130 | using the optional input r_max. Setting a constraint should most likely be 131 | done if the density function is used for demographic reconstruction (i.e., if 132 | it is interpreted as the relative population size as a function of calendar 133 | date). If so, a value of r_max = 0.04 could be sensible. By default, however, 134 | r_max = Inf and no constraint is used. 135 | } 136 | -------------------------------------------------------------------------------- /docs/reference/pipe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Pipe operator — %>% • baydem 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 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
    63 |
    64 | 115 | 116 | 117 | 118 |
    119 | 120 |
    121 |
    122 | 127 | 128 |
    129 |

    See magrittr::%>% for details.

    130 |
    131 | 132 |
    lhs %>% rhs
    133 | 134 | 135 | 136 |
    137 | 142 |
    143 | 144 | 145 |
    146 | 149 | 150 |
    151 |

    Site built with pkgdown 1.6.1.

    152 |
    153 | 154 |
    155 |
    156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /docs/reference/bd_load_calib_curve.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Load Calibration Curve — bd_load_calib_curve • baydem 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 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 100 | 101 | 102 | 103 |
    104 | 105 |
    106 |
    107 | 112 | 113 |
    114 |

    Parse and return the radiocarbon calibration curve stored in data

    115 |
    116 | 117 |
    bd_load_calib_curve(calibCurve)
    118 | 119 |

    Arguments

    120 | 121 | 122 | 123 | 124 | 125 | 126 |
    calibCurve

    Name of calibration curve

    127 | 128 |

    Value

    129 | 130 |

    The calibration dataframe, with columns yearBP, uncalYearBP, and uncalYearBPError

    131 | 132 |
    133 | 143 |
    144 | 145 | 146 |
    147 | 150 | 151 |
    152 |

    Site built with pkgdown 1.4.1.

    153 |
    154 | 155 |
    156 |
    157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /docs/reference/bd_norm_pdf_mat.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Normalize the rows of an input density matrix — bd_norm_pdf_mat • baydem 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 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
    63 |
    64 | 98 | 99 | 100 | 101 |
    102 | 103 |
    104 |
    105 | 110 | 111 |
    112 |

    The input density matrix fMat has dimensions S x G, 113 | where S is the number of samples and G is the number of grid points 114 | at which fMat was evaluated. 115 | Normalize each row to integrate to 1 using the input grid spacing dy.

    116 |
    117 | 118 |
    bd_norm_pdf_mat(fMat, dy)
    119 | 120 |

    Arguments

    121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 |
    fMat

    The input density matrix with dimensions S x G

    dy

    The grid spacing

    132 | 133 |

    Value

    134 | 135 |

    The density matrix with normalized rows

    136 | 137 |
    138 | 146 |
    147 | 148 | 149 |
    150 | 153 | 154 |
    155 |

    Site built with pkgdown 1.4.1.

    156 |
    157 | 158 |
    159 |
    160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /docs/reference/bd_convert_gauss_mix_param_vect_to_list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Convert a Gaussian mixture parameterization from a vector to a list — bd_convert_gauss_mix_param_vect_to_list • baydem 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 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
    63 |
    64 | 98 | 99 | 100 | 101 |
    102 | 103 |
    104 |
    105 | 110 | 111 |
    112 |

    For the input, parameterized Gaussian mixture convert from a 113 | vector representation (which is more efficient for calculations 114 | and the form expected by, e.g., bayDem_calcGaussMixPdf.R) list 115 | (returned by stan).

    116 |
    117 | 118 |
    bd_convert_gauss_mix_param_vect_to_list(th)
    119 | 120 |

    Arguments

    121 | 122 | 123 | 124 | 125 | 127 | 128 |
    th

    A vector that parameterizes the Gaussian mixture. See 126 | bayDem_calcGaussMixPdf.R

    129 | 130 |

    Value

    131 | 132 |

    samp A list that parameterizes the Gaussian mixture. See See

    133 | 134 |
    135 | 143 |
    144 | 145 | 146 |
    147 | 150 | 151 |
    152 |

    Site built with pkgdown 1.4.1.

    153 |
    154 | 155 |
    156 |
    157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /docs/reference/bd_convert_gauss_mix_param_list_to_vect.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Convert a Gaussian mixture parameterization from a list to a vector — bd_convert_gauss_mix_param_list_to_vect • baydem 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 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
    63 |
    64 | 98 | 99 | 100 | 101 |
    102 | 103 |
    104 |
    105 | 110 | 111 |
    112 |

    For the input, parameterized Gaussian mixture convert from a 113 | list (returned by stan) to a vector representation (which is 114 | more efficient for calculations and the form expected by, e.g., 115 | bayDem_calcGaussMixPdf.R).

    116 |
    117 | 118 |
    bd_convert_gauss_mix_param_list_to_vect(samp)
    119 | 120 |

    Arguments

    121 | 122 | 123 | 124 | 125 | 127 | 128 |
    samp

    A list that parameterizes the Gaussian mixture. See 126 | bayDem_samplePrior.R.

    129 | 130 |

    Value

    131 | 132 |

    th A vector that parameterizes the Gaussian mixture. See 133 | bayDem_calcGaussMixPdf.R

    134 | 135 |
    136 | 144 |
    145 | 146 | 147 |
    148 | 151 | 152 |
    153 |

    Site built with pkgdown 1.4.1.

    154 |
    155 | 156 |
    157 |
    158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /docs/LICENSE.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | MIT License • baydem 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 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
    62 |
    63 | 114 | 115 | 116 | 117 |
    118 | 119 |
    120 |
    121 | 124 | 125 |
    126 | 127 |

    Copyright (c) 2020 Michael Holton Price

    128 |

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    129 |

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    130 |

    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    131 |
    132 | 133 |
    134 | 135 | 140 | 141 |
    142 | 143 | 144 | 145 |
    146 | 149 | 150 |
    151 |

    Site built with pkgdown 1.6.1.

    152 |
    153 | 154 |
    155 |
    156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /docs/reference/load_calib_curve.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Load Calibration Curve — load_calib_curve • baydem 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 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
    63 |
    64 | 115 | 116 | 117 | 118 |
    119 | 120 |
    121 |
    122 | 127 | 128 |
    129 |

    Parse and return the radiocarbon calibration curve stored in data.

    130 |
    131 | 132 |
    load_calib_curve(calib_curve)
    133 | 134 |

    Arguments

    135 | 136 | 137 | 138 | 139 | 141 | 142 |
    calib_curve

    Name of calibration curve. One of: "intcal20", "marine20", 140 | "shcal20", "intcal13", "marine13", or "shcal13"

    143 | 144 |

    Value

    145 | 146 |

    The calibration dataframe, with columns year_BP, uncal_year_BP, and 147 | uncal_year_BP_error

    148 | 149 |
    150 | 155 |
    156 | 157 | 158 |
    159 | 162 | 163 |
    164 |

    Site built with pkgdown 1.6.1.

    165 |
    166 | 167 |
    168 |
    169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /docs/reference/bd_plot_known_sim_density.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Plot the known simulation density — bd_plot_known_sim_density • baydem 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 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
    60 |
    61 | 100 | 101 | 102 | 103 |
    104 | 105 |
    106 |
    107 | 112 | 113 |
    114 |

    Plot the known simulation density

    115 |
    116 | 117 |
    bd_plot_known_sim_density(an, add = F, ...)
    118 | 119 |

    Arguments

    120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |
    an

    A list-like object generated by bd_analyze_soln with information on the quantiles of the density function and growth rate

    add

    (default: FALSE) Whether to make a new plot or add to the active plot

    ...

    Additional parameters to pass to plot / lines

    135 | 136 |

    Details

    137 | 138 |

    The input, an, is the result of a call to bd_analyze_soln. It is a 139 | list-like object with information on the quantiles of the density function 140 | and growth rate. By default, a new plot is made, but if add = TRUE the curve 141 | is added to the active plot.

    142 | 143 |
    144 | 152 |
    153 | 154 | 155 | 165 |
    166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | --------------------------------------------------------------------------------