| Crates.io | hyte |
| lib.rs | hyte |
| version | 0.1.1 |
| created_at | 2024-01-09 19:39:36.018674+00 |
| updated_at | 2024-01-09 21:27:31.559874+00 |
| description | A hypothesis testing library crate for Z, T, and Pearson's Chi-squared tests. |
| homepage | |
| repository | https://github.com/abyanmajid/hyte |
| max_upload_size | |
| id | 1094467 |
| size | 55,769 |
Hyte is a Hypothesis testing library crate for Rust with support for Z, T, and Pearson's Chi-squared tests.
Documentation 📃 | crates.io 📦 | Source 🌿
Include the following in your Cargo.toml file.
[dependencies]
hyte = "0.1.0"
The following are collapsible contents, each containing snippets to help you get started.
You can perform a 1-sample Z-test using z::test, a function that takes in the following arguments:
Vec<Number>NumberTails::LOWER, Tails::UPPER, or Tails::BOTHboolwhere Number is a generic that accepts integers and floats. Here is an example of a how you can perform a lower-tailed 1-sample Z-test:
use hyte::z;
use hyte::utils::Tails;
fn main() {
let data = vec![1, 2, 3, 4, 5];
let results = z::test(data, 3.5, Tails::LOWER, true).unwrap();
}
Should you need to perform upper-tailed or 2-sided Z-tests, simply pass the Tails::UPPER or Tails::BOTH variants to tail.
You can alternatively perform Z-tests using the z::test_dataless function which takes in numerical summaries including observed mean, sample size, and population standard deviation, all in replacement of data. The z::test_dataless function takes the following arguments:
NumberNumberu32NumberTails::LOWER, Tails::UPPER, or Tails::BOTHboolHere is an example:
use hyte::z;
use hyte::utils::Tails;
fn main() {
let results = z::test_dataless(1.2, 1.0, 30, 0.5, Tails::LOWER, true).unwrap();
}
You can perform a 1-sample T-test using t::test, a function that takes in the following arguments:
Vec<Number>NumberTails::LOWER, Tails::UPPER, or Tails::BOTHboolwhere Number is a generic that accepts integers and floats. Here is an example of a how you can perform a lower-tailed 1-sample T-test:
use hyte::t;
use hyte::utils::Tails;
fn main() {
let data = vec![2.5, 2.9, 3.1, 2.6, 2.7, 2.8, 3.0, 3.2];
let results = t::test(data, 3, Tails::LOWER, true).unwrap();
}
You can alternatively perform T-tests using the t::test_dataless function which takes in numerical summaries including observed mean, sample size, and population standard deviation, all in replacement of data. The t::test_dataless function takes the following arguments:
NumberNumberu32NumberTails::LOWER, Tails::UPPER, or Tails::BOTHboolHere is an example:
use hyte::t;
use hyte::utils::Tails;
fn main() {
let results = t::test_dataless(1.2, 1.0, 30, 0.5, Tails::LOWER, true).unwrap();
}
Hyte provides the t::test_two_samples function for performing a 2-sample T-test. It takes in the following arguments:
Vec<Number>Vec<Number>boolHere's an example:
use hyte::t;
fn main() {
let group1 = vec![20, 22, 19, 20, 21, 20, 19, 21, 22, 18];
let group2 = vec![22, 24, 23, 24, 25, 23, 24, 23, 22, 24];
let results = t::test_two_samples(group1, group2, true).unwrap();
}
The chisquare module only contains one funtion chisquare::test which can be used to perform both Pearson's Chi-squared test of independence and goodness of fit. It takes on the following arguments:
&strMatrix<Number>Option<Vec<f64>>boolwhere Matrix<Number> is an enum with two variants: Matrix::TwoDimensional(Vec<Vec<Number>>) and Matrix::OneDimensional(Vec<Number>).
To perform a test of independence, you must pass in:
"toi" to test_typeOption::None variant to gof_probabilitiesMatrix::TwoDimensional(Vec<Vec<Number>>) to observed_matrixHere's an example:
use hyte::chisquare;
use hyte::utils::Matrix;
fn main() {
let observed_frequencies = Matrix::TwoDimensional(vec![vec![762, 327, 468],
vec![484, 239, 477]]);
let results = chisquare::test(
"toi",
observed_frequencies,
None,
true
).unwrap();
}
To perform a goodness of fit test, you must pass in:
"gof" to test_typeOption::Some(f64) variant to gof_probabilitiesMatrix::OneDimensional(Vec<Number>) to observed_matrixHere's an example:
use hyte::chisquare;
use hyte::utils::Matrix;
fn main() {
let results = chisquare::test(
"gof",
Matrix::OneDimensional(vec![30, 40, 30]),
Some(vec![0.25, 0.5, 0.25]),
true
).unwrap();
}
concludeEvery instance of a test result such as ZResult, TResult, and ChiSquareResult have a method conclude which returns a Conclusion variant (one of Reject or DoNotReject). The conclude method takes in two parameters:
f64booluse hyte::z;
use hyte::utils::Tails;
fn main() {
let results = z::test(vec![1, 2, 3, 4, 5], 3.5, Tails::LOWER, true).unwrap();
let conclusion = results.conclude(0.1, true);
}
conclude checks if the p-value assigned to self.p exceeds the significance level. If self.p < significance_level, then conclude will return the Reject variant. Otherwise, it will return the DoNotReject variant.
conclude_by_conventionconclude_by_convention is an alternative to conclude. It assumes a significance level of 0.05, which is widely regarded as an appropriate default in statistics.
use hyte::z;
use hyte::utils::Tails;
fn main() {
let results = z::test(vec![1, 2, 3, 4, 5], 3.5, Tails::LOWER, true).unwrap();
let conclusion = results.conclude_by_convention(true);
}
The documentation for this crate can be found at docs.rs/hyte. Alternatively, you can print a short manual to the standard output by calling the help function.
use hyte::help;
fn main() {
help();
}