Skip to content

Commit

Permalink
CRAN 0.8.9
Browse files Browse the repository at this point in the history
deal with #648

* remove effects arg where not needed

* Update interpret_ess_rhat.R

* deal with easystats/report#442

---------

Co-authored-by: Daniel <[email protected]>
Co-authored-by: Indrajeet Patil <[email protected]>
  • Loading branch information
3 people authored Jul 3, 2024
1 parent 9855296 commit 5adb681
Show file tree
Hide file tree
Showing 31 changed files with 229 additions and 188 deletions.
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 @@ -294,7 +294,7 @@ cohens_f <- function(model,

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 Down Expand Up @@ -430,7 +430,7 @@ cohens_f_squared <- function(model,


# 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,37 +448,36 @@ cohens_f_squared <- function(model,

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)
}
}

Expand Down Expand Up @@ -570,7 +569,7 @@ cohens_f_squared <- function(model,


# 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 @@ cohens_f_squared <- function(model,
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 @@ cohens_f_squared <- function(model,
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 Down Expand Up @@ -819,7 +818,7 @@ cohens_f_squared <- function(model,
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 @@ cohens_f_squared <- function(model,
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"),
error = function(...) 1
)
attr(out, "approximate") <- TRUE
Expand Down Expand Up @@ -864,7 +864,8 @@ cohens_f_squared <- function(model,

# 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 @@ cohens_f_squared <- function(model,
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 @@ cohens_f_squared <- function(model,
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

0 comments on commit 5adb681

Please sign in to comment.