Learn R Programming

rstan (version 2.8.2)

optimizing-methods: optimizing: obtain a point estimate by maximizing the joint posterior

Description

Obtain a point estimate by maximizing the joint posterior from the model defined by class stanmodel. This method is a generic function of the S4 class stanmodel.

Usage

## S3 method for class 'stanmodel':
optimizing(object, data = list(), 
    seed = sample.int(.Machine$integer.max, 1), init = 'random', 
    check_data = TRUE, sample_file = NULL, 
    algorithm = c("LBFGS", "BFGS", "Newton"),
    verbose = FALSE, hessian = FALSE, as_vector = TRUE, 
    draws = 0, constrained = TRUE, ...)

Arguments

object
An object of class stanmodel.
data
A named list or environment providing the data for the model or a character vector for all the names of objects used as data. See the notes in stan.
seed
The seed for random number generation. The default is generated from 1 to the maximum integer supported by Ron the machine. When a seed is specified by a number, as.integer will be applied to it. If as.integer produc
init
One of digit 0, string "0" or "random", a function that returns a list, or a named list of initial parameter values. "0": initialize all to be zero on the unconstrained support; "
check_data
Logical: if TRUE, the data would be preprocessed; otherwise not. If the data is not checked and preprocessed, it is safe to leave it to be the default TRUE. See the notes in stan

Value

  • A list with components if the optimization is done successfully:
  • parThe point estimate found. Its form (vector or list) is determined by argument as_vector.
  • valueThe value of the log-posterior (up to an additive constant, the "lp__" in Stan) corresponding to par.
  • hessianThe Hessian matrix if hessian is TRUE
  • theta_tildeThe matrix of parameter draws in the unconstrained space, if draws > 0
  • log_pIf draws > 0, a vector of length draws that contains the value of the log-posterior evaluated at each row of theta_tilde
  • log_gIf draws > 0, a vector of length draws that contains the value of the logarithm of the multivariate normal density evaluated at each row of theta_tilde
  • If the optimization is not finished for reasons such as feeding wrong data, it returns NULL.

See Also

stanmodel

Examples

Run this code
m <- stan_model(model_code = 'parameters {real y;} model {y ~ normal(0,1);}')
f <- optimizing(m, hessian = TRUE)

Run the code above in your browser using DataLab