MathPHP\Probability\Distribution\Table\StandardNormal::getZScoreForConfidenceInterval PHP Метод

getZScoreForConfidenceInterval() публичный статический Метод

Get Z score for confidence interval
public static getZScoreForConfidenceInterval ( string $cl ) : float
$cl string confidence level
Результат float Z score
    public static function getZScoreForConfidenceInterval(string $cl) : float
    {
        if (!array_key_exists($cl, self::Z_SCORES_FOR_CONFIDENCE_INTERVALS)) {
            throw new Exception\BadDataException('Not a valid confidence level');
        }
        return self::Z_SCORES_FOR_CONFIDENCE_INTERVALS[$cl];
    }

Usage Example

Пример #1
0
 /**
  * Confidence interval
  * Finds CI given a sample mean, sample size, and standard deviation.
  * Uses Z score.
  * https://en.wikipedia.org/wiki/Confidence_interval
  *          σ
  * ci = z* --
  *         √n
  *
  * interval = (μ - ci, μ + ci)
  *
  * Available confidence levels: See Probability\StandardNormalTable::Z_SCORES_FOR_CONFIDENCE_INTERVALS
  *
  * @param number $μ  sample mean
  * @param number $n  sample size
  * @param number $σ  standard deviation
  * @param string $cl confidence level (Ex: 95, 99, 99.5, 99.9, etc.)
  *
  * @return array [ ci, lower_bound, upper_bound ]
  */
 public static function confidenceInterval($μ, $n, $σ, string $cl) : array
 {
     $z = Table\StandardNormal::getZScoreForConfidenceInterval($cl);
     $ci = $z * ($σ / sqrt($n));
     $lower_bound = $μ - $ci;
     $upper_bound = $μ + $ci;
     return ['ci' => $ci, 'lower_bound' => $lower_bound, 'upper_bound' => $upper_bound];
 }