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.1

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.1
File Size Uploaded Provenance Actions
rtests-0.2.1.tar.gz 22.3 kB Without provenance Details for rtests-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 35.0 kB

Release files / rtests-0.2.1.tar.gz

Download URL rtests-0.2.1.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c8100daebc1212d34791e081f43568eebbdfb3f4cf2785d1742cab82dfb24a37
BLAKE2b-256 checksum
How to use checksums
c95589f5c0aff78ae64db6999e31946be8346deceaec6e017d1924735d211b7b
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.1-py3-none-any.whl

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

Security for rtests 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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