Skip to content

Commit

Permalink
Merge pull request #57 from rcalinjageman/development
Browse files Browse the repository at this point in the history
esci 1.0.3
  • Loading branch information
rcalinjageman authored Jul 9, 2024
2 parents 5001a8e + a6fdcee commit b2ed473
Show file tree
Hide file tree
Showing 244 changed files with 15,753 additions and 6,741 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: esci
Title: Estimation Statistics with Confidence Intervals
Version: 1.0.2
Version: 1.0.3
Authors@R: person("Robert", "Calin-Jageman", email = "[email protected]",
role = c("aut", "cre", "cph"))
Description: A collection of functions and 'jamovi' module for the estimation approach to inferential statistics, the approach which emphasizes effect sizes, interval estimates, and meta-analysis. Nearly all functions are based on 'statpsych' and 'metafor'. This package is still under active development, and breaking changes are likely, especially with the plot and hypothesis test functions. Data sets are included for all examples from Cumming & Calin-Jageman (2024) <ISBN:9780367531508>.
Expand Down Expand Up @@ -28,7 +28,7 @@ Imports:
Rdpack,
stringr,
mathjaxr
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
RdMacros: Rdpack, mathjaxr
Suggests:
Expand Down
6 changes: 2 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,13 @@ importFrom(rlang,enquo)
importFrom(statpsych,ci.lc.mean.bs)
importFrom(statpsych,ci.lc.median.bs)
importFrom(statpsych,ci.lc.prop.bs)
importFrom(statpsych,ci.mean1)
importFrom(statpsych,ci.median1)
importFrom(statpsych,ci.oddsratio)
importFrom(statpsych,ci.phi)
importFrom(statpsych,ci.prop1)
importFrom(statpsych,ci.ratio.mean.ps)
importFrom(statpsych,ci.ratio.mean2)
importFrom(statpsych,ci.ratio.median.ps)
importFrom(statpsych,ci.ratio.median2)
importFrom(statpsych,ci.stdmean.ps)
importFrom(statpsych,ci.stdmean1)
importFrom(stats,aggregate)
importFrom(stats,anova)
importFrom(stats,complete.cases)
Expand All @@ -90,10 +86,12 @@ importFrom(stats,cor)
importFrom(stats,line)
importFrom(stats,median)
importFrom(stats,na.omit)
importFrom(stats,pbinom)
importFrom(stats,pnorm)
importFrom(stats,predict)
importFrom(stats,pt)
importFrom(stats,qnorm)
importFrom(stats,qt)
importFrom(stats,quantile)
importFrom(stats,rnorm)
importFrom(stats,sd)
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
esci version 1.0.3 (Release data: July 2024)
===========

Changes:

* Tweaks to deal with changes in statpsych 1.6. No substantive updates.



esci version 1.0.2 (Release data: March 2024)
===========

Expand Down
14 changes: 7 additions & 7 deletions R/CI_smd_ind_contrast.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#' contrast
#'
#'
#' @description `CI_smd_ind_contrast` returns the point estimate
#' @description \loadmathjax `CI_smd_ind_contrast` returns the point estimate
#' and confidence interval for a standardized mean difference (smd aka Cohen's
#' *d* aka Hedges *g*). A standardized mean difference is a difference in means standardized
#' to a standard deviation:
#' d = psi/s
#' \mjdeqn{d = \frac{ \psi }{s}}{d = psi/s}
#'
#'
#' @param means A vector of 2 or more means
Expand Down Expand Up @@ -88,16 +88,16 @@
#' When equal variance is assumed, the standardized mean difference is
#' d_s, defined in Kline, p. 196:
#'
#' d_s = psi / sd_s
#' \mjdeqn{ d_s = \frac{ \psi }{ sd_{pooled} } }{ d_s = psi / sd_s}
#'
#'
#' where psi is defined in Kline, equation 7.8:
#'
#' psi = sum(contrasts*means)
#' \mjdeqn{ \psi =\sum_{i=1}^{a}c_iM_i }{psi = sum(contrasts*means)}
#'
#'
#' and where sd_pooled is defined in Kline, equation 3.11
#' sqrt(sum(variances*dfs) / sum(dfs))
#' \mjdeqn{sd_{pooled} = { \frac{ \sum_{i=1}^{a} (n_i -1) s_i^2 } { \sum_{i=1}^{a} (n_i-1) } }}{sqrt(sum(variances*dfs) / sum(dfs))}
#'
#'
#' The CI for d_s is derived from lambda-prime transformation from Lecoutre,
Expand All @@ -115,12 +115,12 @@
#' assumed, the standardized mean difference is d_avg, defined in Bonett,
#' equation 6:
#'
#' d_avg = psi / sd_avg
#' \mjdeqn{ d_{avg} = \frac{ \psi }{ sd_{avg} }}{ d_avg = psi / sd_avg}
#'
#' Where sd_avg is the square root of the average of the group variances, as
#' given in Bonett, explanation of equation 6:
#'
#' sqrt(mean(variances))
#' \mjdeqn{sd_{avg} = \sqrt{ \frac{ \sum_{i=1}^{a} s_i^2 }{ a } }}{sqrt(mean(variances))}
#'
#'
#' #### If only 2 groups ####
Expand Down
6 changes: 2 additions & 4 deletions R/esci-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@
#' @importFrom statpsych ci.lc.mean.bs
#' @importFrom statpsych ci.lc.median.bs
#' @importFrom statpsych ci.lc.prop.bs
#' @importFrom statpsych ci.mean1
#' @importFrom statpsych ci.median1
#' @importFrom statpsych ci.oddsratio
#' @importFrom statpsych ci.phi
#' @importFrom statpsych ci.prop1
#' @importFrom statpsych ci.ratio.mean2
#' @importFrom statpsych ci.ratio.mean.ps
#' @importFrom statpsych ci.ratio.median2
#' @importFrom statpsych ci.ratio.median.ps
#' @importFrom statpsych ci.stdmean1
#' @importFrom statpsych ci.stdmean.ps
#' @importFrom stats aggregate
#' @importFrom stats anova
Expand All @@ -35,8 +31,10 @@
#' @importFrom stats qnorm
#' @importFrom stats predict
#' @importFrom stats pt
#' @importFrom stats pbinom
#' @importFrom stats pnorm
#' @importFrom stats qnorm
#' @importFrom stats qt
#' @importFrom stats quantile
#' @importFrom stats rnorm
#' @importFrom stats sd
Expand Down
8 changes: 5 additions & 3 deletions R/estimate_magnitude.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
#' If you want to compare your sample to a known value or reference, then
#' use [esci::estimate_mdiff_one()].
#'
#' The estimated mean is from [statpsych::ci.mean1()].
#' The estimated mean is from [statpsych::ci.mean1()] (renamed ci.mean as of
#' statpsych 1.6).
#'
#' The estimated median is from [statpsych::ci.median1()]
#' The estimated median is from [statpsych::ci.median1()] (renamed ci.median
#' as of statpsych 1.6)
#'
#'
#' @param data For raw data - A data frame or tibble
Expand Down Expand Up @@ -466,7 +468,7 @@ estimate_magnitude.vector <- function(
estimate$properties$data_source <- NULL

# 2 alpha CI for median
mdn_2a <- statpsych::ci.median1(
mdn_2a <- wrapper_ci.median(
alpha = (1 - conf_level)*2,
y =outcome_variable[!is.na(outcome_variable)]
)
Expand Down
6 changes: 4 additions & 2 deletions R/estimate_mdiff_one.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
#' it with [esci::plot_mdiff()] and you can test hypotheses with
#' [esci::test_mdiff()].
#'
#' The estimated mean differences are from [statpsych::ci.mean1()].
#' The estimated mean differences are from [statpsych::ci.mean1()] (renamed
#' ci.mean as of statpsych 1.6).
#'
#' The estimated SMDs are from [esci::CI_smd_one()].
#'
#' The estimated median differences are from [statpsych::ci.median1()]
#' The estimated median differences are from [statpsych::ci.median1()] (renamed
#' ci.median as of statpsych 1.6)
#'
#'
#' @param data For raw data - a data frame or tibble
Expand Down
3 changes: 2 additions & 1 deletion R/estimate_pdiff_one.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#' it with [esci::plot_pdiff()] and you can test hypotheses with
#' [esci::test_pdiff()].
#'
#' The estimated proportion differences are from [statpsych::ci.prop1()].
#' The estimated proportion differences are from [statpsych::ci.prop1()] (renamed
#' ci.prop as of statpsych 1.6).
#'
#'
#' @param data For raw data - a dataframe or tibble
Expand Down
3 changes: 2 additions & 1 deletion R/estimate_proportion.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#' If you want to compare your estimate to a known value or reference, then
#' use [esci::estimate_pdiff_one()].
#'
#' The estimated proportions are from [statpsych::ci.prop1()].
#' The estimated proportions are from [statpsych::ci.prop1()] (renamed
#' ci.prop as of statpsych 1.6).
#'
#'
#' @param data For raw data - a data frame or tibble
Expand Down
6 changes: 3 additions & 3 deletions R/overview.R
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ overview.base <- function(
# Analysis ----------------------------------------
if (n_means == 1) {
res <- as.data.frame(
statpsych::ci.mean1(
wrapper_ci.mean (
alpha = 1 - conf_level,
m = overview_table$mean,
sd = overview_table$sd,
Expand Down Expand Up @@ -725,7 +725,7 @@ wrap_ci_median1 <- function(

if(length(na.omit(x)) < 2) return(c(median(x), NA, NA, NA))

res <- statpsych::ci.median1(
res <- wrapper_ci.median(
alpha = 1 - conf_level,
y = if(na.rm) x[!is.na(x)] else x
)
Expand All @@ -743,7 +743,7 @@ wrap_ci_mean1 <- function(

if(length(x) < 2) return(c(mean(x), NA, NA, NA))

res <- statpsych::ci.mean1(
res <- wrapper_ci.mean(
alpha = 1 - conf_level,
m = mean(x, na.rm = na.rm),
sd = sd(x, na.rm = na.rm),
Expand Down
4 changes: 2 additions & 2 deletions R/overview_nominal.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ overview_nominal.base <- function(
res_ta <- res
} else {
res <- as.data.frame(
statpsych::ci.prop1(
wrapper_ci.prop(
alpha = 1 - conf_level,
f = overview_table$cases[x],
n = overview_table$n[x]
)
)

res_ta <- as.data.frame(
statpsych::ci.prop1(
wrapper_ci.prop(
alpha = (1 - conf_level)*2,
f = overview_table$cases[x],
n = overview_table$n[x]
Expand Down
101 changes: 75 additions & 26 deletions R/plot_aesthetics.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ esci_plot_mdiff_aesthetics <- function(
esci_plot_simple_aesthetics <- function(myplot, use_ggdist = TRUE) {
# Customize plot -------------------------------
# No legend

ggplot_version <- as.numeric(gsub("\\.", "", utils::packageVersion("ggplot2")))



myplot <- myplot + ggplot2::theme(legend.position = "none")

# Points
Expand All @@ -214,24 +219,43 @@ esci_plot_simple_aesthetics <- function(myplot, use_ggdist = TRUE) {

if (use_ggdist) {
myplot <- myplot + ggplot2::discrete_scale(
c("size", "point_size"),
"point_size_d",
function(n) return(c("raw" = 1, "summary" = 3))
aesthetics = c("size", "point_size"),
scale_name = if (ggplot_version >= 350) NULL else "point_size_d",
palette = function(n) return(c("raw" = 1, "summary" = 3))
)

} else {

if (ggplot_version >= 350) {
myplot <- myplot + ggplot2::discrete_scale(
aesthetics = c("size"),
palette = function(n) return(c("raw" = 1, "summary" = 1))
)

} else {
myplot <- myplot + ggplot2::discrete_scale(
aesthetics = c("size"),
scale_name = "point_size_d",
palette = function(n) return(c("raw" = 1, "summary" = 1))
)

}

}

if (ggplot_version >= 350) {
myplot <- myplot + ggplot2::discrete_scale(
c("size"),
"point_size_d",
function(n) return(c("raw" = 1, "summary" = 1))
aesthetics = c("alpha", "point_alpha"),
palette = function(n) return(c("raw" = 0.8, "summary" = 1))
)
} else {
myplot <- myplot + ggplot2::discrete_scale(
c("alpha", "point_alpha"),
"point_alpha_d",
function(n) return(c("raw" = 0.8, "summary" = 1))
)
}

myplot <- myplot + ggplot2::discrete_scale(
c("alpha", "point_alpha"),
"point_alpha_d",
function(n) return(c("raw" = 0.8, "summary" = 1))
)

# Error bars
myplot <- myplot + ggplot2::scale_linetype_manual(
Expand All @@ -241,28 +265,53 @@ esci_plot_simple_aesthetics <- function(myplot, use_ggdist = TRUE) {
values = c("summary" = "black"),
aesthetics = "interval_color"
)
myplot <- myplot + ggplot2::discrete_scale(
"interval_alpha",
"interval_alpha_d",
function(n) return(c("summary" = 1))
)
myplot <- myplot + ggplot2::discrete_scale(
"interval_size",
"interval_size_d",
function(n) return(c("summary" = 3))
)

if (ggplot_version >= 350) {
myplot <- myplot + ggplot2::discrete_scale(
aesthetics = "interval_alpha",
palette = function(n) return(c("summary" = 1))
)
myplot <- myplot + ggplot2::discrete_scale(
aesthetics = "interval_size",
palette = function(n) return(c("summary" = 3))
)

} else {

myplot <- myplot + ggplot2::discrete_scale(
aesthetics = "interval_alpha",
scale_name = "interval_alpha_d",
palette = function(n) return(c("summary" = 1))
)
myplot <- myplot + ggplot2::discrete_scale(
aesthetics = "interval_size",
scale_name = "interval_size_d",
palette = function(n) return(c("summary" = 3))
)

}


# Slab
myplot <- myplot + ggplot2::scale_fill_manual(
values = c("summary" = "gray"),
aesthetics = "slab_fill"
)
myplot <- myplot + ggplot2::discrete_scale(
"slab_alpha",
"slab_alpha_d",
function(n) return(c("summary" = 1))
)

if (ggplot_version >= 350) {
myplot <- myplot + ggplot2::discrete_scale(
aesthetics = "slab_alpha",
palette = function(n) return(c("summary" = 1))
)

} else {
myplot <- myplot + ggplot2::discrete_scale(
aesthetics = "slab_alpha",
scale_name = "slab_alpha_d",
palette = function(n) return(c("summary" = 1))
)

}

return(myplot)
}
4 changes: 2 additions & 2 deletions R/statpsych_apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ apply_ci_prop1 <- function(
) {

res <- as.data.frame(
statpsych::ci.prop1(
wrapper_ci.prop(
alpha = 1 - conf_level,
f = myrow[["cases"]],
n = myrow[["N"]]
Expand Down Expand Up @@ -279,7 +279,7 @@ apply_ci_mean1 <- function(
) {

res <- as.data.frame(
statpsych::ci.mean1(
wrapper_ci.mean(
alpha = 1 - conf_level,
m = myrow[["mean"]] - reference_mean,
sd = myrow[["sd"]],
Expand Down
Loading

0 comments on commit b2ed473

Please sign in to comment.