Skip to content

Commit 13b46a6

Browse files
authored
deal with alternative = NULL (#555)
* init * Apply automatic changes * fix tests * Apply automatic changes * [skip ci] Co-authored-by: mattansb <[email protected]>
1 parent 1b8ad84 commit 13b46a6

14 files changed

+95
-72
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: effectsize
33
Title: Indices of Effect Size
4-
Version: 0.8.2.6
4+
Version: 0.8.2.10
55
Authors@R:
66
c(person(given = "Mattan S.",
77
family = "Ben-Shachar",

NEWS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# effectsize 0.8.2.xxx
22

3+
## Changes
4+
5+
- `mahalanobis_d()` now defaults to one-sided CIs.
6+
37
## New features
48

59
- `means_ratio()` for computing ratios of two means for ratio-scales outcomes (thanks to @arcaldwell49!)
@@ -23,7 +27,7 @@
2327

2428
## Changes
2529

26-
- cohens_w() has an exact upper bound when used as an effect size for goodness-of-fit.
30+
- `cohens_w()` has an exact upper bound when used as an effect size for goodness-of-fit.
2731

2832
## Bug fixes
2933

R/convert_stat_chisq.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ phi_to_chisq <- function(phi, n, ...) {
326326
.chisq_to_generic_phi <- function(chisq, den, nrow, ncol,
327327
ci = NULL, alternative = "greater",
328328
...) {
329-
alternative <- .match.alt(alternative)
329+
alternative <- .match.alt(alternative, FALSE)
330330

331331
if (ci_numeric <- .test_ci(ci)) {
332332
is_goodness <- ncol == 1 || nrow == 1

R/convert_stat_to_anova.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ F_to_omega2 <- function(f, df, df_error,
183183
#' @rdname F_to_eta2
184184
#' @export
185185
t_to_omega2 <- function(t, df_error,
186-
ci = 0.95, alternative = "greater", ...) {
186+
ci = 0.95, alternative = "greater",
187+
...) {
187188
F_to_omega2(t^2, 1, df_error,
188189
ci = ci, alternative = alternative,
189190
...
@@ -274,7 +275,7 @@ t_to_f2 <- function(t, df_error,
274275
es = "eta2",
275276
ci = 0.95, alternative = "greater",
276277
verbose = TRUE, ...) {
277-
alternative <- .match.alt(alternative)
278+
alternative <- .match.alt(alternative, FALSE)
278279

279280
res <- switch(tolower(es),
280281
eta2 = data.frame(Eta2_partial = (f * df) / (f * df + df_error)),

R/eta_squared-main.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ eta_squared <- function(model,
203203
partial = TRUE, generalized = FALSE,
204204
ci = 0.95, alternative = "greater",
205205
verbose = TRUE, ...) {
206-
alternative <- .match.alt(alternative)
206+
alternative <- .match.alt(alternative, FALSE)
207207
out <- .anova_es(
208208
model,
209209
type = "eta",
@@ -225,7 +225,7 @@ omega_squared <- function(model,
225225
partial = TRUE,
226226
ci = 0.95, alternative = "greater",
227227
verbose = TRUE, ...) {
228-
alternative <- .match.alt(alternative)
228+
alternative <- .match.alt(alternative, FALSE)
229229
out <- .anova_es(model, type = "omega", partial = partial, ci = ci, alternative = alternative, verbose = verbose, ...)
230230
class(out) <- unique(c("effectsize_anova", "effectsize_table", "see_effectsize_table", class(out)))
231231
if ("CI" %in% colnames(out)) attr(out, "ci_method") <- list(method = "ncp", distribution = "F")
@@ -239,7 +239,7 @@ epsilon_squared <- function(model,
239239
partial = TRUE,
240240
ci = 0.95, alternative = "greater",
241241
verbose = TRUE, ...) {
242-
alternative <- .match.alt(alternative)
242+
alternative <- .match.alt(alternative, FALSE)
243243
out <- .anova_es(model, type = "epsilon", partial = partial, ci = ci, alternative = alternative, verbose = verbose, ...)
244244
class(out) <- unique(c("effectsize_anova", "effectsize_table", "see_effectsize_table", class(out)))
245245
if ("CI" %in% colnames(out)) attr(out, "ci_method") <- list(method = "ncp", distribution = "F")
@@ -256,7 +256,7 @@ cohens_f <- function(model,
256256
partial = TRUE, squared = FALSE, model2 = NULL,
257257
ci = 0.95, alternative = "greater",
258258
verbose = TRUE, ...) {
259-
alternative <- .match.alt(alternative)
259+
alternative <- .match.alt(alternative, FALSE)
260260
if (!is.null(model2)) {
261261
return(.cohens_f_delta(model, model2,
262262
squared = squared,

R/mahalanobis_D.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#' # Or
5656
#' mahalanobis_d(mpg + hp + cyl ~ am, data = mtcars)
5757
#'
58-
#' mahalanobis_d(mpg + hp + cyl ~ am, data = mtcars, alternative = "greater")
58+
#' mahalanobis_d(mpg + hp + cyl ~ am, data = mtcars, alternative = "two.sided")
5959
#'
6060
#' # Different mu:
6161
#' mahalanobis_d(mpg + hp + cyl ~ am,
@@ -83,11 +83,11 @@
8383
#' @export
8484
mahalanobis_d <- function(x, y = NULL, data = NULL,
8585
pooled_cov = TRUE, mu = 0,
86-
ci = 0.95, alternative = "two.sided",
86+
ci = 0.95, alternative = "greater",
8787
verbose = TRUE, ...) {
8888
# TODO add one sample case DV1 + DV2 ~ 1
8989
# TODO add paired samples case DV1 + DV2 ~ 1 | ID
90-
alternative <- .match.alt(alternative)
90+
alternative <- .match.alt(alternative, FALSE)
9191
data <- .get_data_multivariate(x, y, data, verbose = verbose, ...)
9292
x <- data[["x"]]
9393
y <- data[["y"]]

R/r2_semipartial.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ r2_semipartial.lm <- function(model, type = c("terms", "parameters"),
9797
ci = 0.95, alternative = "greater",
9898
...) {
9999
type <- match.arg(type)
100-
alternative <- .match.alt(alternative)
100+
alternative <- .match.alt(alternative, FALSE)
101101

102102
y <- stats::model.frame(model)[[1]]
103103
mm <- insight::get_modelmatrix(model)

R/rank_ANOVA.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ rank_epsilon_squared <- function(x, groups, data = NULL,
8989
ci = 0.95, alternative = "greater",
9090
iterations = 200,
9191
verbose = TRUE, ...) {
92-
alternative <- .match.alt(alternative)
92+
alternative <- .match.alt(alternative, FALSE)
9393

9494
if (.is_htest_of_type(x, "Kruskal-Wallis", "Kruskal-Wallis-test")) {
9595
return(effectsize(x, type = "epsilon", ci = ci, iterations = iterations, alternative = alternative))
@@ -130,7 +130,7 @@ rank_eta_squared <- function(x, groups, data = NULL,
130130
ci = 0.95, alternative = "greater",
131131
iterations = 200,
132132
verbose = TRUE, ...) {
133-
alternative <- .match.alt(alternative)
133+
alternative <- .match.alt(alternative, FALSE)
134134

135135
if (.is_htest_of_type(x, "Kruskal-Wallis", "Kruskal-Wallis-test")) {
136136
return(effectsize(x, type = "eta", ci = ci, iterations = iterations, alternative = alternative))
@@ -177,7 +177,7 @@ kendalls_w <- function(x, groups, blocks, data = NULL,
177177
ci = 0.95, alternative = "greater",
178178
iterations = 200,
179179
verbose = TRUE, ...) {
180-
alternative <- .match.alt(alternative)
180+
alternative <- .match.alt(alternative, FALSE)
181181

182182
if (.is_htest_of_type(x, "Friedman", "Friedman-test")) {
183183
return(effectsize(x, ci = ci, iterations = iterations, verbose = verbose, alternative = alternative))

R/utils.R

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -68,49 +68,3 @@
6868
return(FALSE)
6969
}
7070
}
71-
72-
73-
# CI Utils ----------------------------------------------------------------
74-
75-
#' @keywords internal
76-
.test_ci <- function(ci) {
77-
if (is.null(ci)) {
78-
return(FALSE)
79-
}
80-
if (!is.numeric(ci) ||
81-
length(ci) != 1L ||
82-
ci < 0 ||
83-
ci > 1) {
84-
insight::format_error("ci must be a single numeric value between (0, 1)")
85-
}
86-
return(TRUE)
87-
}
88-
89-
#' @keywords internal
90-
.adjust_ci <- function(ci, alternative) {
91-
if (alternative == "two.sided") {
92-
return(ci)
93-
}
94-
95-
2 * ci - 1
96-
}
97-
98-
#' @keywords internal
99-
.limit_ci <- function(out, alternative, lb, ub) {
100-
if (alternative == "two.sided") {
101-
return(out)
102-
}
103-
104-
if (alternative == "less") {
105-
out$CI_low <- lb
106-
} else if (alternative == "greater") {
107-
out$CI_high <- ub
108-
}
109-
110-
out
111-
}
112-
113-
#' @keywords internal
114-
.match.alt <- function(alternative) {
115-
match.arg(alternative, c("two.sided", "less", "greater"))
116-
}

R/utils_ncp_ci.R renamed to R/utils_ci.R

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# NCP -------------------------
2+
13
#' @keywords internal
24
#' @importFrom stats pf qf optim
35
.get_ncp_F <- function(f, df, df_error, conf.level = 0.9) {
@@ -93,3 +95,57 @@
9395

9496
chi_ncp
9597
}
98+
99+
# Validators --------------------------------------
100+
101+
102+
#' @keywords internal
103+
.test_ci <- function(ci) {
104+
if (is.null(ci)) {
105+
return(FALSE)
106+
}
107+
if (!is.numeric(ci) ||
108+
length(ci) != 1L ||
109+
ci < 0 ||
110+
ci > 1) {
111+
insight::format_error("ci must be a single numeric value between (0, 1)")
112+
}
113+
return(TRUE)
114+
}
115+
116+
#' @keywords internal
117+
.adjust_ci <- function(ci, alternative) {
118+
if (alternative == "two.sided") {
119+
return(ci)
120+
}
121+
122+
2 * ci - 1
123+
}
124+
125+
#' @keywords internal
126+
.limit_ci <- function(out, alternative, lb, ub) {
127+
if (alternative == "two.sided") {
128+
return(out)
129+
}
130+
131+
if (alternative == "less") {
132+
out$CI_low <- lb
133+
} else if (alternative == "greater") {
134+
out$CI_high <- ub
135+
}
136+
137+
out
138+
}
139+
140+
#' @keywords internal
141+
.match.alt <- function(alternative, two.sided = TRUE) {
142+
if (is.null(alternative)) {
143+
if (two.sided) {
144+
return("two.sided")
145+
} else {
146+
return("greater")
147+
}
148+
}
149+
150+
match.arg(alternative, c("two.sided", "less", "greater"))
151+
}

0 commit comments

Comments
 (0)