MathPHP\Statistics\Significance::tTestOneSample PHP Method

tTestOneSample() public static method

https://en.wikipedia.org/wiki/Student%27s_t-test Hₐ - H₀ M - μ M - μ M - μ z = ------- = ----- = ----- = ----- σ σ SEM σ/√n p1 = CDF below if left tailed = CDF above if right tailed p2 = CDF outside
public static tTestOneSample ( number $Hₐ, number $s, integer $n, number $H₀ ) : array
$Hₐ number Alternate hypothesis (M Sample mean)
$s number SD of sample
$n integer Sample size
$H₀ number Null hypothesis (μ₀ Population mean)
return array [ z => z score p1 => one-tailed p value (left or right tail depends on how Hₐ differs from H₀) p2 => two-tailed p value ]
    public static function tTestOneSample($Hₐ, $s, $n, $H₀) : array
    {
        // Calculate test statistic t
        $t = self::tScore($Hₐ, $s, $n, $H₀);
        // Degrees of freedom
        $ν = $n - 1;
        // One- and two-tailed P values
        if ($Hₐ < $H₀) {
            $p1 = StudentT::CDF($t, $ν);
        } else {
            $p1 = StudentT::above($t, $ν);
        }
        $p2 = StudentT::outside(-abs($t), abs($t), $ν);
        return ['t' => $t, 'p1' => $p1, 'p2' => $p2];
    }