calc_ess {tracerer}R Documentation

Calculates the Effective Sample Size

Description

Calculates the Effective Sample Size

Usage

calc_ess(trace, sample_interval)

Arguments

trace

the values without burn-in

sample_interval

the interval in timesteps between samples

Value

the effective sample size

Author(s)

The original Java version of the algorithm was from Remco Bouckaert, ported to R and adapted by Richèl J.C. Bilderbeek

See Also

Java code can be found here: https://github.com/CompEvol/beast2/blob/9f040ed0357c4b946ea276a481a4c654ad4fff36/src/beast/core/util/ESS.java#L161 # nolint URLs can be long

Examples

  filename <- get_tracerer_path("beast2_example_output.log")

 # Parse the file as-is and conclude the sampling interval
 df <- parse_beast_log(filename)
 sample_interval <- df$Sample[2] - df$Sample[1] # nolint BEAST2 style

 # Only keep the parameter estimates,
 # do not care about the sampling times anymore
 estimates <- subset(df, select = -Sample) # nolint BEAST2 style

 esses <- rep(NA, ncol(estimates))
 burn_in_fraction <- 0.1
 for (i in seq_along(estimates)) {
   # Trace with the burn-in still present
   trace_raw <- as.numeric(t(estimates[i]))

   # Trace with the burn-in removed
   trace <- remove_burn_in(
     trace = trace_raw,
     burn_in_fraction = 0.1
   )

   # Store the effectice sample size
   esses[i] <- calc_ess(trace, sample_interval = sample_interval)
 }

 # Use the values that TRACER shows
 expected_esses <- c(10, 10, 10, 10, 7, 10, 9, 6)
 testit::assert(all(expected_esses - esses < 0.5))

[Package tracerer version 2.0.1 Index]