This is an internal helper function that generates a sum of squares cost function for any given r* function (e.g. rnorm, rlognorm). The resulting function is intended to be used by an optim call for fitting quantiles to distribution parameters.

generate_cost_function(func)

Arguments

func

A distribution function.

Value

A function.

See also

Other distribution fitting functions: combine_lognorm_trunc, combine_lognorm, combine_norm, fit_capabilities_geomean, fit_capabilities, fit_lognorm_trunc, fit_lognorm, fit_norm_trunc, fit_pois, fit_scenarios_geomean, fit_scenarios, fit_threat_communities, lognormal_to_normal, normal_to_lognormal

Examples

generate_cost_function(stats::qlnorm)
#> function(x, quant, est, ...) { #> x1 <- x[1] #> x2 <- x[2] #> if (x1 < 0 | x2 < 0) return(NA) #> sum( (rlang::get_expr(func)(quant, x1, x2, ...) - est)^2) #> } #> <environment: 0xe12dc38>