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

Add rvar_col argument to all *.data.frame() methods #666

Closed
wants to merge 4 commits into from
Closed
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
20 changes: 19 additions & 1 deletion R/p_direction.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#'
#' ## Methods of computation
#' The *pd* is defined as:
#' \deqn{p_d = max({Pr(\hat{\theta} < \theta_{null}), Pr(\hat{\theta} > \theta_{null})})}{pd = max(mean(x < null), mean(x > null))}

Check warning on line 70 in R/p_direction.R

View workflow job for this annotation

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

file=R/p_direction.R,line=70,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 131 characters.
#' \cr\cr
#' The most simple and direct way to compute the *pd* is to compute the
#' proportion of positive (or larger than `null`) posterior samples, the
Expand All @@ -89,7 +89,7 @@
#'
#' @seealso [pd_to_p()] to convert between Probability of Direction (pd) and p-value.
#'
#' @note There is also a [`plot()`-method](https://easystats.github.io/see/articles/bayestestR.html) implemented in the \href{https://easystats.github.io/see/}{\pkg{see}-package}.

Check warning on line 92 in R/p_direction.R

View workflow job for this annotation

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

file=R/p_direction.R,line=92,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 179 characters.
#'
#' @references
#' - Makowski, D., Ben-Shachar, M. S., Chen, S. A., & Lüdecke, D. (2019).
Expand Down Expand Up @@ -174,8 +174,26 @@


#' @rdname p_direction
#' @param rvar_col Name of an `rvar`-type column. If `NULL`, each column in the
#' data frame is assumed to represent draws from a posterior distribution.
#' @export
p_direction.data.frame <- function(x, method = "direct", null = 0, ...) {
p_direction.data.frame <- function(x, method = "direct", null = 0, rvar_col = NULL, ...) {
if (is.null(rvar_col)) {
return(.p_direction_df(x, method = method, null = null, ...))
}

if (length(rvar_col) != 1L && !rvar_col %in% colnames(x)) {
insight::format_error("The `rvar_col` argument must be a single, valid column name.")
}

out <- p_direction(x[[rvar_col]], method = method, null = null, ...)
x[["pd"]] <- out[["pd"]]
x
}


#' @keywords internal
.p_direction_df <- function(x, method = "direct", null = 0, ...) {
obj_name <- insight::safe_deparse_symbol(substitute(x))
x <- .select_nums(x)

Expand Down Expand Up @@ -352,7 +370,7 @@
#' @export
p_direction.stanreg <- function(x,
effects = c("fixed", "random", "all"),
component = c("location", "all", "conditional", "smooth_terms", "sigma", "distributional", "auxiliary"),

Check warning on line 373 in R/p_direction.R

View workflow job for this annotation

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

file=R/p_direction.R,line=373,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 136 characters.
parameters = NULL,
method = "direct",
null = 0,
Expand Down
2 changes: 1 addition & 1 deletion man/bayestestR-package.Rd

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

5 changes: 4 additions & 1 deletion man/p_direction.Rd

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

Loading