Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/MeikeSteinhilber/sprtt i…
Browse files Browse the repository at this point in the history
…nto develop
  • Loading branch information
MeikeSteinhilber committed Jan 8, 2024
2 parents e2c4aaa + b90b988 commit cf42146
Show file tree
Hide file tree
Showing 3,198 changed files with 382,135 additions and 158 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
^CRAN-RELEASE$
^test_ANOVA\.R$
^compare_anova_script\.csv$
^revdep$
^lastMiKTeXException$
^CRAN-SUBMISSION$
10 changes: 4 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ Authors@R:
comment = c(ORCID = "0000-0001-7248-0662"))
)
Maintainer: Meike Steinhilber <Meike.Steinhilber@aol.com>
Description:
It is a toolbox for Sequential Probability Ratio Tests (SPRT), Wald (1945) <doi:10.2134/agronj1947.00021962003900070011x>.
Description: It is a toolbox for Sequential Probability Ratio Tests (SPRT), Wald (1945) <doi:10.2134/agronj1947.00021962003900070011x>.
SPRTs are applied to the data during the sampling process, ideally after each observation.
At any stage, the test will return a decision to either continue sampling or terminate and accept one of the specified hypotheses.
The seq_ttest() function performs sequential t tests developed by Rushton (1950) <doi:10.2307/2332385>, Rushton (1952) <doi:10.2307/2334026> and Hajnal (1961) <doi:10.2307/2333131>, based on the SPRT.
Specifically, seq_ttest() performs one-sample, two-sample, and paired t tests for testing one- and two-sided hypotheses.
For more information on the SPRT t test, see Schnuerch & Erdfelder (2019) <doi:10.1037/met0000234>.
The seq_anova() function allows to perform a sequential one-way fixed effects ANOVA (see Steinhilber et al. (2023) <> ).
The seq_ttest() function performs one-sample, two-sample, and paired t-tests for testing one- and two-sided hypotheses (Schnuerch & Erdfelder (2019) <doi:10.1037/met0000234>).
The seq_anova() function allows to perform a sequential one-way fixed effects ANOVA (Steinhilber et al. (2023) <doi:10.31234/osf.io/m64ne>).
Learn more about the package by using vignettes "browseVignettes(package = "sprtt")" or go to the website <https://meikesteinhilber.github.io/sprtt/>.
License: AGPL (>= 3)
URL: https://meikesteinhilber.github.io/sprtt/
BugReports: https://github.com/MeikeSteinhilber/sprtt/issues
Expand Down
8 changes: 7 additions & 1 deletion R/calc_plot_sprt.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ calc_plot_anova <- function(seq_anova_arguments, seq_steps) {
stop("wrong input for seq_steps argument.")
}


lr_log <- double(length(seq_steps))
sample_size <- double(length(seq_steps))
i = 1

k_groups_start <- table(seq_anova_arguments@data[1:seq_steps[1], 2])

if (any(k_groups_start < 2)) {
stop("The first 2*k_groups data points are not balanced. Every group needs two data points.
Solution: Use the argument 'plot' to define a customized vector with the sample size steps in the seq_anova() function")
}

for (position in seq_steps) {
temp_arguments@data <- seq_anova_arguments@data[1:position, ]
temp_arguments@total_sample_size <- position
Expand Down
3 changes: 2 additions & 1 deletion R/draw_sample_mixture.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ rnorm_mix <- function(n, mu1, sig1, mu2, sig2, gamma) {
#' @param f Cohen's f. The simulated effect size.
#' @param max_n sample size for the groups (total sample size = max_n*k_groups)
#' @param counter_n number of times the function tries to find a possible parameter combination for the distribution. Default value is set to 100.
#' @param verbose `TRUE` or `FALSE.` Print out more information about the internal process of sampling the parameters.
#' @param verbose `TRUE` or `FALSE.` Print out more information about the internal process of sampling the parameters
#' (the internal counter that was reached, some additional hints and the drawn parameters for the Gaussian Mixture distributions.)
#'
#' @return returns a data.frame with the columns y (observations) and x (factor_A).
#'
Expand Down
18 changes: 13 additions & 5 deletions R/plot_sprt.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
# #' @param B_boundary_log Log of the B boundary.
#' @param anova_results result object of the seq_anova() function (argument must be of class `seq_anova_results`).
#' @param labels show labels in the plot.
#' @param position_labels_x position of the boundary labels on the x-axis.
#' @param position_labels_y position of the boundary labels on the y-axis.
#' @param position_lr_x scales the position of the LR label on the x-axis.
#' @param position_labels_x position of the boundary labels on the x-axis. 0 positions the center on the 0 of the x-axis.
#' @param position_labels_y position of the boundary labels on the y-axis. 0 positions the labels on the dotted lines.
#' @param position_lr_x scales the position of the LR label on the x-axis. 0 positions the label directly under the last calculated LR.
#' @param position_lr_y scales the position of the LR label on the x-axis. 0 positions the label on the 0 of the y-axis
#' @param font_size font size of the plot.
#' @param line_size line size of the plot.
#' @param highlight_color highlighting color, default is "#CD2626" (red).
Expand All @@ -30,6 +31,7 @@ plot_anova <- function(anova_results,
position_labels_x = 0.15,
position_labels_y = 0.075,
position_lr_x = 0.05,
position_lr_y = NULL,
font_size = 25,
line_size = 1.5,
highlight_color = "#CD2626"
Expand All @@ -42,6 +44,10 @@ plot_anova <- function(anova_results,
stop("anova_results argument must be of class seq_anova_results.")
}

if (is.null(anova_results@plot)) {
stop("The anova_results@plot is NULL. Solution: The function argument `plot` must be set to TRUE in the seq_anova() function.")
}

A_boundary_log <- anova_results@plot$A_boundary_log
B_boundary_log <- anova_results@plot$B_boundary_log

Expand Down Expand Up @@ -106,11 +112,13 @@ plot_anova <- function(anova_results,
if (labels == TRUE) {
LR <- round(exp(results$lr_log[N_steps]), 2)
nLR <- results$sample_size[N_steps]
if (results$lr_log[N_steps]>0) {y_ = -0.5} else{y_ = 0.5}
if (is.null(position_lr_y)) {
if (results$lr_log[N_steps]>0) {position_lr_y = -0.5} else{position_lr_y = 0.5}
}
plot <- plot +
annotate(geom = "text",
x = results$sample_size[N_steps] + results$sample_size[N_steps]*position_lr_x,
y = y_,
y = position_lr_y,
label = glue("LR[{nLR}] ==~ {LR}"),
parse = TRUE,
size = font_size/.pt, color = highlight_color)
Expand Down
3 changes: 2 additions & 1 deletion R/seq_anova.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' `r lifecycle::badge("experimental")`
#'
#' Performs a sequential one-way fixed effects ANOVA, see Steinhilber et al. (2023) <doi:10.31234/osf.io/m64ne>
#' for more information.
#' for more information. The repeated measurement ANOVA is not implemented yet in this function. For more information check out the vignette `vignette("one_way_anova", package = "sprtt")`
#'
#' @param formula A formula specifying the model.
#' @param data A data frame in which the variables specified in the formula will be found.
Expand All @@ -30,6 +30,7 @@
#' If the data do not fit to this, you have to specify the sequential steps yourself in this argument.
#' `balanced` specifies that the step size is equal to the number of groups.
#' Attention: the calculation starts at the number of groups times two.
#' If the data do not fit to this, you have to specify the sequential steps yourself in this argument.
#'
#'@return An object of the S4 class [`seq_anova_results-class`]. Click on the
#' class link to see the full description of the slots.
Expand Down
13 changes: 10 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ editor_options:
mode: gfm
---

<!-- <a href='https://meikesteinhilber.github.io/sprtt/'><img src="man/figures/logo.png" align="right" height="139"/></a> <br> <br> -->
<!-- ATTENTION! see below -->

```{r setup, include=FALSE}
knitr::opts_chunk$set(
Expand All @@ -25,7 +25,7 @@ options(tibble.print_min = 5, tibble.print_max = 5)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/sprtt?color=green)](https://cran.r-project.org/package=sprtt)
[![total](https://cranlogs.r-pkg.org/badges/grand-total/sprtt)](https://cran.r-project.org/package=sprtt)
[![monthly](https://cranlogs.r-pkg.org/badges/sprtt)](https://cran.r-project.org/package=sprtt)
[![codecov](https://codecov.io/gh/MeikeSteinhilber/sprtt/branch/main/graph/badge.svg?token=IQHTDTRBAW)](https://codecov.io/gh/MeikeSteinhilber/sprtt) [![pkgdown](https://github.com/MeikeSteinhilber/sprtt/actions/workflows/pkgdown-pak.yaml/badge.svg)](https://github.com/MeikeSteinhilber/sprtt/actions/workflows/pkgdown-pak.yaml) [![R-CMD-check](https://github.com/MeikeSteinhilber/sprtt/actions/workflows/R-CMD-check-windows-macOs.yaml/badge.svg)](https://github.com/MeikeSteinhilber/sprtt/actions/workflows/R-CMD-check-windows-macOs.yaml)
[![codecov](https://codecov.io/gh/MeikeSteinhilber/sprtt/branch/main/graph/badge.svg?token=IQHTDTRBAW)](https://app.codecov.io/gh/MeikeSteinhilber/sprtt) [![pkgdown](https://github.com/MeikeSteinhilber/sprtt/actions/workflows/pkgdown-pak.yaml/badge.svg)](https://github.com/MeikeSteinhilber/sprtt/actions/workflows/pkgdown-pak.yaml) [![R-CMD-check](https://github.com/MeikeSteinhilber/sprtt/actions/workflows/R-CMD-check-windows-macOs.yaml/badge.svg)](https://github.com/MeikeSteinhilber/sprtt/actions/workflows/R-CMD-check-windows-macOs.yaml)


<!-- badges: end -->
Expand Down Expand Up @@ -84,6 +84,13 @@ Short examples can be found in the following paragraph.
>
> `#> results of function()`: is console output
```{r, code=xfun::read_utf8('inst/examples/seq_ttest.R')}
<!--
ATTENTION!
in the .md file must be changed by hand. Otherwise the picture is not found on the website and CRAN.
<img src="man/figures/figure-gfm/unnamed-chunk-3-1.png" width="100%" />
-->
```{r, code=xfun::read_utf8('inst/examples/sprtt_examples.R')}
```
120 changes: 38 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<!-- <a href='https://meikesteinhilber.github.io/sprtt/'><img src="man/figures/logo.png" align="right" height="139"/></a> <br> <br> -->
<!-- ATTENTION! see below -->

# sprtt

Expand All @@ -8,7 +8,7 @@
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/sprtt?color=green)](https://cran.r-project.org/package=sprtt)
[![total](https://cranlogs.r-pkg.org/badges/grand-total/sprtt)](https://cran.r-project.org/package=sprtt)
[![monthly](https://cranlogs.r-pkg.org/badges/sprtt)](https://cran.r-project.org/package=sprtt)
[![codecov](https://codecov.io/gh/MeikeSteinhilber/sprtt/branch/main/graph/badge.svg?token=IQHTDTRBAW)](https://codecov.io/gh/MeikeSteinhilber/sprtt)
[![codecov](https://codecov.io/gh/MeikeSteinhilber/sprtt/branch/main/graph/badge.svg?token=IQHTDTRBAW)](https://app.codecov.io/gh/MeikeSteinhilber/sprtt)
[![pkgdown](https://github.com/MeikeSteinhilber/sprtt/actions/workflows/pkgdown-pak.yaml/badge.svg)](https://github.com/MeikeSteinhilber/sprtt/actions/workflows/pkgdown-pak.yaml)
[![R-CMD-check](https://github.com/MeikeSteinhilber/sprtt/actions/workflows/R-CMD-check-windows-macOs.yaml/badge.svg)](https://github.com/MeikeSteinhilber/sprtt/actions/workflows/R-CMD-check-windows-macOs.yaml)

Expand Down Expand Up @@ -79,13 +79,20 @@ Short examples can be found in the following paragraph.
>
> `#> results of function()`: is console output
<!--
&#10;ATTENTION!
&#10;in the .md file must be changed by hand. Otherwise the picture is not found on the website and CRAN.
<img src="man/figures/figure-gfm/unnamed-chunk-3-1.png" width="100%" />
-->

``` r
# set seed --------------------------------------------------------------------
set.seed(333)

# load library ----------------------------------------------------------------
library(sprtt)

# t-TEST ----------------------------------------------------------------------
# one sample: numeric input ---------------------------------------------------
treatment_group <- rnorm(20, mean = 0, sd = 1)
results <- seq_ttest(treatment_group, mu = 1, d = 0.8)
Expand All @@ -99,93 +106,42 @@ results@likelihood_ratio
results["likelihood_ratio"]
#> [1] 965.0728

# two sample: numeric input----------------------------------------------------
treatment_group <- stats::rnorm(20, mean = 0, sd = 1)
control_group <- stats::rnorm(20, mean = 1, sd = 1)
seq_ttest(treatment_group, control_group, d = 0.8)
#>
#> ***** Sequential Two Sample t-test *****
#>
#> formula: treatment_group and control_group
#> test statistic:
#> log-likelihood ratio = 5.347, decision = accept H1
#> SPRT thresholds:
#> lower log(B) = -2.944, upper log(A) = 2.944
#> Log-Likelihood of the:
#> alternative hypothesis = -4.211
#> null hypothesis = -9.558
#> alternative hypothesis: true difference in means is not equal to 0.
#> specified effect size: Cohen's d = 0.8
#> degrees of freedom: df = 38
#> sample estimates:
#> mean of x mean of y
#> -0.05204 1.18768
#> *Note: to get access to the object of the results use the @ or [] instead of the $ operator.

# two sample: formula input ---------------------------------------------------
stress_level <- stats::rnorm(20, mean = 0, sd = 1)
sex <- as.factor(c(rep(1, 10), rep(2, 10)))
seq_ttest(stress_level ~ sex, d = 0.8)
#>
#> ***** Sequential Two Sample t-test *****
#>
#> formula: stress_level ~ sex
#> test statistic:
#> log-likelihood ratio = -1.455, decision = continue sampling
#> SPRT thresholds:
#> lower log(B) = -2.944, upper log(A) = 2.944
#> Log-Likelihood of the:
#> alternative hypothesis = -1.233
#> null hypothesis = 0.222
#> alternative hypothesis: true difference in means is not equal to 0.
#> specified effect size: Cohen's d = 0.8
#> degrees of freedom: df = 18
#> sample estimates:
#> mean of x mean of y
#> -0.23286 -0.08217
#> *Note: to get access to the object of the results use the @ or [] instead of the $ operator.

# NA in the data --------------------------------------------------------------
stress_level <- c(NA, stats::rnorm(20, mean = 0, sd = 2), NA)
sex <- as.factor(c(rep(1, 11), rep(2, 11)))
seq_ttest(stress_level ~ sex, d = 0.8, na.rm = TRUE)
# ANOVA -----------------------------------------------------------------------
# simulate data ---------------------------------------------------------------
set.seed(333)
data <- sprtt::draw_sample_normal(k_groups = 3,
f = 0.25,
sd = c(1, 1, 1),
max_n = 25)

# calculate sequential ANOVA --------------------------------------------------
results <- sprtt::seq_anova(y ~ x, f = 0.25, data = data, plot = TRUE)
# test decision
results@decision
#> [1] "continue sampling"
# test results
results
#>
#> ***** Sequential Two Sample t-test *****
#> ***** Sequential ANOVA *****
#>
#> formula: stress_level ~ sex
#> formula: y ~ x
#> test statistic:
#> log-likelihood ratio = -0.359, decision = continue sampling
#> log-likelihood ratio = 2.892, decision = continue sampling
#> SPRT thresholds:
#> lower log(B) = -2.944, upper log(A) = 2.944
#> Log-Likelihood of the:
#> alternative hypothesis = -1.923
#> null hypothesis = -1.564
#> alternative hypothesis = -2.715
#> null hypothesis = -5.607
#> alternative hypothesis: true difference in means is not equal to 0.
#> specified effect size: Cohen's d = 0.8
#> degrees of freedom: df = 18
#> sample estimates:
#> mean of x mean of y
#> -0.40818 0.42068
#> specified effect size: Cohen's f = 0.25
#> empirical Cohen's f = 0.4045074, 95% CI[0.129478, 0.6171581]
#> Cohen's f adjusted = 0.355
#> degrees of freedom: df1 = 2, df2 = 72
#> SS effect = 10.74731, SS residual = 65.68208, SS total = 76.42939
#> *Note: to get access to the object of the results use the @ or [] instead of the $ operator.

# work with dataset (data are in the package included) ------------------------
seq_ttest(monthly_income ~ sex, data = df_income, d = 0.8)
#>
#> ***** Sequential Two Sample t-test *****
#>
#> formula: monthly_income ~ sex
#> test statistic:
#> log-likelihood ratio = -9.514, decision = accept H0
#> SPRT thresholds:
#> lower log(B) = -2.944, upper log(A) = 2.944
#> Log-Likelihood of the:
#> alternative hypothesis = -8.093
#> null hypothesis = 1.421
#> alternative hypothesis: true difference in means is not equal to 0.
#> specified effect size: Cohen's d = 0.8
#> degrees of freedom: df = 118
#> sample estimates:
#> mean of x mean of y
#> 3072.086 3080.715
#> *Note: to get access to the object of the results use the @ or [] instead of the $ operator.
# plot results -----------------------------------------------------------------
sprtt::plot_anova(results)
```

<img src="man/figures/figure-gfm/unnamed-chunk-3-1.png" width="100%" />
64 changes: 18 additions & 46 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,26 @@
## Test environments
* local R installation (on windows), R 4.1.0
* ubuntu-16.04 (on GitHub Actions), R 4.0.0
* ubuntu-20.04 (on GitHub Actions)
* macOS-latest (on GitHub Actions)
* windows-latest (on GitHub Actions)
* R-hub
- Windows Server 2008 R2 SP1, R-devel, 32/64 bit
- Ubuntu Linux 20.04.1 LTS, R-release, GCC
- Fedora Linux, R-devel, clang, gfortran
* win builder
- using R version 4.1.0 (2021-05-18), using platform: x86_64-w64-mingw32 (64-bit)
- using R Under development (unstable) (2021-07-25 r80663), using platform: x86_64-w64-mingw32 (64-bit)
* GitHub Action
macos-latest (release)
windows-latest (release)
ubuntu-latest (devel)
ubuntu-latest (release)
ubuntu-latest (oldrel-1)

* macOS builder
Build system: r-release-macosx-arm64|4.3.0|macosx|macOS 13.3.1 (22E261)|Mac mini|Apple M1||en_US.UTF-8|macOS 11.3|clang-1403.0.22.14.1|GNU Fortran (GCC) 12.2.0
* win-builder

## R CMD check results
New submission
==> This is my first submission
── R CMD check results ────────────────── sprtt 0.2.0 ────
Duration: 2m 28.5s

Possibly mis-spelled words in DESCRIPTION:
Erdfelder (31:34)
Hajnal (25:5)
Rushton (24:49)
SPRT (22:54, 25:33, 31:5)
Schnuerch (31:22)
==> spelling is correct
0 errors ✔ | 0 warnings ✔ | 0 notes ✔

Found the following (possibly) invalid DOIs:
DOI: 10.2307/2332385
From: DESCRIPTION
Status: Forbidden
Message: 403
DOI: 10.2307/2333131
From: DESCRIPTION
Status: Forbidden
Message: 403
DOI: 10.2307/2334026
From: DESCRIPTION
Status: Forbidden
Message: 403
R CMD check succeeded

==> DOIs are correct!
## Reverse Dependencies
0 reverse dependencies

0 errors √ | 0 warnings √ | 1 note x

## last CRAN feedback
Please add () behind all function names in the description texts (DESCRIPTION file). e.g: 'seq_ttest' --> seq_ttest()
==> DONE

Please write references in the description of the DESCRIPTION file in the form authors (year) <doi:...>
==> DONE

Please add \value to .Rd files regarding exported methods and explain the functions results in the documentation.
==> DONE
## Change of licence from GPL to AGPL
all authors of the package accepted the change
(see open issue: https://github.com/MeikeSteinhilber/sprtt/issues/33)
2 changes: 1 addition & 1 deletion inst/examples/draw_sample_mixture.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data
data <- sprtt::draw_sample_mixture(
k_groups = 4,
f = 1.2, # very large effect size
max_n = 2,
max_n = 4,
counter_n = 1000, # increase of counter is necessary
verbose = TRUE # prints more information to the console
)
Expand Down
Loading

0 comments on commit cf42146

Please sign in to comment.