You are here

public static function PHPExcel_Calculation_Statistical::TDIST in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Statistical.php \PHPExcel_Calculation_Statistical::TDIST()

* TDIST * * Returns the probability of Student's T distribution. * *

Parameters

float $value Value for the function: * @param float $degrees degrees of freedom * @param float $tails number of tails (1 or 2) * @return float

1 call to PHPExcel_Calculation_Statistical::TDIST()
PHPExcel_Calculation_Statistical::TINV in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Statistical.php
* TINV * * Returns the one-tailed probability of the chi-squared distribution. * *

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Statistical.php, line 3219

Class

PHPExcel_Calculation_Statistical
PHPExcel_Calculation_Statistical

Code

public static function TDIST($value, $degrees, $tails) {
  $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
  $degrees = floor(PHPExcel_Calculation_Functions::flattenSingleValue($degrees));
  $tails = floor(PHPExcel_Calculation_Functions::flattenSingleValue($tails));
  if (is_numeric($value) && is_numeric($degrees) && is_numeric($tails)) {
    if ($value < 0 || $degrees < 1 || $tails < 1 || $tails > 2) {
      return PHPExcel_Calculation_Functions::NaN();
    }

    //	tdist, which finds the probability that corresponds to a given value
    //	of t with k degrees of freedom. This algorithm is translated from a
    //	pascal function on p81 of "Statistical Computing in Pascal" by D
    //	Cooke, A H Craven & G M Clark (1985: Edward Arnold (Pubs.) Ltd:
    //	London). The above Pascal algorithm is itself a translation of the
    //	fortran algoritm "AS 3" by B E Cooper of the Atlas Computer
    //	Laboratory as reported in (among other places) "Applied Statistics
    //	Algorithms", editied by P Griffiths and I D Hill (1985; Ellis
    //	Horwood Ltd.; W. Sussex, England).
    $tterm = $degrees;
    $ttheta = atan2($value, sqrt($tterm));
    $tc = cos($ttheta);
    $ts = sin($ttheta);
    $tsum = 0;
    if ($degrees % 2 == 1) {
      $ti = 3;
      $tterm = $tc;
    }
    else {
      $ti = 2;
      $tterm = 1;
    }
    $tsum = $tterm;
    while ($ti < $degrees) {
      $tterm *= $tc * $tc * ($ti - 1) / $ti;
      $tsum += $tterm;
      $ti += 2;
    }
    $tsum *= $ts;
    if ($degrees % 2 == 1) {
      $tsum = M_2DIVPI * ($tsum + $ttheta);
    }
    $tValue = 0.5 * (1 + $tsum);
    if ($tails == 1) {
      return 1 - abs($tValue);
    }
    else {
      return 1 - abs(1 - $tValue - $tValue);
    }
  }
  return PHPExcel_Calculation_Functions::VALUE();
}