Created
March 8, 2021 22:09
-
-
Save bwiernik/4ad429d7deeb6aa8b0a44d3a5e569835 to your computer and use it in GitHub Desktop.
S3 dispatch examples for R packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(psychmeta) | |
ma_obj <- ma_r(rxyi = rxyi, n = n, rxx = rxxi, ryy = ryyi, | |
construct_x = x_name, construct_y = y_name, sample_id = sample_id, | |
moderators = moderator, data = data_r_meas_multi) | |
summary(ma_obj) | |
class(ma_obj) | |
inherits(ma_obj, "ma_psychmeta") | |
inherits(ma_obj, "ma_table") | |
inherits(ma_obj, "data.frame") | |
print <- function (x, ...) { | |
UseMethod("print") | |
} | |
#' @export | |
#' @keywords internal | |
#' @method print ad_tsa | |
print.ad_tsa <- function(x, ..., digits = 3){ | |
cat("Taylor-Series Artifact Distributions\n") | |
cat("------------------------------------\n") | |
print(round(as.matrix(x[,]), digits = digits)) | |
cat("\n") | |
invisible(x) | |
} | |
# S3method(print,ad_tsa) | |
# export(adjust_n_d) | |
#' @export | |
#' @importFrom dplyr filter_if | |
#' @method filter_if ma_psychmeta | |
filter_if.ma_psychmeta <- function(.tbl, predicate, .vars_predicate){ | |
original <- .tbl | |
modified <- NextMethod() | |
modified <- reattribute(x = original, result = modified) | |
return(modified) | |
} | |
test <- t.test(1:10, y = c(7:20), var.equal = TRUE) | |
class(test) | |
#' @export | |
effectsize <- function(object, ...) { | |
UseMethod("effectsize") | |
} | |
#' @export | |
#' @method effectsize htest | |
effectsize.htest <- function(object, ..., n1 = NULL, n2 = NULL, prop = NULL) { | |
if (is.null(prop)) { | |
if (! (is.null(n1) && is.null(n2))) { | |
prop <- n1 / sum(n1, n1) | |
} else { | |
prop <- .5 | |
} | |
} | |
stat <- object$statistic | |
df <- object$parameter | |
N <- df + 2 | |
a <- 1 / (prop * (1 - prop)) | |
eff_size <- stat * sqrt(a / N) | |
conf_int <- ci_cohen_d(...) | |
out <- list(eff_size = eff_size, conf_int = conf_int) | |
class(out) <- "es_mote" | |
return(out) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment