Calculate and plot r and Cohen’s d effect size and its confidence intervals.
effsize_plot(x, g, method = 'r', paired = F,
color = 'black', size = 2,
width = .05,
line.col = 'grey', lwd = 1, lty = 2,
ggtheme = theme_minimal(),
par_r = list(conf = .95, type = 'perc', R = 1000),
par_d = list(pooled = T, hedges.correction = F, conf.level = .95),
plot = T, show = F)
x, g dataframe and vector with numerical and factor variables, respectively.
method specify what effect size to compute: Wilcoxon r ('r') or Cohen’s d ('d').
paired logical. Wether the samples are paired.
color, size character or hexa specifying the errorbar and point colors, and size of points, respectively.
width width of errorbar brackets.
line.col, lwd, lty color, width and type of the zero-crossing line, respectively.
ggtheme a ggplot2 theme function.
par_r list of parameters to be passed to WilcoxonR or WilcoxonPairedR functions. Specify as list(conf, type, R), where conf is the level of confidence interval, type is the type of bootstrap estimation for confidence interval (‘norm’ for …, ‘basic’ for …, ‘perc’ for …, ‘bca’ for …) and R is the number of bootstrap resampling.
par_d list of parameters to be passed to cohen.d function. Specify as list(pooled, hedges.correction, conf.level), where pooled is a logical indicating whether should be used the pooled standard deviation (TRUE, default) or the whole sample standard deviation (FALSE), hedges.correction is a logical indicating if Hedges correction should be applied (TRUE) or not (FALSE, default) and conf.level is the level of confidence inteval.
plot logical indicating whether to plot (TRUE, default) or not (FALSE)
show logical indicating whether to print the estimate, p-value, effect size and its confidence intervals (TRUE) or not (FALSE, default).
The packages rcompanion (Mangiafico 2020) and effsize (Torchiano 2020) are required to calculate r and d/g effect size, respectively.
For more details about how each effect size is calculated, read the documentation of rcompanion and effsize.
A list comprised of:
es_plot the plot output.
metrics a data.frame with variable names, statistic (t or W/V), p-value, effect size (r or d/g) and lower and upper limits of confidence interval.
Generating dataset
x <- factor(rep(c('A','B'), each = 50))
y1 <- abs(rnorm(100, mean = 8.4, sd = 2)) %>% round(.,0)
y1[51:100] <- abs(rnorm(50, 10, 4)) %>% round(.,0)
y2 <- abs(rnorm(100, 25, 5)) %>% round(.,0)
y2[51:100] <- abs(rnorm(50, 23.3, 4)) %>% round(.,0)
y3 <- abs(rnorm(100, 8.5, 4)) %>% round(.,0)
y3[51:100] <- abs(rnorm(50, 11.2, 5.5)) %>% round(.,0)
df <- data.frame(x,y1,y2,y3)
Loading the function
source('https://github.com/geovanjr/stats/raw/master/effsize_plot.R')
Calculating r effect size
effsize_plot(df[,2:4], df[,1], method = 'r', paired = F, plot = T, show = T,
color = 'forestgreen',
par_r = list(R = 500))
## variable W p r lower upper
## 1 y1 859.5 0.0067 -0.271 -0.46700 -0.0882
## 2 y2 1546.0 0.0409 0.205 0.00481 0.3890
## 3 y3 999.0 0.0831 -0.174 -0.36100 0.0430
Calculating d effect size
effsize_plot(df[,2:4], df[,1], method = 'd', paired = F, plot = T, show = T,
color = 'forestgreen', size = 3, lty = 3, ggtheme = theme_light())
## variable t p d lower upper
## 1 y1 -3.019994 0.0035 -0.6039988 -1.009840950 -0.19815667
## 2 y2 1.972555 0.0514 0.3945111 -0.006224558 0.79524674
## 3 y3 -2.297717 0.0238 -0.4595433 -0.861641189 -0.05744545
Calculating g effect size
effsize_plot(df[,2:4], df[,1], method = 'd', paired = F, plot = T, show = T,
color = 'forestgreen', size = 3, lty = 3,
par_d = list(hedges.correction = TRUE))
## variable t p g lower upper
## 1 y1 -3.019994 0.0035 -0.4689179 -0.868142052 -0.06969377
## 2 y2 1.972555 0.0514 0.4028026 0.004980506 0.80062469
## 3 y3 -2.297717 0.0238 -0.4102974 -0.808267973 -0.01232683
Changing es_plot aesthetics
es <- effsize_plot(df[,2:4], df[,1], method = 'd', paired = F, plot = F, show = F,
color = 'forestgreen', size = 3, lty = 3,
par_d = list(hedges.correction = TRUE))
es$es_plot +
theme(axis.text.y = element_blank()) +
annotate('text', 1+.2, es$metrics[1,4],
label = paste0(es$metrics[1,1]),
size = 4, color = 'forestgreen') +
annotate('text', 2+.2, es$metrics[2,4],
label = paste0(es$metrics[2,1]),
size = 4, color = 'forestgreen') +
annotate('text', 3+.2, es$metrics[3,4],
label = paste0(es$metrics[3,1]),
size = 4, color = 'forestgreen')
Getting metrics
es$metrics
| variable | t | p | g | lower | upper |
|---|---|---|---|---|---|
| y1 | -3.019994 | 0.0035 | -0.4689179 | -0.8681421 | -0.0696938 |
| y2 | 1.972555 | 0.0514 | 0.4028026 | 0.0049805 | 0.8006247 |
| y3 | -2.297717 | 0.0238 | -0.4102974 | -0.8082680 | -0.0123268 |
Mangiafico, Salvatore. 2020. Rcompanion: Functions to Support Extension Education Program Evaluation. https://CRAN.R-project.org/package=rcompanion.
Torchiano, Marco. 2020. Effsize: Efficient Effect Size Computation. https://CRAN.R-project.org/package=effsize.