MathPHP\Statistics\Experiment::oddsRatio PHP Method

oddsRatio() public static method

Ratio which quantitatively describes the association between the presence/absence of "A" and the presence/absence of "B" for individuals in the population. https://en.wikipedia.org/wiki/Odds_ratio http://www.bmj.com/content/343/bmj.d2304 a / b OR = ----- c / d Standard error of the log odds ratio: ______________ 1 1 1 1 SS{ln(OR)} = / - + - - - + - √ a b c d CI Range(95%) = exp( ln(OR) - z × SS{ln(OR)} ) to exp( ln(OR) + z × SS{ln(OR)} ) P = exp((-0.717 * z) - (0.416 * z²))
public static oddsRatio ( integer $a, integer $b, integer $c, integer $d ) : array
$a integer Exposed and event present
$b integer Exposed and event absent
$c integer Non-exposed and event present
$d integer Non-exposed and event absent
return array [ OR, ci_lower_bound, ci_upper_bound, p ]
    public static function oddsRatio(int $a, int $b, int $c, int $d) : array
    {
        // Odds ratio
        $OR = $a / $b / ($c / $d);
        // Standard error of the log odds ratio
        $ln⟮OR⟯ = log($OR);
        $SS{ln⟮OR⟯} = sqrt(1 / $a + 1 / $b + 1 / $c + 1 / $d);
        // Confidence interval
        $ci_lower_bound = exp($ln⟮OR⟯ - self::Z * $SS{ln⟮OR⟯});
        $ci_upper_bound = exp($ln⟮OR⟯ + self::Z * $SS{ln⟮OR⟯});
        // P-value (significance level)
        $est = log($OR);
        // estimate of effect
        $l = log($ci_lower_bound);
        // ln CI lower bound
        $u = log($ci_upper_bound);
        // ln CI upper bound
        $SE = ($u - $l) / (2 * self::Z);
        // standard error
        $z = abs($est / $SE);
        // test statistic z
        $p = exp(self::NORMAL_LOWER_TAIL_PROBABILITY * $z - self::NORMAL_UPPER_TAIL_PROBABILITY * $z ** 2);
        return ['OR' => $OR, 'ci_lower_bound' => $ci_lower_bound, 'ci_upper_bound' => $ci_upper_bound, 'p' => $p];
    }