shake: Generate new x values

shakeR Documentation

Generate new x values

Description

Used internally by quake() to generate new x values. Different flavours (shake_*) exist depending the type of uncertainties you have. *_within variants allow to share new values within a level.

Usage

shake_uniform(x, min, max)

shake_uniform_within(x, min, max, within)

shake_gaussian(x, mean, sd)

shake_gaussian_within(x, mean, sd, within)

Arguments

x

tibble()

min, max

colnames to pass to stats::runif() (shake_uniform_*)

within

colname to define which levels share new x values (*_within variants)

mean, sd

colnames to pass to stats::rnorm() (shake_gaussian_*)

Details

uniform considers that the actual x can be anytime between two temporal bounds. This is typically the case for ante quem data.

gaussian considers that the actual x is centered on a value but with an associated error. You can think of C^14 dating which is provided as and estimate and a standard deviation to expect around it.

For shake_uniform_*, min/max correspond to tpq/taq respectively. For shake_gaussian_*, mean/sd correspond to the single (best) x and its standard deviation.

Value

a 'shaken' tibble() with an additional x_new column

Functions

  • shake_uniform: generate new x values using uniform distribution

  • shake_uniform_within: shake_uniform within a group

  • shake_gaussian: generate new x values using gaussian distribution

  • shake_gaussian_within: shake_gaussian within a group

Examples

set.seed(2329) # replicability
# we will use builtin dummy df_u and df_g

# show uniform shaking
df_u # 'unshaken' data
df_u %>% shake_uniform(tpq, taq)  # new x values bounded between each tpq/taq
df_u %>% shake_uniform(tpq, taq)  # same idea, different values

# you can decide that new values must be stratified per site
# we create a df_u variant with equal tpq and taq per site (otherwise makes no sense)
df_u %>%
  dplyr::group_by(site) %>%
  dplyr::mutate(tpq=tpq[1], taq=taq[1]) %>% # first value defines all others
  dplyr::ungroup() -> df_u_site

# now compare
df_u_site %>% shake_uniform(tpq, taq)
df_u_site %>% shake_uniform_within(tpq, taq, within=site) # equal x_new within site

# gaussian shaking now
df_g # unshaken data
df_g %>% shake_gaussian(c14, sd1) # x_new is centered on c14 with gaussian noise (sd=sd1)
df_g %>% shake_gaussian(c14, sd1) # same idea, different values

# stratified version
# same approach as above, inherit from 1st value,
# to make a tibble that makes sense for *_within variant
df_g %>%
  dplyr::group_by(site) %>%
  dplyr::mutate(c14=c14[1], sd1=sd1[1]) %>%
  dplyr::ungroup() -> df_g_site

df_g_site %>% shake_gaussian_within(c14, sd1, site)


vbonhomme/pataqu documentation built on April 24, 2022, 10:03 p.m.