Skip to contents

Sample from the grid

Usage

sample_grid(
  grid,
  n_samples = 2000L,
  prior_h = NULL,
  prior_psi = c(0.25, 0.5, 0.25),
  seed = NULL
)

Arguments

grid

A data.frame containing validated grid-cell summaries with Cell, objective/nll, h, psi, and optional m0/m10 or fixed_m0/fixed_m10 columns. A legacy list of fitted objects from run_grid() is also accepted for compatibility.

n_samples

Integer specifying the number of samples to draw from the grid. Default is 2000.

prior_h

Optional numeric prior weights for the unique steepness values. If NULL, equal weights are used.

prior_psi

Optional numeric prior weights for the unique psi values. Default is c(0.25, 0.5, 0.25).

seed

Optional integer random seed for reproducible grid-cell sampling.

Value

A list with three elements:

grid_cells

Integer vector of length n_samples indicating which grid cells were sampled.

grid_freq

A tibble summarising the frequency of each grid cell in the sample, including columns for Cell, nll, m0, m10, h, psi, and Freq.

grid_prob

A tibble containing the sampling probabilities.

Details

The current data-frame route samples deterministic MLE cells using relative likelihood and structural-prior weights. It is not the balanced posterior-draw allocation used by grid_mcmc_to_tmbfit(). Supplying seed calls set.seed() and does not restore the caller's prior random-number state. The list-object route assumes the historical direct-anchor M0/M10 parameterization and is retained only for compatibility.