Metadata-Version: 2.4
Name: rstatistics
Version: 0.1.0
Summary: R's probability and statistics functions in pure Python: d/p/q/r distributions, t.test and friends, summary, quantile, with R's numbers and R's printed output
License: MIT License
        
        Copyright (c) 2026 ccc-claude-opus
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/ccc-claude-opus/rupy/tree/main/rstat
Keywords: statistics,probability,R,distributions,hypothesis-testing
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# rstat

R's probability and statistics functions in pure Python, with R's numbers and R's
printed output. There are no dependencies: vectors are plain `list[float]`.

```
pip install rstatistics
```

The package installs as `rstatistics` and is imported as `rstat`.

```python
import rstat as r

x = [5.1, 4.9, 6.2, 5.8, 6.0, 5.5, 5.3, 6.1]
print(r.t_test(x, mu=5.0))
print(r.summary(x))
```

```
	One Sample t-test

data:  x
t = 3.5696, df = 7, p-value = 0.009101
alternative hypothesis: true mean is not equal to 5
95 percent confidence interval:
 5.206762 6.018238
sample estimates:
mean of x 
   5.6125 

   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  4.900   5.250   5.650   5.612   6.025   6.200 
```

That is what R prints for `t.test(x, mu = 5)` and `summary(x)`.

## Names

R's names, with `_` for `.`: `t.test` is `t_test`, `lower.tail` is `lower_tail`,
`var.equal` is `var_equal`. R's `range`, `round` and `signif` of vectors are
`range_`, `round_` and `signif_`.

## What there is

| Area | Functions |
| --- | --- |
| Distributions (`d`, `p`, `q`) | `norm`, `unif`, `exp`, `gamma`, `chisq`, `beta`, `t`, `f` (`df`, `pf`, `qf`), `lnorm`, `weibull`, `cauchy`, `logis`, `binom`, `pois`, `geom`, `nbinom` (`d`, `p`), `hyper` (`d`, `p`); `lower_tail` and `log_p` as in R |
| Random numbers | `set_seed(seed)` returns a generator with R's numbers: `runif`, `rnorm`, `rexp`, `rlnorm`, `sample`, `sample_from` |
| Descriptive | `mean`, `var`, `sd`, `cov`, `cor` (pearson, spearman, kendall), `median`, `quantile` (types 1–9), `IQR`, `mad`, `fivenum`, `rank`, `scale`, `weighted_mean`, `summary` |
| Tests | `t_test` (one-sample, Welch, pooled, paired), `var_test`, `chisq_test`, `chisq_test_table`, `binom_test`, `prop_test`, `cor_test`; each returns an `HTest` that prints as R's `htest` and has `statistic`, `parameter`, `p_value`, `conf_int`, `estimate` |
| Special functions | `gamma`, `lgamma`, `beta`, `lbeta`, `choose`, `lchoose` |
| Printing | `format` (R's `format` of a numeric vector), `format_num`, `format_pval`, `print_vector`, `signif` |

### Random numbers

R keeps one generator for the session; rstat passes it explicitly. After
`set_seed(n)` the numbers are R's after `set.seed(n)` (Mersenne-Twister, normal
numbers by inversion, R ≥ 3.6's rejection sampling):

```python
g = r.set_seed(42)
print(r.print_vector(g.rnorm(5)))
# [1]  1.3709584 -0.5646982  0.3631284  0.6328626  0.4042683
```

## How close to R

`tests/` holds R scripts, their output in R 4.6, and the same programs in Python;
`python tests/run.py` compares them (`--regen` reruns R first). The printed output
of the tests, `format`, `summary`, `quantile` and the random numbers is identical
to R's; distribution functions agree with R to a relative 1e-12. One difference:
R names the data of a test from the call (`data:  c(20, 30, 25, 25)`), rstat from
the `data_name` argument (default `x`, `x and y`, ...).

## rupy

rstat is written in [rupy](https://github.com/ccc-claude-opus/rupy)'s typed subset
of Python, and rupy has it built in: `rupy run` compiles a program that imports
rstat to Rust, `rupy wasm` to WebAssembly, with the same output as CPython.

## License

MIT
