Hyte 🦀
Hyte is a Hypothesis testing library crate for Rust with support for Z, T, and Pearson's Chi-squared tests.
Documentation 📃 | crates.io 📦 | Source 🌿
Installation
Include the following in your Cargo.toml file.
[]
= "0.1.0"
Quickstart
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:
- data:
Vec<Number> - expected_mean:
Number - tail:
Tails::LOWER,Tails::UPPER, orTails::BOTH - print_output:
bool
where 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 z;
use Tails;
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:
- observed_mean:
Number - expected_mean:
Number - sample_size:
u32 - pop_sd:
Number - tail:
Tails::LOWER,Tails::UPPER, orTails::BOTH - print_output:
bool
Here is an example:
use z;
use Tails;
You can perform a 1-sample T-test using t::test, a function that takes in the following arguments:
- data:
Vec<Number> - expected_mean:
Number - tail:
Tails::LOWER,Tails::UPPER, orTails::BOTH - print_output:
bool
where 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 t;
use Tails;
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:
- observed_mean:
Number - expected_mean:
Number - sample_size:
u32 - pop_sd:
Number - tail:
Tails::LOWER,Tails::UPPER, orTails::BOTH - print_output:
bool
Here is an example:
use t;
use Tails;
Hyte provides the t::test_two_samples function for performing a 2-sample T-test. It takes in the following arguments:
- data1:
Vec<Number> - data2:
Vec<Number> - print_output:
bool
Here's an example:
use t;
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:
- test_type:
&str - observed_matrix:
Matrix<Number> - gof_probabilities:
Option<Vec<f64>> - print_output:
bool
where 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"totest_typeOption::Nonevariant togof_probabilitiesMatrix::TwoDimensional(Vec<Vec<Number>>)toobserved_matrix
Here's an example:
use chisquare;
use Matrix;
To perform a goodness of fit test, you must pass in:
"gof"totest_typeOption::Some(f64)variant togof_probabilitiesMatrix::OneDimensional(Vec<Number>)toobserved_matrix
Here's an example:
use chisquare;
use Matrix;
Every 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:
- significance_level:
f64 - print_output:
bool
use z;
use Tails;
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_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 z;
use Tails;
Getting help
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 help;