Inheritance: extends Continuous
Example #1
0
 /**
  * Cumulative distribution function
  *
  * Fᵥ,ᵤ(x) = Fᵥ,ᵤ(x),      if x ≥ 0
  *         = 1 - Fᵥ,₋ᵤ(x)  if x < 0
  *
  * @param number $x
  * @param int    $ν Degrees of freedom
  * @param number $μ Noncentrality parameter
  *
  * @return number
  */
 public static function CDF($x, int $ν, $μ)
 {
     Support::checkLimits(self::LIMITS, ['x' => $x, 'ν' => $ν, 'μ' => $μ]);
     if ($μ == 0) {
         return StudentT::CDF($x, $ν);
     }
     if ($x >= 0) {
         return self::F($x, $ν, $μ);
     }
     return 1 - self::F($x, $ν, -$μ);
 }
Example #2
0
 /**
  * The prediction interval of the regression
  *                        _________________
  *                       /1    1   (x - x̄)²
  * PI(x,p,q) = t * sy * / - +  - + --------
  *                     √  q    n     SSx
  *
  * Where:
  *   t is the critical t for the p value
  *   sy is the estimated standard deviation of y
  *   q is the number of replications
  *   n is the number of data points
  *   x̄ is the average of the x values
  *   SSx = ∑(x - x̄)²
  *
  * If $p = .05, then we can say we are 95% confidence that the future averages of $q trials at $x
  * will be within an interval of evaluate($x) ± PI($x, .05, $q).
  *
  * @param number $x
  * @param number $p  0 < p < 1 The P value to use
  * @param int    $q  Number of trials
  *
  * @return number
  */
 public function PI($x, $p, $q = 1)
 {
     $V = $this->regressionVariance($x) + 1 / $q;
     $σ² = $this->meanSquareResidual();
     // The t-value
     $t = StudentT::inverse2Tails($p, $this->ν);
     return $t * sqrt($σ² * $V);
 }
Example #3
0
 /**
  * Two-sample t-test
  * Test the means of two samples.
  * https://en.wikipedia.org/wiki/Student%27s_t-test
  *
  *      μ₁ - μ₂ - Δ
  * z = --------------
  *        _________
  *       /σ₁²   σ₂²
  *      / --- + ---
  *     √   n₁    n₂
  *
  * where
  *  μ₁ is sample mean 1
  *  μ₂ is sample mean 2
  *  Δ  is the hypothesized difference between the population means (0 if testing for equal means)
  *  σ₁ is standard deviation of sample mean 1
  *  σ₂ is standard deviation of sample mean 2
  *  n₁ is sample size of mean 1
  *  n₂ is sample size of mean 2
  *
  * For Student's t distribution CDF, degrees of freedom:
  *  ν = (n₁ - 1) + (n₂ - 1)
  *
  * p1 = CDF above
  * p2 = CDF outside
  *
  * @param number $μ₁ Sample mean of population 1
  * @param number $μ₂ Sample mean of population 2
  * @param number $n₁ Sample size of population 1
  * @param number $n₂ Sample size of population 1
  * @param number $σ₁ Standard deviation of sample mean 1
  * @param number $σ₂ Standard deviation of sample mean 2
  * @param number $Δ  (Optional) hypothesized difference between the population means (0 if testing for equal means)
  *
  * @return array [
  *   t  => t score
  *   p1 => one-tailed p value
  *   p2 => two-tailed p value
  * ]
  */
 public static function tTestTwoSample($μ₁, $μ₂, $n₁, $n₂, $σ₁, $σ₂, $Δ = 0) : array
 {
     // Calculate t score (test statistic)
     $t = ($μ₁ - $μ₂ - $Δ) / sqrt($σ₁ ** 2 / $n₁ + $σ₂ ** 2 / $n₂);
     // Degrees of freedom
     $ν = $n₁ - 1 + ($n₂ - 1);
     // One- and two-tailed P values
     $p1 = StudentT::above(abs($t), $ν);
     $p2 = StudentT::outside(-abs($t), abs($t), $ν);
     return ['t' => $t, 'p1' => $p1, 'p2' => $p2];
 }