How to return a sample size by population using PHP.
The formula is s = Z^2 * (p) * (1-p) / c^2 where , Z is the confidence level, and c is the confidence interval. Then:
ss = s / [1+(s-1 / pop)] where ss = sample size and pop = population size. Here is a simple PHP function I wrote the implements the formula.
function getSampleSize($pop){ //$pop = 10000; // population $Z = 1.99; // confidence level $c = .03; // confidence interval $p = .5; $top = pow($Z,2)*($p)*(1-$p); $bot = pow($c,2); $ss = ($top/$bot); return round($ss/(1+($ss-1)/$pop)); }
I wrote this as a way to randomly sample a table for errors. We’ll see if it works.
Resources: