| 1 |
#' @templateVar class fitdistr |
| 2 |
#' @template title_desc_tidy |
| 3 |
#' |
| 4 |
#' @param x A `fitdistr` object returned by [MASS::fitdistr()]. |
| 5 |
#' @template param_unused_dots |
| 6 |
#' |
| 7 |
#' @evalRd return_tidy("term", "estimate", "std.error") |
| 8 |
#' |
| 9 |
#' @examplesIf rlang::is_installed("MASS") |
| 10 |
#' |
| 11 |
#' # load libraries for models and data |
| 12 |
#' library(MASS) |
| 13 |
#' |
| 14 |
#' # generate data |
| 15 |
#' set.seed(2015) |
| 16 |
#' x <- rnorm(100, 5, 2) |
| 17 |
#' |
| 18 |
#' # fit models |
| 19 |
#' fit <- fitdistr(x, dnorm, list(mean = 3, sd = 1)) |
| 20 |
#' |
| 21 |
#' # summarize model fit with tidiers |
| 22 |
#' tidy(fit) |
| 23 |
#' glance(fit) |
| 24 |
#' |
| 25 |
#' @export |
| 26 |
#' @family fitdistr tidiers |
| 27 |
#' @aliases fitdistr_tidiers |
| 28 |
#' @seealso [tidy()], [MASS::fitdistr()] |
| 29 |
tidy.fitdistr <- function(x, ...) { |
| 30 |
tibble( |
| 31 |
term = names(x$estimate), |
| 32 |
estimate = unname(x$estimate), |
| 33 |
std.error = unname(x$sd) |
| 34 |
) |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
#' @templateVar class fitdistr |
| 39 |
#' @template title_desc_glance |
| 40 |
#' |
| 41 |
#' @inherit tidy.fitdistr params examples |
| 42 |
#' |
| 43 |
#' @evalRd return_glance("logLik", "AIC", "BIC", "nobs") |
| 44 |
#' |
| 45 |
#' @export |
| 46 |
#' @family fitdistr tidiers |
| 47 |
#' @seealso [tidy()], [MASS::fitdistr()] |
| 48 |
glance.fitdistr <- function(x, ...) { |
| 49 |
as_glance_tibble( |
| 50 |
logLik = stats::logLik(x), |
| 51 |
AIC = stats::AIC(x), |
| 52 |
BIC = stats::BIC(x), |
| 53 |
nobs = stats::nobs(x), |
| 54 |
na_types = "rrri" |
| 55 |
) |
| 56 |
} |