Learn R Programming

topolow (version 1.0.0)

profile_likelihood: Profile Likelihood Analysis

Description

Calculates profile likelihood for a parameter by evaluating conditional maximum likelihood across a grid of parameter values. Uses local sample windowing to estimate conditional likelihoods. This implementation is not a classical profile likelihood calculation, but rather an "empirical profile likelihood" which estimates the profile likelihood at each point based on the many observations previously sampled in 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
)

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

Arguments

param

Character name of parameter to analyze

samples

Data frame containing parameter samples and log-likelihoods

grid_size

Integer number of grid points (default: 48)

bandwidth_factor

Numeric factor for local sample window (default: 0.03)

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 bandwidth window

  2. Calculates conditional maximum likelihood from these samples

  3. Tracks sample counts to assess estimate reliability

  4. Handles boundary conditions and sparse regions

See Also

plot.profile_likelihood for visualization

Examples

Run this code
# Create a sample data frame of MCMC 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 parameter "log_N"
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)

Run the code above in your browser using DataLab