Skip to content

Commit

Permalink
Fixes #138
Browse files Browse the repository at this point in the history
  • Loading branch information
spsanderson committed Apr 8, 2022
1 parent 6344dda commit 1d2db90
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export(util_beta_param_estimate)
export(util_binomial_param_estimate)
export(util_cauchy_param_estimate)
export(util_cauchy_stats_tbl)
export(util_chisquare_stats_tbl)
export(util_exponential_param_estimate)
export(util_f_stats_tbl)
export(util_gamma_param_estimate)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ qq, quantile and probability plots to a single graph.
16. Fix #141 - Add function `util_cauchy_stats_tbl()`
17. Fix #140 - Add function `util_t_stats_tbl()`
18. Fix #139 - Add function `util_f_stats_tbl()`
19. Fix #138 - Add function `util_chisquare_stats_tbl()`

## Minor Fixes and Improvements
1. Fix #110 - Bug fix, correct the `p` calculation in `tidy_poisson()` that will
Expand Down
85 changes: 85 additions & 0 deletions R/stats-chisquare-tbl.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#' Distribution Statistics
#'
#' @family Chisquare
#' @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
#' tidy_chisquare() %>%
#' util_chisquare_stats_tbl()
#'
#' @return
#' A tibble
#'
#' @export
#'

util_chisquare_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_chisquare"){
rlang::abort(
message = "You must use 'tidy_chisquare()'",
use_cli_format = TRUE
)
}

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

atb <- attributes(data_tbl)

stat_mean <- atb$.df
stat_median <- (atb$.df - 2/3)
stat_mode <- ifelse(
atb$.df > 2,
atb$.df - 2,
"undefined"
)
stat_range = "0 to Inf"
stat_sd <- sqrt(2 * atb$.df)
stat_coef_var <- sqrt(2/atb$.df)
stat_skewness <- ((2^1.5) / sqrt(atb$.df))
stat_kurtosis <- 3 + (12/atb$.df)

# Data Tibble
ret <- tibble::tibble(
tidy_function = atb$tibble_type,
function_call = atb$dist_with_params,
distribution = atb$tibble_type %>%
stringr::str_remove("tidy_") %>%
stringr::str_to_title(),
distribution_type = atb$distribution_family_type,
points = atb$.n,
simulations = atb$.num_sims,
mean = stat_mean,
median = stat_median,
mode = stat_mode,
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)
)

# Return
return(ret)

}
3 changes: 3 additions & 0 deletions man/tidy_chisquare.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.

50 changes: 50 additions & 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_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_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.

1 change: 1 addition & 0 deletions 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_uniform_stats_tbl.Rd

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

0 comments on commit 1d2db90

Please sign in to comment.