Last active
April 5, 2016 19:00
-
-
Save richshaw/1170b4a7c44530013cd998e9066c8901 to your computer and use it in GitHub Desktop.
Confidence Interval of Proportions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function to get confidence interval of proportions in PHP | |
* Based on https://onlinecourses.science.psu.edu/stat200/node/48 | |
*/ | |
/** | |
* Calculates CI, defaults to 95% z of 1.96 | |
* for 99% use z of 2.58 | |
*/ | |
function ci($prop, $n, $z = 1.96) { | |
//Std Error | |
$se = sqrt($prop * (1 - $prop) / $n); | |
return [$prop + $z * $se, | |
$prop - $z * $se]; | |
} | |
//Test | |
$ci = ci(0.640,1168); | |
//Returns [0.676,0.604] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment