Skip to content

Commit

Permalink
equivalence_test, estimate_density
Browse files Browse the repository at this point in the history
[skip]
  • Loading branch information
mattansb committed Sep 5, 2024
1 parent 114f07d commit e49b705
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
20 changes: 18 additions & 2 deletions R/equivalence_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,24 @@ equivalence_test.numeric <- function(x, range = "default", ci = 0.95, verbose =


#' @rdname equivalence_test
#' @inheritParams p_direction
#' @export
equivalence_test.data.frame <- function(x, range = "default", ci = 0.95, verbose = TRUE, ...) {
equivalence_test.data.frame <- function(x, range = "default", ci = 0.95, rvar_col = NULL, verbose = TRUE, ...) {

obj_name <- insight::safe_deparse_symbol(substitute(x))

if (length(x_rvar <- .possibly_extract_rvar_col(x, rvar_col)) > 0L) {

Check warning on line 154 in R/equivalence_test.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/equivalence_test.R,line=154,col=14,[implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`.
cl <- match.call()
cl[[1]] <- bayestestR::equivalence_test
cl$x <- x_rvar
cl$rvar_col <- NULL
out <- eval.parent(cl)

attr(out, "object_name") <- sprintf('%s[["%s"]]', obj_name, rvar_col)

return(.append_datagrid(out, x))
}

l <- insight::compact_list(lapply(
x,
equivalence_test,
Expand All @@ -163,7 +179,7 @@ equivalence_test.data.frame <- function(x, range = "default", ci = 0.95, verbose
)
row.names(out) <- NULL

attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(x))
attr(out, "object_name") <- obj_name
class(out) <- unique(c("equivalence_test", "see_equivalence_test_df", class(out)))

out
Expand Down
23 changes: 23 additions & 0 deletions R/estimate_density.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ estimate_density.numeric <- function(x,


#' @rdname estimate_density
#' @inheritParams p_direction
#' @export
estimate_density.data.frame <- function(x,
method = "kernel",
Expand All @@ -232,7 +233,29 @@ estimate_density.data.frame <- function(x,
select = NULL,
by = NULL,
at = NULL,
rvar_col = NULL,
...) {

if (length(x_rvar <- .possibly_extract_rvar_col(x, rvar_col)) > 0L) {

Check warning on line 239 in R/estimate_density.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/estimate_density.R,line=239,col=14,[implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`.
cl <- match.call()
cl[[1]] <- bayestestR::estimate_density
cl$x <- x_rvar
cl$rvar_col <- NULL
out <- eval.parent(cl)

obj_name <- insight::safe_deparse_symbol(substitute(x))
attr(out, "object_name") <- sprintf('%s[["%s"]]', obj_name, rvar_col)

# This doesn't use .append_datagrid because we get a non-grid output
dgrid <- x[,vapply(x, function(col) !inherits(col, "rvar"), FUN.VALUE = logical(1)), drop = FALSE]
dgrid$Parameter <- unique(out$Parameter)
out <- datawizard::data_join(dgrid, out, by = "Parameter")
out$Parameter <- NULL
class(out) <- .set_density_class(out)
return(out)
}


# Sanity
if (!is.null(at)) {
insight::format_warning(paste0(
Expand Down
12 changes: 11 additions & 1 deletion man/equivalence_test.Rd

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

4 changes: 4 additions & 0 deletions man/estimate_density.Rd

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

0 comments on commit e49b705

Please sign in to comment.