calc_ess: Calculates the Effective Sample Size

Description Usage Arguments Value Author(s) Examples

Description

Calculates the Effective Sample Size

Usage

1
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)

Richel J.C. Bilderbeek

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  filename <- system.file(
   "extdata", "beast2_example_output.log", package = "RBeast"
 )

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

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

 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 <- RBeast::remove_burn_in(trace = trace_raw, burn_in_fraction = 0.1)

   # Store the effectice sample size
   esses[i] <- RBeast::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))

beast-dev/RBeast documentation built on May 12, 2019, 10:02 a.m.