Learn R Programming

ctsem (version 3.11.0)

stanoptimis: 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,
  estonly = FALSE,
  tol = 1e-08,
  stochastic = TRUE,
  priors = TRUE,
  carefulfit = TRUE,
  uncertainty = "hessian",
  uncertaintyDraws = "auto",
  uncertaintyControl = list(),
  subsamplesize = 1,
  parsteps = c(),
  parstepsAutoModel = FALSE,
  groupFreeThreshold = 0.5,
  plot = FALSE,
  is = FALSE,
  isitersize = 1000,
  isESS = 100,
  finishsamples = 1000,
  lproughnesstarget = 0.2,
  verbose = 0,
  cores = 2,
  matsetup = NA,
  nsubsets = 10,
  stochasticTolAdjust = 1000
)

Value

list containing fit elements

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' .

estonly

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

tol

objective tolerance.

stochastic

Logical. Use stochastic gradient descent as main optimizer. Always finishes (double checks) with mize (bfgs) optimizer.

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

uncertainty

Character string selecting the optimized-fit uncertainty approximation. Options are 'hessian', 'surrogate', 'bootstrap', 'fullbootstrap', 'sandwich', and 'opg'.

uncertaintyDraws

Character string controlling approximate raw-parameter draws from the approximate uncertainty. 'auto' uses empirical draws for uncertainty='bootstrap' or uncertainty='fullbootstrap' and normal draws otherwise. 'normal' draws from a multivariate normal using the selected covariance, 'empirical' uses empirical draws when available, and 'imis' runs importance sampling.

uncertaintyControl

List of method-specific options passed to ctOptimUncertainty internals. Score-based methods use subject-level score contributions when there are at least two subjects; single-subject models warn and use case-level contributions. Score-based methods warn when there are fewer than ten independent subjects or no more score rows than raw parameters. Full bootstrap requires at least two subjects and warns below ten independent subjects. Bootstrap-style methods require at least two returned samples / refits.

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.

parstepsAutoModel

if TRUE, determines model structure for the parameters specified in parsteps automatically. If 'group', determines this on a group level first and then a subject level. Primarily for internal ctsem use, see ?ctFitAuto.

groupFreeThreshold

threshold for determining whether a parameter is free in a group level model. If the proportion of subjects with a non-zero parameter is above this threshold, the parameter is considered free. Only used with parstepsAutoModel = 'group'.

plot

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

is

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

isitersize

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

isESS

target effective sample size for importance sampling. If is=TRUE, this is used to determine the number of samples to draw from the approximating distribution.

finishsamples

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

lproughnesstarget

target log posterior roughness for stochastic optimizer (suggest between .05 and .4).

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.