Skip to content

Commit 3e48af9

Browse files
committed
init
1 parent ffda13b commit 3e48af9

10 files changed

Lines changed: 255 additions & 0 deletions

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export(logoddsratio_to_riskratio)
170170
export(mad_pooled)
171171
export(mahalanobis_d)
172172
export(means_ratio)
173+
export(med)
173174
export(nnt)
174175
export(nnt_to_arr)
175176
export(nnt_to_logoddsratio)

R/med.R

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#' Most Extreme Differences
2+
#'
3+
#' Compute the Most Extreme Differences effect sizes between two ECDFs. Pair
4+
#' with any reported Kolmogorov-Smirnov test ([`stats::ks.test()`]).
5+
#'
6+
#' @inheritParams cohens_d
7+
#' @param pdf a character string naming a cumulative distribution function or an
8+
#' actual cumulative distribution function such as `pnorm`. Only continuous
9+
#' CDFs are valid
10+
#' @param alternative a character string specifying the alternative hypothesis.
11+
#' This _does not_ control the type of CI returned, but the effect calculated;
12+
#' see [`stats::ks.test()`] for more details.
13+
#' @param ... for the default method, parameters of the distribution specified
14+
#' (as a character string) by `pdf`.
15+
#'
16+
#' @details Something...
17+
#'
18+
#' @inheritSection effectsize_CIs CIs and Significance Tests
19+
#' @inheritSection print.effectsize_table Plotting with `see`
20+
#'
21+
#' @return A data frame with the effect size `D` and its CI (`CI_low` and
22+
#' `CI_high`).
23+
#'
24+
#' @family standardized differences
25+
#'
26+
#' @examples
27+
#' x <- rnorm(50)
28+
#' y <- runif(30)
29+
#'
30+
#' # Do x and y come from the same distribution?
31+
#' ks.test(x, y)
32+
#' med(x, y)
33+
#'
34+
#' # Is the CDS of x larger than that of y?
35+
#' ks.test(x, y, alternative = "l")
36+
#' med(x, y, alternative = "l")
37+
#'
38+
#' plot(ecdf(x), xlim = range(c(x, y)), col = "blue")
39+
#' lines(ecdf(y), col = "red")
40+
#'
41+
#' # Does x come from a shifted gamma distribution with shape 3 and rate 2?
42+
#' ks.test(x+2, "pgamma", 3, 2)
43+
#' med(x+2, pdf = "pgamma", shape = 3, rate = 2)
44+
#'
45+
#' plot(ecdf(x + 2), xlim = range(x + 2), col = "blue")
46+
#' curve(pgamma(x, 3, 2), col = "red", add = TRUE)
47+
#'
48+
#'
49+
#' @export
50+
med <- function(
51+
x,
52+
y = NULL,
53+
data = NULL,
54+
pdf,
55+
mu = 0,
56+
reference = NULL,
57+
ci = 0.95,
58+
alternative = "two.sided",
59+
verbose = TRUE,
60+
...
61+
) {
62+
# if (.is_htest_of_type(x, "t-test")) {
63+
# return(effectsize(x, type = type, verbose = verbose, data = data, ...))
64+
# } else if (
65+
# .is_BF_of_type(x, c("BFoneSample", "BFindepSample"), "t-squared")
66+
# ) {
67+
# return(effectsize(x, ci = ci, verbose = verbose, ...))
68+
# }
69+
70+
alternative <- .match.alt(alternative)
71+
out <- .get_data_2_samples(
72+
x,
73+
y,
74+
data,
75+
reference = reference,
76+
verbose = verbose,
77+
...
78+
)
79+
x <- out[["x"]]
80+
y <- out[["y"]]
81+
82+
test <- stats::ks.test(x - mu, y %||% pdf, alternative = alternative, ...)
83+
84+
out <- data.frame(D = unname(test$statistic))
85+
86+
if (.test_ci(ci)) {
87+
# Add cis
88+
out$CI <- ci
89+
ci_level <- .adjust_ci(ci, alternative)
90+
alpha <- 1 - ci_level
91+
92+
if (is.null(y)) {
93+
n <- length(x)
94+
s <- sqrt(n)
95+
} else {
96+
n1 <- length(x)
97+
n2 <- length(y)
98+
s <- sqrt(n1 * n2 / (n1 + n2))
99+
}
100+
101+
conf_int <- out[["D"]] + c(-1, 1) * stats::qnorm(1 - alpha / 2) / s
102+
out$CI_low <- pmax(conf_int[1], 0)
103+
out$CI_high <- pmin(conf_int[2], 1)
104+
ci_method <- list(method = "normal")
105+
} else {
106+
ci_method <- alternative <- NULL
107+
}
108+
109+
class(out) <- c(
110+
"effectsize_difference",
111+
"effectsize_table",
112+
"see_effectsize_table",
113+
class(out)
114+
)
115+
.someattributes(out) <- .nlist(
116+
ci,
117+
mu,
118+
ci_method,
119+
alternative,
120+
approximate = FALSE
121+
)
122+
out
123+
}
124+

man/cohens_d.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mahalanobis_d.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/means_ratio.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/med.Rd

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/p_superiority.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/rank_biserial.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/repeated_measures_d.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

play with med.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
library(effectsize)
2+
3+
4+
5+

0 commit comments

Comments
 (0)