knitr::opts_chunk$set(echo = TRUE, cache = TRUE, autodep = TRUE)
library(hamstr)

Compare hamstr models with Bacon models fit using the hamstr_bacon interface

Using the example dataset from Bacon

Calibrate the radiocarbon ages for hamstr

MSB2K_cal <- calibrate_14C_age(MSB2K, age.14C = "age", age.14C.se = "error")

First run a hamstr model for comparison.

hamstr_1 <- hamstr(depth = MSB2K_cal$depth,
                   obs_age = MSB2K_cal$age.14C.cal,
                   obs_err = MSB2K_cal$age.14C.cal.se,
                   #K = c(10, 10),
                   cores = 3)
plot(hamstr_1, plot_diagnostics = FALSE)

Then run a hamstr_bacon model. Remember to pass the uncalibrated radiocarbon dates to hamstr_bacon as Bacon will do the calibration.

hambac_5 <- hamstr_bacon(id = "sdf", 
                         depth = MSB2K_cal$depth,
                               obs_age = MSB2K_cal$age,
                               obs_err = MSB2K_cal$error,
                               thick = 5, cc = 1, 
                         close.connections = FALSE)

plot(hambac_5)

The plot method works for hamstr_bacon models too.

plot(hambac_5,
     # plot the individual iterations rather than a summary, and only plot 30
     summarise = FALSE,
     n.iter = 30)

Getting the age-model realisations and summaries

Summarise the age models at the modelled depths

summary(hambac_5)

Get all the iterations with predict()

predict(hambac_5)

If you want specific depths you can ask for them and the age models will be linearly interpolated

spec_depths <- predict(hambac_5, depth = c(10:15))

spec_depths

Summary also works after interpolation

summary(spec_depths)

Accumulation rates

predict(hambac_5, type = "acc_rates")
plot(hambac_5, type = "acc_rates")
plot(hambac_5, type = "acc_rates",  tau = 10)
summary(hambac_5, type = "acc_rates")


EarthSystemDiagnostics/hamstrbacon documentation built on June 2, 2025, 5:04 a.m.