Metadata-Version: 2.4
Name: rtests
Version: 0.2.0
Summary: Wilcoxon, Mann-Whitney and aligned rank transform ANOVA through R
Home-page: https://blindforreview.com
Author: BlindForReview.com
Author-email: mail@blindforreview.com
License: MIT
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: rpy2<3.7,>=3.6.9
Requires-Dist: rpy2-rinterface<3.7,>=3.6.7
Requires-Dist: pandas<4,>=2.2
Requires-Dist: tabulate<1,>=0.9
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# 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](https://www.python.org/downloads/windows/) and
[CRAN](https://cran.r-project.org/bin/windows/base/). 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:

```powershell
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:

```powershell
$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

```python
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:

```python
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

```python
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

```powershell
.\.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](CHANGELOG.md) before upgrading.
