Skip to content

Commit fcac19f

Browse files
Copilotrempsycgithub-actions[bot]Copilotstrengejacke
authored
Add validation to ensure es_type parameter is only used with effectsize = "boot" (#577)
* Initial plan * Add validation to ensure es_type only used with effectsize='boot' Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> * Improve validation to also error when es_type used with effectsize=NULL Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> * Update R/estimate_contrasts.R [skip ci] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update tests/testthat/test-estimate_contrasts_effectsize.R [skip ci] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update tests/testthat/test-estimate_contrasts_effectsize.R [skip ci] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * air because reviewdog is being really annoying right now * spellcheck, wordlist * Update R/estimate_contrasts.R Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * air because of annoying dog * refactor * air --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Daniel <mail@danielluedecke.de>
1 parent d2e3dfc commit fcac19f

7 files changed

Lines changed: 180 additions & 127 deletions

File tree

R/estimate_contrasts.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@
7171
#' size will be computed.
7272
#' @param es_type Specifies the type of effect-size measure to estimate when
7373
#' using `effectsize = "boot"`. One of `"unstandardized"`, `"cohens.d"`,
74-
#' `"hedges.g"`, `"cohens.d.sigma"`, `"r"`, or `"akp.robust.d"`. See`
75-
#' effect.type` argument of [bootES::bootES] for details.
74+
#' `"hedges.g"`, `"cohens.d.sigma"`, `"r"`, or `"akp.robust.d"`. See `effect.type`
75+
#' argument of [`bootES::bootES()`] for details. If not specified, defaults to
76+
#' `"cohens.d"`.
7677
#' @param iterations The number of bootstrap resamples to perform.
7778
#' @inheritParams estimate_means
7879
#'
@@ -301,7 +302,7 @@ estimate_contrasts.default <- function(
301302
keep_iterations = FALSE,
302303
effectsize = NULL,
303304
iterations = 200,
304-
es_type = "cohens.d",
305+
es_type = NULL,
305306
backend = NULL,
306307
verbose = TRUE,
307308
...
@@ -317,6 +318,12 @@ estimate_contrasts.default <- function(
317318
# validate input
318319
estimate <- .validate_estimate_arg(estimate)
319320
comparison <- .check_for_inequality_comparison(comparison)
321+
# Validate es_type usage
322+
if (is.null(effectsize) && !is.null(es_type)) {
323+
insight::format_error(
324+
"`es_type` can only be used when `effectsize` is specified. Currently `effectsize = NULL`."
325+
)
326+
}
320327

321328
if (backend == "emmeans") {
322329
# Emmeans ----------------------------------------------------------------

R/estimate_contrasts_effectsize.R

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
.estimate_contrasts_effectsize <- function(model,
2-
estimated,
3-
contrasts_results,
4-
effectsize,
5-
bootstraps,
6-
bootES_type,
7-
backend) {
1+
.estimate_contrasts_effectsize <- function(
2+
model,
3+
estimated,
4+
contrasts_results,
5+
effectsize,
6+
bootstraps,
7+
bootES_type,
8+
backend
9+
) {
810
# Add standardized effect size
911
insight::validate_argument(effectsize, c("none", "emmeans", "marginal", "boot"))
1012

1113
if (effectsize == "emmeans" && backend != "emmeans") {
12-
insight::format_error("`effectsize = \"emmeans\"` only possible with `backend = \"emmeans\"`")
14+
insight::format_error(
15+
"`effectsize = \"emmeans\"` only possible with `backend = \"emmeans\"`"
16+
)
17+
}
18+
19+
if (!is.null(bootES_type) && effectsize != "boot") {
20+
insight::format_error("`es_type` can only be used when `effectsize = \"boot\"`.")
1321
}
1422

1523
# Check if the model includes any random effects. Effect size calculations in
@@ -36,7 +44,8 @@
3644
))
3745
}
3846

39-
switch(effectsize,
47+
switch(
48+
effectsize,
4049
emmeans = {
4150
eff <- emmeans::eff_size(
4251
estimated,
@@ -54,10 +63,16 @@
5463
# d_adj <- contrasts$t * contrasts$SE / sigma(model) * sqrt(1 - R2)
5564
# New: d_adj <- difference * (1- R2)/ sigma
5665
R2 <- summary(model)$r.squared
57-
d_adj <- contrasts_results$Difference * (1 - R2) / insight::get_sigma(model, verbose = FALSE)
66+
d_adj <- contrasts_results$Difference *
67+
(1 - R2) /
68+
insight::get_sigma(model, verbose = FALSE)
5869
contrasts_results <- cbind(contrasts_results, marginal_d = d_adj)
5970
},
6071
boot = {
72+
# set default
73+
if (is.null(bootES_type)) {
74+
bootES_type <- "cohens.d"
75+
}
6176
insight::check_if_installed("bootES")
6277
dat <- insight::get_data(model)
6378
resp <- insight::find_response(model)
@@ -84,7 +99,11 @@
8499

85100
eff <- do.call(rbind, es.lists)
86101
eff <- eff[1:3]
87-
names(eff) <- c(bootES_type, paste0(bootES_type, "_CI_low"), paste0(bootES_type, "_CI_high"))
102+
names(eff) <- c(
103+
bootES_type,
104+
paste0(bootES_type, "_CI_low"),
105+
paste0(bootES_type, "_CI_high")
106+
)
88107

89108
contrasts_results <- cbind(contrasts_results, eff)
90109
}

R/estimate_means.R

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@
306306
#'
307307
#' The output from `equivalence_test()` returns a column `SGPV`, the "second
308308
#' generation p-value", which is equivalent to the `p (Equivalence)` column when
309-
#' using the `equivalence` argument. It is basically representiv the ROPE coverage
309+
#' using the `equivalence` argument. It is basically representative of the ROPE coverage
310310
#' from the confidence interval of the estimate (i.e. the proportion of the
311311
#' confidence intervals that lies within the region of practical equivalence).
312312
#'
@@ -414,16 +414,18 @@
414414
#' estimate_means(model, by = "Sepal.Width", length = 3)
415415
#' }
416416
#' @export
417-
estimate_means <- function(model,
418-
by = "auto",
419-
predict = NULL,
420-
ci = 0.95,
421-
estimate = NULL,
422-
transform = NULL,
423-
keep_iterations = FALSE,
424-
backend = NULL,
425-
verbose = TRUE,
426-
...) {
417+
estimate_means <- function(
418+
model,
419+
by = "auto",
420+
predict = NULL,
421+
ci = 0.95,
422+
estimate = NULL,
423+
transform = NULL,
424+
keep_iterations = FALSE,
425+
backend = NULL,
426+
verbose = TRUE,
427+
...
428+
) {
427429
# Process argument ---------------------------------------------------------
428430
# --------------------------------------------------------------------------
429431

@@ -469,12 +471,16 @@ estimate_means <- function(model,
469471
info <- attributes(estimated)
470472

471473
# Table formatting
472-
attr(means, "table_title") <- c(switch(estimate,
473-
specific = "Model-based Predictions",
474-
typical = "Estimated Marginal Means",
475-
average = "Average Predictions",
476-
population = "Average Counterfactual Predictions"
477-
), "blue")
474+
attr(means, "table_title") <- c(
475+
switch(
476+
estimate,
477+
specific = "Model-based Predictions",
478+
typical = "Estimated Marginal Means",
479+
average = "Average Predictions",
480+
population = "Average Counterfactual Predictions"
481+
),
482+
"blue"
483+
)
478484

479485
attr(means, "table_footer") <- .table_footer(
480486
means,

inst/WORDLIST

Lines changed: 26 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,39 @@
1-
’s
21
ANCOVAs
3-
Arel
4-
ATE
52
ATEs
63
ATT
74
ATU
5+
Analysing
6+
Arel
87
Axelsson
9-
BH
108
BLUPs
119
Bundock
12-
cdot
13-
Chatton
1410
CJ
15-
coefficients’
16-
diag
17-
Dickerman
18-
Dom
11+
Chatton
1912
DS
13+
Dickerman
2014
EFC
2115
EMM
2216
EMMs
2317
EUROFAMCARE
2418
Fitzsimons
2519
GAMM
20+
GLM's
2621
GLMM
2722
GLMMs
28-
GLM's
2923
GMM
3024
GMMs
3125
Greifer
3226
Heiss
33-
Hernan
3427
Hernán
3528
ICC's
3629
ICCs
3730
IPW
3831
Intersectional
3932
Intersectionality
33+
JOSS
34+
LM
4035
Leckie
4136
Lenth
42-
LM
4337
MAIHDA
4438
Mattan
4539
McCabe
@@ -49,154 +43,113 @@ Merlo
4943
Mize
5044
Mmmh
5145
Modelisation
52-
Modelling
53-
Møller
5446
Montiel
5547
Mulinari
48+
Møller
5649
Neyman
57-
Olea
50+
Nonresponse
5851
ORCID
52+
Olea
5953
Owww
60-
PCVs
6154
PCV
55+
PCVs
6256
Plagborg
63-
QoL
6457
Psychometrika
58+
QoL
6559
RCTs
6660
README
67-
Rohrer
6861
RStudio
6962
RTs
7063
Ratcliff
71-
Reproducibility
72-
Rescaling
64+
Rohrer
65+
SSM
66+
SV
67+
SVARs
7368
Setosa
7469
Shachar
7570
Spiller
76-
SSM
7771
Subramanian
78-
SV
79-
SVARs
8072
Versicolor
8173
Virginica
82-
Visualisation
8374
Visualising
8475
Wagenmakers
8576
Weisberg
8677
Wemrell
8778
Wiernik
8879
al
8980
analysing
90-
bc
9181
behaviour
92-
blogpost
93-
bocode
94-
bonferroni
9582
bootES
9683
brglm
9784
brms
98-
caregiving
85+
cdot
9986
ception
10087
codecov
101-
computable
88+
coefficients’
10289
conditionspeed
103-
counterfactuals
10490
confounder
105-
confounders
10691
coxme
10792
d'être
108-
d’être
10993
dat
11094
datagrid
11195
datawizard
96+
diag
11297
doi
11398
dpar
99+
d’être
114100
easystats
115-
edu
116-
effectsize
117101
emmeans
118-
emtrends
119102
et
120103
exchangeability
121104
favour
122-
fdr
123-
fmwww
124105
foR
125106
generalizability
126107
geoms
127108
ggplot
128109
github
129110
glmmTMB
130111
glms
131-
grano
132112
grey
133-
hochberg
134-
holm
135-
hommel
136-
http
137113
https
138-
individuals'
139-
interpretable
114+
individuals’
140115
intersectional
141116
intersectionality
142117
intra
143-
io
144118
jmr
145119
joss
146120
labelled
147-
lifecycle
148121
lme
149-
lme4
150122
loess
151123
marginaleffects
152-
marginalizations
153124
mattansb
154125
modelisation
155126
modelled
156127
modelling
157-
natively
158128
nd
159129
nnet
160130
ol
161131
onwards
162132
partialled
163-
patilindrajeets
164-
pscl
165133
pre
166-
quartiles
134+
pscl
167135
rOpenSci
168-
Remotes
169136
raison
170-
recoding
171-
recodings
172-
repec
173-
reproducibility
174-
rescaled
175-
rescales
176-
residualize
177137
residualized
138+
residualizes
178139
rootSolve
179140
rstanarm
180-
salis
181141
spinoff
182142
ssmph
183-
strengejacke
184-
summarised
185143
summarises
186-
terciles
187-
transint
188-
tukey
189-
ultron
190-
uninformativeness
144+
tinyplot
191145
unidimensional
146+
uninformativeness
192147
unstandardizing
193148
usecases
194149
versicolor
195150
virginica
196151
visualisation
197152
visualise
198-
visualising
199153
walkthrough
200-
Nonresponse
201-
tinyplot
202154
155+
’s

0 commit comments

Comments
 (0)