fit_model: fit_model

View source: R/fit_model.R

fit_modelR Documentation

fit_model

Description

run optimization algorithms from a variety of packages

Usage

fit_model(
  objective,
  start = NULL,
  lower = NULL,
  upper = NULL,
  hessian = FALSE,
  package = "optimx",
  method = NULL,
  restart = FALSE,
  consecutive = 0L,
  max_runs = Inf,
  sigma = 0.1,
  verbose = FALSE,
  n_pop = 50,
  opt_args = list(),
  obj_args = list(),
  aic = FALSE,
  bic = FALSE,
  n_obs = NULL,
  return_df = FALSE,
  return_all = FALSE,
  ...
)

Arguments

objective

function; the objective function to minimize

start

numeric vector; parameter vector. Default = NULL

lower

numeric vector; lower bounds on parameters. Default = NULL

upper

numeric vector; upper bounds on parameters. Default = NULL

hessian

logical; if TRUE, calculate hessian at final solution; Default = FALSE.

package

string; package to use for optimization, see Details. Default = "optimx"

method

string; method to use from the package (if applicable, see Details for options). Default = NULL (use method default for package)

restart

logical; if TRUE, restart optimization until no more improvement. Only applicable for package = optimx, nloptr, & pracma. Default = FALSE

max_runs

integer; maximum number of optimx runs. Only applicable for package = optimx, nloptr, & pracma. Default = Inf

sigma

numeric vector; standard deviation to perturb starting values. For packages = optimx, nloptr, pracma, if consecutive > 0, will perturb start values before each successive run. For packages = DEoptim, RcppDE, GA, used to create random initial population (with specified starting values). Default = 0.1

verbose

logical; if TRUE, print progress statements. Only applicable for packages = optimx, nloptrm, pracma. Default=FALSE

n_pop

numeric vector; size of population. Only applicable for package = RcppDE, DEoptim, GA. Default = 50, recommended to be 10 * n parameters.

opt_args

list; further arguments passed to fitting method

obj_args

list; further arguments passed to objective function

aic

logical; if TRUE, calculate Akaike Information Criterion. Default = FALSE

bic

logical; if TRUE, calculate Bayes Information Criterion. Default = FALSE

n_obs

integer; the number of observations (used to calculate BIC). Default = NULL

return_df

logical; if TRUE, return results as a data frame

return_all

logical; if TRUE, return list of results from modelfitr AND results from the package used to fit the model

...

further arguments passed to objective function (similar to obj_args)

conescutive

integer; stop after this number of consecutive runs without improvement. Only applicable for package = optimx, nloptr, & pracma. Default = 0

Details

Still under developement...

Package options = "optimx", "nloptr", "pracma", "GenSA", "rgenoud", "GA", "DEoptim", "RcppDE".
Others are implemented but no guarantees.
Further documentation coming soon.

Value

if return_df = FALSE and return_all = FALSE (default), returns a list containing the following fields:

pars

parameter values

value

the value of the objective function at the solution

hess

if hessian=TRUE, the hessian matrix at the solution, otherwise NA

convergence

if hessian=TRUE, convergence = TRUE if the hessian is positive definite, otherwise FALSE. if hessian = FALSE, convergence = NA

code

the message or code returned by the optimization method if applicable, otherwise NA

if aic = TRUE and/or bic = TRUE, list also contains:

aic

the aic for the model

bic

the bic for the model

if return_df = TRUE, returns a data frame instead of a list. This data frame has 1 row and columns for:

  • each parameter

  • value

  • covergence

  • code

  • aic - if applicable

  • bic - if applicable

if return_all = TRUE, returns a list containing:

  • the list or data frame as described above

  • the direct output from the optimization method


gkane26/modelfitr documentation built on March 21, 2022, 10:52 a.m.