It would be helpful if tidy_optim() supported summarizing the Hessian, if present.
library(broom)
tidy_optim <- function(x, ...) {
if (is.null(names(x$par))) {
names(x$par) <- paste0("parameter", seq_along(x$par))
}
ret <- tibble(parameter = names(x$par), value = unname(x$par))
if ("hessian" %in% names(x)) {
ret$std.error <- sqrt(diag(solve(x$hessian)))
}
ret
}
r <- function(x) (3 - x[1])^2 + 4 * (x[2] - x[1]^2)^2
res <- optim(1:2, r)
tidy_optim(res)
#> Error in tibble(parameter = names(x$par), value = unname(x$par)): could not find function "tibble"
resH <- optim(1:2, r, hessian=TRUE)
tidy_optim(resH)
#> Error in tibble(parameter = names(x$par), value = unname(x$par)): could not find function "tibble"
Created on 2018-11-16 by the reprex package (v0.2.0).
(As mentioned in #505)
It would be helpful if
tidy_optim()supported summarizing the Hessian, if present.Created on 2018-11-16 by the reprex package (v0.2.0).
(As mentioned in #505)