Skip to main content

rtests

Wilcoxon signed-rank tests, Mann-Whitney U tests and aligned rank transform repeated-measures ANOVA from Python through a local R installation.

Windows 11 setup

Install standard 64-bit Python and 64-bit R from python.org and CRAN. Keep the R installer's registry registration enabled. RStudio is optional and does not replace R. CI is configured for Python 3.12, 3.13 and 3.14 on Windows and Linux; the package retains its Python >=3.9 minimum.

In PowerShell, from this repository:

python -m venv .venv
.\.venv\Scripts\python.exe -m pip install .
.\.venv\Scripts\python.exe -m rtests.setup_r

For an already published release, replace pip install . with pip install --upgrade rtests.

No PowerShell activation, administrator rights, Git Bash, compiler or Rtools is required for standard Windows installations with available binary packages. rtests detects R through R_HOME, the Windows registry, or an R executable on PATH, then prepares the process's DLL search paths. Import rtests before initializing rpy2 yourself. Existing R_HOME values take precedence; an invalid value produces an actionable error instead of silently choosing another R.

The one-time R setup installs coin, ARTool and their required dependencies from CRAN into R's version-specific user library. On Windows it requests binary packages exclusively. Internet access is needed for initial setup. The matching R release and CPU architecture must have CRAN/rpy2 binaries; this is normally Windows x86-64. Updating R to a new minor version may require running setup again.

Missing R packages are also installed on first use. To prepare an offline deployment, run setup while online, then disable automatic installation:

$env:RTESTS_AUTO_INSTALL = "0"

To select a different library, set R_LIBS_USER before starting Python, or call rtests.ensure_r_packages(library="C:/path/to/R-library") for the current session. The Windows loader also avoids rpy2's import-time compiler probe, which can otherwise fail when Git Bash is installed without Rtools.

Rank tests

from rtests import r_wilcoxsign_test, r_mannwhitneyu_test

paired = r_wilcoxsign_test([1, 2, 3, 4, 5], [1, 1, 2, 2, 2])
independent = r_mannwhitneyu_test([1, 2, 3], [2, 3, 4])

Both tests return full-precision p_value and z_statistics from the same exact coin test. w_statistics (paired) or u_statistics (independent) comes from stats::wilcox.test. Values are extracted from R objects, independent of printing precision and language. W is R's positive signed-rank sum, printed as V by R; U refers to the first independent sample.

Paired tests keep coin's Pratt default for zero differences. Base R's W discards zero differences, so its ranks can differ from Pratt's ranks. To use Wilcoxon's zero handling for the coin calculation too:

paired = r_wilcoxsign_test(a, b, zero_method="Wilcoxon")

r_value is abs(Z) / sqrt(N), rounded to five decimals. N is the number of pairs for Pratt, nonzero pairs for Wilcoxon, or the combined size of independent samples. Completely zero differences/constant pooled samples return p=1, Z=0, and r=0 by convention because their variance is zero. Empty, nonfinite and unequally sized paired samples are rejected. get_stars uses inclusive upper thresholds of .05, .01, .001 and .0001 and rejects invalid p-values.

ART repeated-measures ANOVA

import pandas as pd
from rtests import R_art_rmanova

df = pd.read_csv("tests/anova.csv")
anova, posthocs = R_art_rmanova(
    df, indep_vars=["AR_or_VR", "H_or_NH"],
    response_var="RMSE_q1", subject_id_var="pid",
)

The default formula remains response ~ factor1 * factor2 + Error(subject). Specify formula= for another error/random-effects structure appropriate to your study design. Contrasts are calculated for all model terms, including nonsignificant terms, with Holm adjustment within each term by default. They are not restricted to significant omnibus effects. print_anova=False and print_latex_report=False disable the corresponding outputs.

The function copies the supplied data, keeps conversion contexts local, and does not overwrite the caller's R globals. Generated LaTeX command names encode punctuation and digits as letters so they remain valid TeX commands. Include the comment package to use the report's comment environments.

Tests and release build

.\.venv\Scripts\python.exe -m unittest discover -s tests -v
.\.venv\Scripts\python.exe -m pip install build twine
.\.venv\Scripts\python.exe -m build
.\.venv\Scripts\python.exe -m twine check dist/*

make.bat runs the build and metadata checks without uploading. Publish the reviewed files separately with python -m twine upload dist/*. Version 0.2.0 changes statistical outputs; see CHANGELOG.md before upgrading.

Metadata

Release files for rtests 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rtests 0.2.0
File Size Uploaded
rtests-0.2.0.tar.gz 21.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rtests 0.2.0
File Interpreter ABI Platform
rtests-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.8 kB

Release files / rtests-0.2.0.tar.gz

Download URL rtests-0.2.0.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d8e290c0b4f0373de1fc1b18b09313d7988c1299436a691a53fb00508750b28d
BLAKE2b-256 checksum
How to use checksums
379ff111da35ee638651e02d3b37ef96b37c6d58562eb89515a0fcb70a2dd741
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / rtests-0.2.0-py3-none-any.whl

Download URL rtests-0.2.0-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b5fb42e68940b43e4807ab944fa078208c90b5deea62688b305394731556fc2
BLAKE2b-256 checksum
How to use checksums
3ee958e2584951c3d840276c7b71073e881f75d614c07b56a4b187f611e19d5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page