Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #471 #489

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export(util_weibull_param_estimate)
export(util_weibull_stats_tbl)
export(util_zero_truncated_poisson_aic)
export(util_zero_truncated_poisson_param_estimate)
export(util_zero_truncated_poisson_stats_tbl)
export(util_ztn_binomial_param_estimate)
export(util_ztn_binomial_stats_tbl)
importFrom(data.table,.SD)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ None
1. #468 - Add function `util_negative_binomial_aic()` to calculate the AIC for the negative binomial distribution.
2. #470 - Add function `util_ztn_binomial_param_estimate()` and `util_rztnbinom_aic()` to estimate the parameters and calculate the AIC for the zero-truncated negative binomial distribution. Also added `util_ztn_binomial_stats_tbl()`
3. #467 - Add function `util_zero_truncated_poisson_param_estimate()` to estimate
the parameters of the zero-truncated Poisson distribution.
the parameters of the zero-truncated Poisson distribution. Add function `util_zero_truncated_poisson_aic()` to calculate the AIC for the zero-truncated Poisson distribution. Add function `util_zero_truncated_poisson_stats_tbl()` to create a summary table of the zero-truncated Poisson distribution.
4. #472 - Add function `util_f_param_estimate()` and `util_f_aic()` to estimate the parameters and calculate the AIC for the F distribution.

## Minor Improvements and Fixes
Expand Down
86 changes: 86 additions & 0 deletions R/stats-ztpoisson-tbl.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#' Distribution Statistics
#'
#' @family Poisson
#' @family Zero Truncated
#' @family Distribution Statistics
#'
#' @author Steven P. Sanderson II, MPH
#'
#' @details This function will take in a tibble and returns the statistics
#' of the given type of `tidy_` distribution. It is required that data be
#' passed from a `tidy_` distribution function.
#'
#' @description Returns distribution statistics in a tibble.
#'
#' @param .data The data being passed from a `tidy_` distribution function.
#'
#' @examples
#' library(dplyr)
#'
#' tidy_zero_truncated_poisson() |>
#' util_zero_truncated_poisson_stats_tbl() |>
#' glimpse()
#'
#' @return
#' A tibble
#'
#' @name util_zero_truncated_poisson_stats_tbl
NULL

#' @export
#' @rdname util_zero_truncated_poisson_stats_tbl

util_zero_truncated_poisson_stats_tbl <- function(.data) {

# Immediate check for tidy_ distribution function
if (!"tibble_type" %in% names(attributes(.data))) {
rlang::abort(
message = "You must pass data from the 'tidy_dist' function.",
use_cli_format = TRUE
)
}

if (attributes(.data)$tibble_type != "tidy_zero_truncated_poisson") {
rlang::abort(
message = "You must use 'tidy_zero_truncated_poisson()'",
use_cli_format = TRUE
)
}

# Data
data_tbl <- dplyr::as_tibble(.data)

atb <- attributes(data_tbl)
l <- atb$.lambda

stat_mean <- l
stat_mode <- floor(l)
stat_sd <- sqrt(l)
stat_skewness <- 1 / sqrt(l)
stat_kurtosis <- 3 + (1 / l)
stat_coef_var <- 1 / sqrt(l)

# Data Tibble
ret <- dplyr::tibble(
tidy_function = atb$tibble_type,
function_call = atb$dist_with_params,
distribution = dist_type_extractor(atb$tibble_type),
distribution_type = atb$distribution_family_type,
points = atb$.n,
simulations = atb$.num_sims,
mean = stat_mean,
mode = stat_mode,
range = paste0("1 to Inf"),
std_dv = stat_sd,
coeff_var = stat_coef_var,
skewness = stat_skewness,
kurtosis = stat_kurtosis,
computed_std_skew = tidy_skewness_vec(data_tbl$y),
computed_std_kurt = tidy_kurtosis_vec(data_tbl$y),
ci_lo = ci_lo(data_tbl$y),
ci_hi = ci_hi(data_tbl$y)
)

# Return
return(ret)
}
3 changes: 2 additions & 1 deletion man/tidy_poisson.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/tidy_zero_truncated_poisson.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_bernoulli_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_beta_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_binomial_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_burr_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_cauchy_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_chisquare_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_exponential_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_f_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_gamma_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_geometric_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_hypergeometric_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_logistic_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_lognormal_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_negative_binomial_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_normal_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_pareto_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/util_poisson_param_estimate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/util_poisson_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_t_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_triangular_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_uniform_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/util_weibull_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/util_zero_truncated_poisson_param_estimate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions man/util_zero_truncated_poisson_stats_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading