stanoptimis: Optimize / importance sample a stan or ctStan model.

View source: R/stanoptimis.R

stanoptimisR Documentation

Optimize / importance sample a stan or ctStan model.

Description

Optimize / importance sample a stan or ctStan model.

Usage

stanoptimis(
  standata,
  sm,
  init = "random",
  initsd = 0.01,
  sampleinit = NA,
  deoptim = FALSE,
  estonly = FALSE,
  tol = 1e-08,
  decontrol = list(),
  stochastic = TRUE,
  priors = TRUE,
  carefulfit = TRUE,
  bootstrapUncertainty = FALSE,
  subsamplesize = 1,
  parsteps = c(),
  plot = FALSE,
  hessianType = "numerical",
  stochasticHessianSamples = 50,
  stochasticHessianEpsilon = 1e-05,
  is = FALSE,
  isloopsize = 1000,
  finishsamples = 1000,
  tdf = 10,
  chancethreshold = 100,
  finishmultiply = 5,
  verbose = 0,
  cores = 2,
  matsetup = NA,
  nsubsets = 100,
  stochasticTolAdjust = 1000
)

Arguments

standata

list object conforming to rstan data standards.

sm

compiled stan model object.

init

vector of unconstrained parameter values, or character string 'random' to initialise with random values very close to zero.

initsd

positive numeric specifying sd of normal distribution governing random sample of init parameters, if init='random' .

sampleinit

either NA, or an niterations * nparams matrix of samples to initialise importance sampling.

deoptim

Do first pass optimization using differential evolution? Slower, but better for cases with multiple minima / difficult optimization.

estonly

if TRUE,just return point estimates under $rawest subobject.

tol

objective tolerance.

decontrol

List of control parameters for differential evolution step, to pass to DEoptim.control.

stochastic

Logical. Use stochastic gradient descent instead of mize (bfgs) optimizer. Still experimental, worth trying for either robustness checks or problematic, high dimensional, nonlinear, problems.

priors

logical. If TRUE, a priors integer is set to 1 (TRUE) in the standata object – only has an effect if the stan model uses this value.

carefulfit

Logical. If TRUE, priors are always used for a rough first pass to obtain starting values when priors=FALSE

bootstrapUncertainty

Logical. If TRUE, subject wise gradient contributions are resampled to estimate the hessian, for computing standard errors or initializing importance sampling.

subsamplesize

value between 0 and 1 representing proportion of subjects to include in first pass fit.

parsteps

ordered list of vectors of integers denoting which parameters should begin fixed at zero, and freed sequentially (by list order). Useful for complex models, e.g. keep all cross couplings fixed to zero as a first step, free them in second step.

plot

Logical. If TRUE, plot iteration details. Probably slower.

hessianType

either 'numerical' or 'stochastic', the latter is experimental at present.

stochasticHessianSamples

number of samples to use for stochastic Hessian, if selected.

stochasticHessianEpsilon

SD of random samples for stochastic hessian, if selected.

is

Logical. Use importance sampling, or just return map estimates?

isloopsize

Number of samples of approximating distribution per iteration of importance sampling.

finishsamples

Number of samples to draw (either from hessian based covariance or posterior distribution) for final results computation.

tdf

degrees of freedom of multivariate t distribution. Higher (more normal) generally gives more efficent importance sampling, at risk of truncating tails.

chancethreshold

drop iterations of importance sampling where any samples are chancethreshold times more likely to be drawn than expected.

finishmultiply

Importance sampling stops once available samples reach finishsamples * finishmultiply , then the final samples are drawn without replacement from this set.

verbose

Integer from 0 to 2. Higher values print more information during model fit – for debugging.

cores

Number of cpu cores to use, should be at least 2.

matsetup

subobject of ctStanFit output. If provided, parameter names instead of numbers are output for any problem indications.

nsubsets

number of subsets for stochastic optimizer. Subsets are further split across cores, but each subjects data remains whole – processed by one core in one subset.

stochasticTolAdjust

Multiplier for stochastic optimizer tolerance.

Value

list containing fit elementsF


ctsem documentation built on Sept. 11, 2024, 9:06 p.m.