profile_likelihood: Profile Likelihood Analysis

View source: R/adaptive_sampling.R

profile_likelihoodR Documentation

Profile Likelihood Analysis

Description

Calculates the profile likelihood for a given parameter by evaluating the conditional maximum likelihood across a grid of parameter values. This "empirical profile likelihood" estimates the likelihood surface based on samples from Monte Carlo simulations.

Usage

profile_likelihood(
  param,
  samples,
  grid_size = 40,
  bandwidth_factor = 0.05,
  start_factor = 0.5,
  end_factor = 1.5,
  min_samples = 5
)

Arguments

param

The character name of the parameter to analyze (e.g., "log_N").

samples

A data frame containing parameter samples and a log-likelihoods column named "NLL".

grid_size

The integer number of grid points for the analysis.

bandwidth_factor

A numeric factor for the local sample window size.

start_factor, end_factor

Numeric range multipliers for parameter grid (default: 0.5, 1.2)

min_samples

Integer minimum samples required for reliable estimate (default: 10)

Details

For each value in the parameter grid, the function:

  1. Identifies nearby samples using a bandwidth window.

  2. Calculates the conditional maximum likelihood from these samples.

  3. Tracks sample counts to assess the reliability of the estimate.

Value

Object of class "profile_likelihood" containing:

param

Vector of parameter values

ll

Vector of log-likelihood values

param_name

Name of analyzed parameter

bandwidth

Bandwidth used for local windows

sample_counts

Number of samples per estimate

See Also

The S3 methods print.profile_likelihood and summary.profile_likelihood for viewing results.

Examples

# Create a sample data frame of parameter samples
mcmc_samples <- data.frame(
  log_N = log(runif(50, 2, 10)),
  log_k0 = log(runif(50, 1, 5)),
  log_cooling_rate = log(runif(50, 0.01, 0.1)),
  log_c_repulsion = log(runif(50, 0.1, 1)),
  NLL = runif(50, 20, 100)
)

# Calculate profile likelihood for the "log_N" parameter
pl <- profile_likelihood("log_N", mcmc_samples,
                         grid_size = 10, # Smaller grid for a quick example
                         bandwidth_factor = 0.05)

# Print the results
print(pl)


topolow documentation built on Aug. 31, 2025, 1:07 a.m.