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

New CRAN release #649

Merged
merged 21 commits into from
Jul 3, 2024
Merged
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
11 changes: 5 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: effectsize
Title: Indices of Effect Size
Version: 0.8.8.2
Version: 0.8.9
Authors@R:
c(person(given = "Mattan S.",
family = "Ben-Shachar",
Expand Down Expand Up @@ -72,10 +72,10 @@ Depends:
R (>= 3.6)
Imports:
bayestestR (>= 0.13.2),
insight (>= 0.19.10),
parameters (>= 0.21.7),
performance (>= 0.11.0),
datawizard (>= 0.10.0),
insight (>= 0.20.1),
parameters (>= 0.22.0),
performance (>= 0.12.0),
datawizard (>= 0.11.0),
stats,
utils
Suggests:
Expand Down Expand Up @@ -112,4 +112,3 @@ Config/Needs/website:
rstudio/bslib,
r-lib/pkgdown,
easystats/easystatstemplate
Remotes: easystats/insight, easystats/datawizard, easystats/bayestestR, easystats/parameters, easystats/performance
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# effectsize 0.8.9

## Bug fixes

- `interpret(<effectsize_table>)` no longer returns transformed effect sizes ( #640 )

# effectsize 0.8.8

## Bug fixes
Expand Down
14 changes: 6 additions & 8 deletions R/cohens_g.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,23 @@ cohens_g <- function(x, y = NULL,
insight::format_error("'x' and 'y' must have the same number of levels (minimum 2)")
}
x <- table(x, y)
} else {
if ((nrow(x) < 2) || (ncol(x) != nrow(x))) {
insight::format_error("'x' must be square with at least two rows and columns")
}
} else if ((nrow(x) < 2) || (ncol(x) != nrow(x))) {
insight::format_error("'x' must be square with at least two rows and columns")
}


b <- x[upper.tri(x)]
c <- t(x)[upper.tri(x)]
a <- x[upper.tri(x)]
b <- t(x)[upper.tri(x)]

P <- sum(pmax(b, c)) / (sum(b) + sum(c))
P <- sum(pmax(a, b)) / (sum(a) + sum(b))
g <- P - 0.5

out <- data.frame(Cohens_g = g)

if (.test_ci(ci)) {
out$CI <- ci

n <- sum(b) + sum(c)
n <- sum(a) + sum(b)
k <- P * n

res <- stats::prop.test(k, n,
Expand Down
4 changes: 2 additions & 2 deletions R/common_language.R
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ wmw_odds <- function(x, y = NULL, data = NULL,
y <- data[data$g == "y", "r"]

.foo <- function(p) {
diff <- stats::quantile(x, probs = c(p, 1 - p)) - stats::quantile(y, probs = c(1 - p, p))
min(abs(diff))
difference <- stats::quantile(x, probs = c(p, 1 - p)) - stats::quantile(y, probs = c(1 - p, p))
min(abs(difference))
}

stats::optim(
Expand Down
44 changes: 22 additions & 22 deletions R/convert_between_odds_to_probs.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ probs_to_odds.data.frame <- function(probs, log = FALSE, select = NULL, exclude
#' @keywords internal
.odds_to_probs_df <- function(odds = NULL, probs = NULL, log = FALSE, select = NULL, exclude = NULL, ...) {
# If vector
if (!is.null(odds)) {
df <- odds
if (is.null(odds)) {
mydata <- probs
} else {
df <- probs
mydata <- odds
}

# check for formula notation, convert to character vector
Expand All @@ -93,55 +93,55 @@ probs_to_odds.data.frame <- function(probs, log = FALSE, select = NULL, exclude
}

# Variable order
var_order <- names(df)
var_order <- names(mydata)

# Keep subset
if (!is.null(select) && select %in% names(df)) {
if (!is.null(select) && select %in% names(mydata)) {
select <- as.vector(select)
to_keep <- as.data.frame(df[!names(df) %in% select])
df <- df[names(df) %in% select]
to_keep <- as.data.frame(mydata[!names(mydata) %in% select])
mydata <- mydata[names(mydata) %in% select]
} else {
to_keep <- NULL
}

# Remove exceptions
if (!is.null(exclude) && exclude %in% names(df)) {
if (!is.null(exclude) && exclude %in% names(mydata)) {
exclude <- as.vector(exclude)
if (is.null(to_keep)) {
to_keep <- as.data.frame(df[exclude])
to_keep <- as.data.frame(mydata[exclude])
} else {
to_keep <- cbind(to_keep, as.data.frame(df[exclude]))
to_keep <- cbind(to_keep, as.data.frame(mydata[exclude]))
}

df <- df[!names(df) %in% exclude]
mydata <- mydata[!names(mydata) %in% exclude]
}

# Remove non-numerics
is_num <- vapply(df, is.numeric, logical(1))
dfother <- df[!is_num]
dfnum <- df[is_num]
is_num <- vapply(mydata, is.numeric, logical(1))
dfother <- mydata[!is_num]
dfnum <- mydata[is_num]

# Tranform
if (!is.null(odds)) {
dfnum <- data.frame(lapply(dfnum, odds_to_probs.numeric, log = log))
} else {
if (is.null(odds)) {
dfnum <- data.frame(lapply(dfnum, probs_to_odds.numeric, log = log))
} else {
dfnum <- data.frame(lapply(dfnum, odds_to_probs.numeric, log = log))
}

# Add non-numerics
if (is.null(ncol(dfother))) {
df <- dfnum
mydata <- dfnum
} else {
df <- cbind(dfother, dfnum)
mydata <- cbind(dfother, dfnum)
}

# Add exceptions
if (!is.null(select) || !is.null(exclude) && exists("to_keep")) {
df <- cbind(df, to_keep)
mydata <- cbind(mydata, to_keep)
}

# Reorder
df <- df[var_order]
mydata <- mydata[var_order]

return(df)
mydata
}
2 changes: 1 addition & 1 deletion R/effectsize.htest.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ effectsize.htest <- function(model, type = NULL, verbose = TRUE, ...) {

cl <- match.call()
cl <- cl[-which(names(cl) == "subset")]
dots <- list(eval(cl, parent.frame()))
dots <- insight::compact_list(list(eval(cl, parent.frame())))

dots$alternative <- model$alternative
dots$ci <- attr(model$conf.int, "conf.level")
Expand Down
90 changes: 46 additions & 44 deletions R/eta_squared-main.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' @param verbose Toggle warnings and messages on or off.
#' @inheritParams chisq_to_phi
#' @param ... Arguments passed to or from other methods.
#' - Can be `include_intercept = TRUE` to include the effect size for the intercept (when it is included in the ANOVA table).

Check warning on line 26 in R/eta_squared-main.R

View workflow job for this annotation

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

file=R/eta_squared-main.R,line=26,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 127 characters.
#' - For Bayesian models, arguments passed to `ss_function`.
#'
#' @return
Expand Down Expand Up @@ -248,7 +248,7 @@
ci = 0.95, alternative = "greater",
verbose = TRUE, ...) {
alternative <- .match.alt(alternative, FALSE)
out <- .anova_es(model, type = "epsilon", partial = partial, ci = ci, alternative = alternative, verbose = verbose, ...)

Check warning on line 251 in R/eta_squared-main.R

View workflow job for this annotation

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

file=R/eta_squared-main.R,line=251,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 122 characters.
class(out) <- unique(c("effectsize_anova", "effectsize_table", "see_effectsize_table", class(out)))
if ("CI" %in% colnames(out)) attr(out, "ci_method") <- list(method = "ncp", distribution = "F")
attr(out, "approximate") <- isTRUE(attr(out, "approximate", exact = TRUE))
Expand Down Expand Up @@ -294,7 +294,7 @@

es_name <- get_effectsize_name(colnames(res))
res[[es_name]] <- res[[es_name]] / (1 - res[[es_name]])
if (grepl("_partial", es_name)) {
if (grepl("_partial", es_name, fixed = TRUE)) {
colnames(res)[colnames(res) == es_name] <- "Cohens_f2_partial"
} else {
colnames(res)[colnames(res) == es_name] <- "Cohens_f2"
Expand All @@ -316,7 +316,7 @@
if ("CI" %in% colnames(res)) attr(res, "ci_method") <- list(method = "ncp", distribution = "F")
class(res) <- unique(c("effectsize_anova", "effectsize_table", "see_effectsize_table", class(res)))
attr(res, "approximate") <- isTRUE(attr(res, "approximate", exact = TRUE))
attr(res, "table_footer") <- if (method != "eta") sprintf("Based on %s squared.", paste0(toupper(substring(method, 1, 1)), substring(method, 2)))

Check warning on line 319 in R/eta_squared-main.R

View workflow job for this annotation

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

file=R/eta_squared-main.R,line=319,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 147 characters.
res
}

Expand Down Expand Up @@ -430,7 +430,7 @@


# Estimate effect size ---
if (type == "eta") {
if (type == "eta") { # nolint
if (isTRUE(generalized) || is.character(generalized)) {
## copied from afex
obs <- logical(nrow(aov_table))
Expand All @@ -448,44 +448,43 @@

aov_table$Eta2_generalized <- aov_table$Sum_Squares /
(aov_table$Sum_Squares + values$Sum_Squares_residuals + obs_SSn1 - obs_SSn2)
} else if (!isTRUE(partial)) {
aov_table$Eta2 <- aov_table$Sum_Squares /
values$Sum_Squares_total
} else {
} else if (isTRUE(partial)) {
aov_table$Eta2_partial <-
aov_table$Sum_Squares /
(aov_table$Sum_Squares + values$Sum_Squares_residuals)
} else {
aov_table$Eta2 <- aov_table$Sum_Squares / values$Sum_Squares_total
}
} else if (type == "omega") {
if (!isTRUE(partial)) {
aov_table$Omega2 <-
(aov_table$Sum_Squares - aov_table$df * values$Mean_Square_residuals) /
(values$Sum_Squares_total + values$Mean_Square_residuals)
aov_table$Omega2 <- pmax(0, aov_table$Omega2)
} else {
if (isTRUE(partial)) {
aov_table$Omega2_partial <-
(aov_table$Sum_Squares - aov_table$df * values$Mean_Square_residuals) /
(aov_table$Sum_Squares + (values$n - aov_table$df) * values$Mean_Square_residuals)
aov_table$Omega2_partial <- pmax(0, aov_table$Omega2_partial)
} else {
aov_table$Omega2 <-
(aov_table$Sum_Squares - aov_table$df * values$Mean_Square_residuals) /
(values$Sum_Squares_total + values$Mean_Square_residuals)
aov_table$Omega2 <- pmax(0, aov_table$Omega2)
}
} else if (type == "epsilon") {
if (!isTRUE(partial)) {
aov_table$Epsilon2 <-
(aov_table$Sum_Squares - aov_table$df * values$Mean_Square_residuals) /
values$Sum_Squares_total
aov_table$Epsilon2 <- pmax(0, aov_table$Epsilon2)
} else {
if (isTRUE(partial)) {
aov_table$Epsilon2_partial <-
(aov_table$Sum_Squares - aov_table$df * values$Mean_Square_residuals) /
(aov_table$Sum_Squares + values$Sum_Squares_residuals)
aov_table$Epsilon2_partial <- pmax(0, aov_table$Epsilon2_partial)
} else {
aov_table$Epsilon2 <-
(aov_table$Sum_Squares - aov_table$df * values$Mean_Square_residuals) /
values$Sum_Squares_total
aov_table$Epsilon2 <- pmax(0, aov_table$Epsilon2)
}
}

out <- aov_table

# Add CIs ---
if (!is.null(ci)) {

Check warning on line 487 in R/eta_squared-main.R

View workflow job for this annotation

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

file=R/eta_squared-main.R,line=487,col=7,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.
# based on MBESS::ci.R2
ES <- pmax(0, out[[ncol(out)]])
f <- (ES / out$df) / ((1 - ES) / df_error)
Expand Down Expand Up @@ -570,7 +569,7 @@


# Estimate effect size ---
if (type == "eta") {
if (type == "eta") { # nolint
if (isTRUE(generalized) || is.character(generalized)) {
## copied from afex
obs <- logical(nrow(aov_table))
Expand All @@ -589,12 +588,12 @@
aov_table$Eta2_generalized <- aov_table$Sum_Squares /
(aov_table$Sum_Squares + sum(sapply(values, "[[", "Sum_Squares_residuals")) +
obs_SSn1 - obs_SSn2)
} else if (!isTRUE(partial)) {
aov_table$Eta2 <- aov_table$Sum_Squares / Sum_Squares_total
} else {
} else if (isTRUE(partial)) {
aov_table$Eta2_partial <-
aov_table$Sum_Squares /
(aov_table$Sum_Squares + Sum_Squares_residuals)
} else {
aov_table$Eta2 <- aov_table$Sum_Squares / Sum_Squares_total
}
} else if (type == "omega") {
SSS_values <- values[[which(names(values) %in% DV_names)]]
Expand All @@ -603,29 +602,29 @@
Mean_Squares_Subjects <- SSS_values$Mean_Square_residuals

# implemented from https://www.jasonfinley.com/tools/OmegaSquaredQuickRef_JRF_3-31-13.pdf/
if (!isTRUE(partial)) {
aov_table$Omega2 <-
(aov_table$Sum_Squares - aov_table$df * Mean_Square_residuals) /
(Sum_Squares_total + Mean_Squares_Subjects)
aov_table$Omega2 <- pmax(0, aov_table$Omega2)
} else {
if (isTRUE(partial)) {
aov_table$Omega2_partial <-
(aov_table$Sum_Squares - aov_table$df * Mean_Square_residuals) /
(aov_table$Sum_Squares + is_within * Sum_Squares_residuals +
Sum_Squares_Subjects + Mean_Squares_Subjects)
aov_table$Omega2_partial <- pmax(0, aov_table$Omega2_partial)
} else {
aov_table$Omega2 <-
(aov_table$Sum_Squares - aov_table$df * Mean_Square_residuals) /
(Sum_Squares_total + Mean_Squares_Subjects)
aov_table$Omega2 <- pmax(0, aov_table$Omega2)
}
} else if (type == "epsilon") {
if (!isTRUE(partial)) {
aov_table$Epsilon2 <-
(aov_table$Sum_Squares - aov_table$df * Mean_Square_residuals) /
Sum_Squares_total
aov_table$Epsilon2 <- pmax(0, aov_table$Epsilon2)
} else {
if (isTRUE(partial)) {
aov_table$Epsilon2_partial <-
(aov_table$Sum_Squares - aov_table$df * Mean_Square_residuals) /
(aov_table$Sum_Squares + Sum_Squares_residuals)
aov_table$Epsilon2_partial <- pmax(0, aov_table$Epsilon2_partial)
} else {
aov_table$Epsilon2 <-
(aov_table$Sum_Squares - aov_table$df * Mean_Square_residuals) /
Sum_Squares_total
aov_table$Epsilon2 <- pmax(0, aov_table$Epsilon2)
}
}

Expand All @@ -633,7 +632,7 @@


# Add CIs ---
if (!is.null(ci)) {

Check warning on line 635 in R/eta_squared-main.R

View workflow job for this annotation

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

file=R/eta_squared-main.R,line=635,col=7,[if_not_else_linter] Prefer `if (A) x else y` to the less-readable `if (!A) y else x` in a simple if/else statement.
# based on MBESS::ci.R2
ES <- pmax(0, out[[ncol(out)]])
f <- (ES / out$df) / ((1 - ES) / df_residuals)
Expand Down Expand Up @@ -819,7 +818,7 @@
df_error = model[, df_errori],
stringsAsFactors = FALSE
)
par_table <- par_table[!par_table[["Parameter"]] %in% "Residuals", ]
par_table <- par_table[par_table[["Parameter"]] != "Residuals", ]

out <-
.es_aov_table(
Expand All @@ -833,7 +832,8 @@
include_intercept = include_intercept
)

attr(out, "anova_type") <- tryCatch(attr(parameters::model_parameters(model, verbose = FALSE, effects = "fixed", es_type = NULL), "anova_type"),
## TODO: add back `effects = "fixed"` once the deprecation warning in parameters is removed
attr(out, "anova_type") <- tryCatch(attr(parameters::model_parameters(model, verbose = FALSE, es_type = NULL), "anova_type"),

Check warning on line 836 in R/eta_squared-main.R

View workflow job for this annotation

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

file=R/eta_squared-main.R,line=836,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 127 characters.
error = function(...) 1
)
attr(out, "approximate") <- TRUE
Expand Down Expand Up @@ -864,7 +864,8 @@

# TODO this should be in .anova_es.anvoa
# TODO the aoc method should convert to an anova table, then pass to anova
params <- parameters::model_parameters(model, verbose = verbose, effects = "fixed", es_type = NULL)
## TODO: add back `effects = "fixed"` once the deprecation warning in parameters is removed
params <- parameters::model_parameters(model, verbose = verbose, es_type = NULL)
out <- .es_aov_simple(as.data.frame(params),
type = type,
partial = partial, generalized = generalized,
Expand All @@ -890,7 +891,8 @@
verbose = TRUE,
include_intercept = FALSE,
...) {
params <- parameters::model_parameters(model, verbose = verbose, effects = "fixed", es_type = NULL)
## TODO: add back `effects = "fixed"` once the deprecation warning in parameters is removed
params <- parameters::model_parameters(model, verbose = verbose, es_type = NULL)
anova_type <- attr(params, "anova_type")
params <- as.data.frame(params)

Expand Down Expand Up @@ -944,11 +946,11 @@
df_residuals <- sum(params[iResid, "df"])

list(
"Mean_Square_residuals" = Mean_Square_residuals,
"Sum_Squares_residuals" = Sum_Squares_residuals,
"Sum_Squares_total" = Sum_Squares_total,
"n_terms" = N_terms,
"n" = N,
"df_residuals" = df_residuals
Mean_Square_residuals = Mean_Square_residuals,
Sum_Squares_residuals = Sum_Squares_residuals,
Sum_Squares_total = Sum_Squares_total,
n_terms = N_terms,
n = N,
df_residuals = df_residuals
)
}
Loading
Loading