Skip to content

Commit

Permalink
Fixes #48
Browse files Browse the repository at this point in the history
  • Loading branch information
spsanderson committed Feb 9, 2022
1 parent f176d2a commit 5aa1666
Show file tree
Hide file tree
Showing 79 changed files with 1,309 additions and 370 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(enquos)
export(tidy_autoplot)
export(tidy_beta)
export(tidy_binomial)
export(tidy_burr)
export(tidy_cauchy)
export(tidy_chisquare)
export(tidy_distribution_summary_tbl)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ None
15. Fix #38 - Add function `tidy_inverse_exponential()`
16. Fix #45 - Add function `tidy_inverse_gamma()`
17. Fix #46 - Add function `tidy_inverse_weibull()`
18. Fix #48 - Add function `tidy_burr()`

## Fixes and Minor Improvements
1. Fix #30 - Move `crayon`, `rstudioapi`, and `cli` from Suggests to Imports due to `pillar`
Expand Down
5 changes: 3 additions & 2 deletions R/autoplot-density.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ tidy_autoplot <- function(.data, .plot_type = "density", .line_size = .5,
"tidy_zero_truncated_binomial", "tidy_zero_truncated_negative_binomial",
"tidy_pareto_single_parameter", "tidy_pareto", "tidy_inverse_pareto",
"tidy_generalized_pareto","tidy_paralogistic", "tidy_inverse_exponential",
"tidy_inverse_gamma","tidy_inverse_weibull"
"tidy_inverse_gamma","tidy_inverse_weibull","tidy_burr"
)) {
rlang::abort("The data passed must come from a `tidy_` distribution function.")
}
Expand Down Expand Up @@ -154,7 +154,8 @@ tidy_autoplot <- function(.data, .plot_type = "density", .line_size = .5,
paste0("Shape: ", atb$.shape, " - Min: ", atb$.min)
} else if (atb$tibble_type %in% c("tidy_pareto", "tidy_inverse_pareto")) {
paste0("Shape: ", atb$.shape, " - Scale: ", atb$.scale)
} else if (atb$tibble_type %in% c("tidy_generalized_pareto")){
} else if (atb$tibble_type %in% c("tidy_generalized_pareto",
"tidy_burr")){
paste0(
"Shape1: ", atb$.shape1, " - ",
"Shape2: ", atb$.shape2, " - ",
Expand Down
3 changes: 2 additions & 1 deletion R/autoplot-randomwalk.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ tidy_random_walk_autoplot <- function(.data, .line_size = 1, .geom_rug = FALSE,
paste0("Shape: ", atb$all$.shape, " - Min: ", atb$all$.min)
} else if (atb$all$tibble_type %in% c("tidy_pareto", "tidy_inverse_pareto")) {
paste0("Shape: ", atb$all$.shape, " - Scale: ", atb$all$.scale)
} else if (atb$all$tibble_type %in% c("tidy_generalized_pareto")){
} else if (atb$all$tibble_type %in% c("tidy_generalized_pareto",
"tidy_burr")){
paste0(
"Shape1: ", atb$all$.shape1, " - ",
"Shape2: ", atb$all$.shape2, " - ",
Expand Down
3 changes: 2 additions & 1 deletion R/random-tidy-beta.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Tidy Randomly Generated Beta Distribution Tibble
#'
#' @family Data Generator
#' @family Continuous Distribution
#' @family Beta
#'
#' @author Steven P. Sanderson II, MPH
#'
Expand Down
121 changes: 121 additions & 0 deletions R/random-tidy-burr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#' Tidy Randomly Generated Burr Distribution Tibble
#'
#' @family Continuous Distribution
#' @family Burr
#'
#' @author Steven P. Sanderson II, MPH
#'
#' @seealso \url{https://openacttexts.github.io/Loss-Data-Analytics/C-SummaryDistributions.html}
#'
#' @details This function uses the underlying `actuar::rburr()`, and its underlying
#' `p`, `d`, and `q` functions. For more information please see [actuar::rburr()]
#'
#' @description This function will generate `n` random points from a Burr
#' distribution with a user provided, `.shape1`, `.shape2`, `.scale`, `.rate`, and number of
#' random simulations to be produced. The function returns a tibble with the
#' simulation number column the x column which corresponds to the n randomly
#' generated points, the `d_`, `p_` and `q_` data points as well.
#'
#' The data is returned un-grouped.
#'
#' The columns that are output are:
#'
#' - `sim_number` The current simulation number.
#' - `x` The current value of `n` for the current simulation.
#' - `y` The randomly generated data point.
#' - `dx` The `x` value from the [stats::density()] function.
#' - `dy` The `y` value from the [stats::density()] function.
#' - `p` The values from the resulting p_ function of the distribution family.
#' - `q` The values from the resulting q_ function of the distribution family.
#'
#' @param .n The number of randomly generated points you want.
#' @param .shape1 Must be strictly positive.
#' @param .shape2 Must be strictly positive.
#' @param .scale Must be strictly positive.
#' @param .rate An alternative way to specify the `.scale`.
#' @param .num_sims The number of randomly generated simulations you want.
#'
#' @examples
#' tidy_burr()
#' @return
#' A tibble of randomly generated data.
#'
#' @export
#'

tidy_burr <- function(.n = 50, .shape1 = 1, .shape2 = 1, .rate = 1,
.scale = 1/.rate, .num_sims = 1) {

# Tidyeval ----
n <- as.integer(.n)
num_sims <- as.integer(.num_sims)
shape1 <- as.numeric(.shape1)
shape2 <- as.numeric(.shape2)
scale <- as.numeric(.scale)
rate <- as.numeric(.rate)

# Checks ----
if (!is.integer(n) | n < 0) {
rlang::abort(
"The parameters '.n' must be of class integer. Please pass a whole
number like 50 or 100. It must be greater than 0."
)
}

if (!is.integer(num_sims) | num_sims < 0) {
rlang::abort(
"The parameter `.num_sims' must be of class integer. Please pass a
whole number like 50 or 100. It must be greater than 0."
)
}

if (!is.numeric(shape1) | !is.numeric(shape2) | !is.numeric(scale) | !is.numeric(rate)) {
rlang::abort(
"The parameters of '.shape1', '.shape2', '.rate', and '.scale' must be of class numeric."
)
}

if (shape1 <= 0 | shape2 <= 0 | rate <= 0 | scale <= 0) {
rlang::abort(
"The parameters of '.shape1', '.shape2', '.rate', and '.scale' must be greater than 0."
)
}

x <- seq(1, num_sims, 1)

ps <- seq(-n, n - 1, 2)
qs <- seq(0, 1, (1 / (n - 1)))

df <- dplyr::tibble(sim_number = as.factor(x)) %>%
dplyr::group_by(sim_number) %>%
dplyr::mutate(x = list(1:n)) %>%
dplyr::mutate(y = list(actuar::rburr(n = n, shape1 = shape1,
shape2 = shape2, rate = rate,
scale = scale))) %>%
dplyr::mutate(d = list(density(unlist(y), n = n)[c("x", "y")] %>%
purrr::set_names("dx", "dy") %>%
dplyr::as_tibble())) %>%
dplyr::mutate(p = list(actuar::pburr(ps, shape1 = shape1,
shape2 = shape2, rate = rate,
scale = scale))) %>%
dplyr::mutate(q = list(actuar::qburr(qs, shape1 = shape1,
shape2 = shape2, rate = rate,
scale = scale))) %>%
tidyr::unnest(cols = c(x, y, d, p, q)) %>%
dplyr::ungroup()


# Attach descriptive attributes to tibble
attr(df, ".shape1") <- .shape1
attr(df, ".shape2") <- .shape2
attr(df, ".scale") <- .scale
attr(df, ".rate") <- .rate
attr(df, ".n") <- .n
attr(df, ".num_sims") <- .num_sims
attr(df, "tibble_type") <- "tidy_burr"
attr(df, "ps") <- ps
attr(df, "qs") <- qs

# Return final result as function output
return(df)
}
3 changes: 2 additions & 1 deletion R/random-tidy-cauchy.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Tidy Randomly Generated Cauchy Distribution Tibble
#'
#' @family Data Generator
#' @family Continuous Distribution
#' @family Cauchy
#'
#' @author Steven P. Sanderson II, MPH
#'
Expand Down
3 changes: 2 additions & 1 deletion R/random-tidy-chisquare.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Tidy Randomly Generated Chisquare (Non-Central) Distribution Tibble
#'
#' @family Data Generator
#' @family Continuous Distribution
#' @family Chisquare
#'
#' @author Steven P. Sanderson II, MPH
#'
Expand Down
3 changes: 2 additions & 1 deletion R/random-tidy-f.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Tidy Randomly Generated F Distribution Tibble
#'
#' @family Data Generator
#' @family Continuous Distribution
#' @family F Distribution
#'
#' @author Steven P. Sanderson II, MPH
#'
Expand Down
3 changes: 2 additions & 1 deletion R/random-tidy-geom.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Tidy Randomly Generated Geometric Distribution Tibble
#'
#' @family Data Generator
#' @family Continuous Distribution
#' @family Geometric
#'
#' @author Steven P. Sanderson II, MPH
#'
Expand Down
3 changes: 2 additions & 1 deletion R/random-tidy-hypergeometric.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Tidy Randomly Generated Hypergeometric Distribution Tibble
#'
#' @family Data Generator
#' @family Continuous Distribution
#' @family Hypergeometric
#'
#' @author Steven P. Sanderson II, MPH
#'
Expand Down
3 changes: 2 additions & 1 deletion R/random-tidy-lognormal.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Tidy Randomly Generated Lognormal Distribution Tibble
#'
#' @family Data Generator
#' @family Continuous Distribution
#' @family Lognormal
#'
#' @author Steven P. Sanderson II, MPH
#'
Expand Down
3 changes: 2 additions & 1 deletion R/random-tidy-normal.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Tidy Randomly Generated Gaussian Distribution Tibble
#'
#' @family Data Generator
#' @family Continuous Distribution
#' @family Gaussian
#'
#' @author Steven P. Sanderson II, MPH
#'
Expand Down
3 changes: 2 additions & 1 deletion R/random-tidy-uniform.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Tidy Randomly Generated Uniform Distribution Tibble
#'
#' @family Data Generator
#' @family Continuous Distribution
#' @family Uniform
#'
#' @author Steven P. Sanderson II, MPH
#'
Expand Down
1 change: 0 additions & 1 deletion R/random-tidy-weibull.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#'
#' @family Continuous Distribution
#' @family Weibull
#' @family Inverse Distribution
#'
#' @author Steven P. Sanderson II, MPH
#'
Expand Down
24 changes: 12 additions & 12 deletions docs/articles/getting-started.html

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

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/news/index.html

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

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ pkgdown: 2.0.2
pkgdown_sha: ~
articles:
getting-started: getting-started.html
last_built: 2022-02-09T16:38Z
last_built: 2022-02-09T20:21Z

Binary file modified docs/reference/Rplot002.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/tidy_autoplot-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/tidy_autoplot-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5aa1666

Please sign in to comment.