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

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) #> } #> <bytecode: 0x7feca5b7d838> #> <environment: 0x7fec871cca90>