Skip to content

Commit

Permalink
Fixes #183
Browse files Browse the repository at this point in the history
Fixes #184
  • Loading branch information
spsanderson committed May 17, 2022
1 parent 6327885 commit b05d803
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ None

## Minor Fixes and Improvements
1. Fix #176 - Update `_autoplot` functions to include cumulative mean MCMC chart
by taking advantage of the `.num_sims` paramter of `tidy_` distribution
by taking advantage of the `.num_sims` parameter of `tidy_` distribution
functions.
2. Fix #184 - Update `tidy_empirical()` to add a parameter of `.distribution_type`
3. Fix #183 - `tidy_empirical()` is now again plotted by `_autoplot` functions.

# TidyDensity 1.1.0

Expand Down
23 changes: 16 additions & 7 deletions R/empirical-tidy.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,30 @@
#' The `y` column is set equal to `dy` from the density function.
#'
#' @param .x A vector of numbers
#' @param .distribution_type A string of either "continuous" or "discrete". The
#' function will default to "continuous"
#'
#' @examples
#' tidy_empirical(.x = 1:10)
#' tidy_empirical(.x = 1:10, .distribution_type = "continuous")
#' @return
#' A tibble
#'
#' @export
#'

tidy_empirical <- function(.x) {
tidy_empirical <- function(.x, .distribution_type = "continuous") {
x_term <- .x
n <- length(x_term)
dist_type <- tolower(as.character(.distribution_type))

if (!is.vector(x_term)) {
rlang::abort("You must pass a vector as the .x argument to this function.")
}

if (!dist_type %in% c("continuous","discrete")){
rlang::abort("You must choose either 'continuous' or 'discrete'.")
}

## New P
e <- stats::ecdf(x_term)

Expand All @@ -48,11 +55,13 @@ tidy_empirical <- function(.x) {
df <- df %>%
dplyr::mutate(q = q_vec$q)

attr(df, ".x") <- .x
attr(df, ".n") <- n
attr(df, ".num_sims") <- 1L
attr(df, "tibble_type") <- "tidy_empirical"
attr(df, "dist_with_params") <- "Empirical"
# Attach descriptive attributes to tibble
attr(df, "distribution_family_type") <- dist_type
attr(df, ".x") <- .x
attr(df, ".n") <- n
attr(df, ".num_sims") <- 1L
attr(df, "tibble_type") <- "tidy_empirical"
attr(df, "dist_with_params") <- "Empirical"

# Return ----
return(df)
Expand Down
7 changes: 5 additions & 2 deletions man/tidy_empirical.Rd

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

0 comments on commit b05d803

Please sign in to comment.