Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]
1 <?php 2 3 namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; 4 5 use PhpOffice\PhpSpreadsheet\Calculation\Functions; 6 use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Averages; 7 use PhpOffice\PhpSpreadsheet\Calculation\Statistical\StandardDeviations; 8 9 class StandardNormal 10 { 11 /** 12 * NORMSDIST. 13 * 14 * Returns the standard normal cumulative distribution function. The distribution has 15 * a mean of 0 (zero) and a standard deviation of one. Use this function in place of a 16 * table of standard normal curve areas. 17 * 18 * @param mixed $value Float value for which we want the probability 19 * 20 * @return float|string The result, or a string containing an error 21 */ 22 public static function cumulative($value) 23 { 24 return Normal::distribution($value, 0, 1, true); 25 } 26 27 /** 28 * NORM.S.DIST. 29 * 30 * Returns the standard normal cumulative distribution function. The distribution has 31 * a mean of 0 (zero) and a standard deviation of one. Use this function in place of a 32 * table of standard normal curve areas. 33 * 34 * @param mixed $value Float value for which we want the probability 35 * @param mixed $cumulative Boolean value indicating if we want the cdf (true) or the pdf (false) 36 * 37 * @return float|string The result, or a string containing an error 38 */ 39 public static function distribution($value, $cumulative) 40 { 41 return Normal::distribution($value, 0, 1, $cumulative); 42 } 43 44 /** 45 * NORMSINV. 46 * 47 * Returns the inverse of the standard normal cumulative distribution 48 * 49 * @param mixed $value Float probability for which we want the value 50 * 51 * @return float|string The result, or a string containing an error 52 */ 53 public static function inverse($value) 54 { 55 return Normal::inverse($value, 0, 1); 56 } 57 58 /** 59 * GAUSS. 60 * 61 * Calculates the probability that a member of a standard normal population will fall between 62 * the mean and z standard deviations from the mean. 63 * 64 * @param mixed $value 65 * 66 * @return float|string The result, or a string containing an error 67 */ 68 public static function gauss($value) 69 { 70 $value = Functions::flattenSingleValue($value); 71 if (!is_numeric($value)) { 72 return Functions::VALUE(); 73 } 74 75 return self::distribution($value, true) - 0.5; 76 } 77 78 /** 79 * ZTEST. 80 * 81 * Returns the one-tailed P-value of a z-test. 82 * 83 * For a given hypothesized population mean, x, Z.TEST returns the probability that the sample mean would be 84 * greater than the average of observations in the data set (array) — that is, the observed sample mean. 85 * 86 * @param mixed $dataSet The dataset should be an array of float values for the observations 87 * @param mixed $m0 Alpha Parameter 88 * @param mixed $sigma A null or float value for the Beta (Standard Deviation) Parameter; 89 * if null, we use the standard deviation of the dataset 90 * 91 * @return float|string (string if result is an error) 92 */ 93 public static function zTest($dataSet, $m0, $sigma = null) 94 { 95 $dataSet = Functions::flattenArrayIndexed($dataSet); 96 $m0 = Functions::flattenSingleValue($m0); 97 $sigma = Functions::flattenSingleValue($sigma); 98 99 if (!is_numeric($m0) || ($sigma !== null && !is_numeric($sigma))) { 100 return Functions::VALUE(); 101 } 102 103 if ($sigma === null) { 104 $sigma = StandardDeviations::STDEV($dataSet); 105 } 106 $n = count($dataSet); 107 108 return 1 - self::cumulative((Averages::average($dataSet) - $m0) / ($sigma / sqrt($n))); 109 } 110 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body