Skip to contents

Fit a model by maximum a posteriori (the mode of the posterior formed from the model's own priors) and return a fit object carrying the parameter estimates, the Hessian-based covariance, and optimizer bookkeeping. Wraps the shared C++ MaximumAPosteriori ported from USACE-RMC RMC.BestFit.

Usage

fit_map(
  model,
  distribution = NULL,
  optimizer = "NelderMead",
  hessian = TRUE,
  profile = FALSE,
  profile_bins = 100
)

Arguments

model

a model_univariate() (or any model_*()) object, or a plain numeric vector of observations together with distribution. A model can bring censored observations (see analysis_data()), nonstationary trends (see trend()), and parameter bounds or priors (see model_parameter()).

distribution

distribution family name, required only when model is a numeric vector.

optimizer

one of "NelderMead" (default), "Brent", "BFGS", "Powell", "DifferentialEvolution", "MultilevelSingleLinkage".

hessian

logical; compute the covariance, standard errors and correlation. TRUE by default. A model with fewer than two parameters reports NaN for all three.

profile

logical; also compute the profile likelihood and profile confidence intervals. FALSE by default because each costs profile_bins * length(parameters) likelihood evaluations.

profile_bins

number of bins in each parameter's profile.

Value

An object of class corehydro_fit. When profile = TRUE, it also carries $profile, a named list (one entry per parameter, named to match coef()) of profile_bins-by-2 matrices with columns value and log_likelihood, the profile-likelihood grid confint()'s intervals are drawn from – plot a parameter's curve with e.g. plot(f$profile[[1]], type = "l"). Absent (NULL) when the fit was built with the default profile = FALSE. See fit_bayesian() for the Bayesian surface.

Examples

peaks <- c(12500, 15300, 8900, 22100, 18700, 14200, 9800, 28500, 17400, 11600)
f <- fit_map(model_univariate("LogPearsonTypeIII", peaks))
coef(f)
#>    Mean (of log) (µ) Std Dev (of log) (σ)    Skew (of log) (γ) 
#>            4.1704998            0.1446415            0.6291806 
AIC(f)
#> [1] 211.1519