Пример #1
0
function ab_test_conversion_rate($test, $alt)
{
    $p = (int) ab_tests_total_participants_for_alternative($test, $alt);
    //$c1 = (int)ab_tests_total_conversions_for_alternative($test,$alt);
    $c2 = (int) ab_tests_total_converted_for_alternative($test, $alt);
    if ($p > 0) {
        $conv_rate = $c2 / $p * 100;
    } else {
        $conv_rate = 0;
    }
    return $conv_rate;
}
Пример #2
0
/**
 * @param unknown_type $test
 * @param unknown_type $probability
 */
function ab_tests_score($test, $probability = 90)
{
    global $ab_tests;
    //i am going to create a nice array/mixed type thingy
    //that will carry all the results from this function
    $result = array();
    //get all alternatives for this test
    $alts = $ab_tests[$test]['alternatives'];
    //	echo "<br>alts: "; print_r($alts);
    //gather a list of conversion rates for each test
    $conversion_rates = array();
    foreach ($alts as $alt) {
        $conversion_rates[$alt] = ab_test_conversion_rate($test, $alt);
    }
    arsort($conversion_rates);
    $result['sorted_alts'] = $conversion_rates;
    //	echo "<br>sortedalts: "; print_r($conversion_rates);
    //base is the second best result
    $base = array_slice($conversion_rates, 1, 1);
    $result['base'] = $base;
    //	echo "<br>base: "; print_r($base);
    //calculate z-score for base:
    $base_name = array_slice(array_keys($conversion_rates), 1, 1);
    $base_name = $base_name[0];
    //	echo "<br>base name: "; print_r($base_name);
    $result['base_name'] = $base_name;
    $pc = ab_test_conversion_rate($test, $base_name) / 100;
    $nc = (int) ab_tests_total_participants_for_alternative($test, $base_name);
    //	echo "<br>pc: ". $pc . " nc:" . $nc;
    $z_scores = array();
    $percentiles = array();
    foreach ($conversion_rates as $alt => $rate) {
        //		echo "<br>rate: "; print_r($alt); echo " "; print_r($rate);
        $p = ab_test_conversion_rate($test, $alt) / 100;
        $n = (int) ab_tests_total_participants_for_alternative($test, $alt);
        //prevent division by zero
        $z_scores[$alt] = 0;
        $percentiles[$alt] = 0;
        if ($n == 0 || $nc == 0) {
            continue;
        }
        //z-score is the difference over the std deviation
        //(p - pc) / ((p * (1-p)/n) + (pc * (1-pc)/nc)).abs ** 0.5
        $std_deviation = pow(abs($p * (1 - $p) / $n + $pc * (1 - $pc) / $nc), 0.5);
        if ($std_deviation == 0) {
            continue;
        }
        $z_scores[$alt] = ($p - $pc) / $std_deviation;
        $percentiles[$alt] = convert_z_score_to_percentile(abs($z_scores[$alt]));
    }
    //	echo "<br>z-score: "; print_r($z_scores);
    $result['z-scores'] = $z_scores;
    $result['percentiles'] = $percentiles;
    //find the least converted one that converted more than 0 times
    $least = false;
    //fast forward to the end
    end($conversion_rates);
    if (current($conversion_rates) > 0) {
        $least['name'] = key($conversion_rates);
        $least['rate'] = current($conversion_rates);
    } else {
        //keep rewinding until you find one
        while (prev($conversion_rates) !== false && $least !== false) {
            if (current($conversion_rates) > 0) {
                $least['name'] = key($conversion_rates);
                $least['rate'] = current($conversion_rates);
            }
        }
    }
    //	echo "<br>least: "; print_r($least);
    $result['least'] = $least;
    $differences = array();
    foreach ($conversion_rates as $alt => $rate) {
        $c1 = ab_test_conversion_rate($test, $alt);
        $c2 = $least['rate'];
        //		echo "<br>c1: " . $c1 . " c2: " . $c2;
        $differences[$alt] = $c1 - $c2;
    }
    //	echo "<br>differences: "; print_r($differences);
    $result['differences'] = $differences;
    $best = array_slice(array_keys($conversion_rates), 0, 1);
    $best = $best[0];
    $result['best'] = $best;
    //	echo "<br>best: "; print_r($best);
    //print_r($result);
    return $result;
}
Пример #3
0
    echo "<P class=\"indent\" style='color: #556; font-size: 12px'>" . $test['description'];
    if ($forced_alternative != null) {
        //echo "<P class=\"indent\" style='color: #999; font-size: 15px; margin-top: 12px'>" .  "Currently forced to show option <u style='color: #666'>$forced_alternative</u> for all participants";
        /*echo '  <a href="?force=true&test=' . $test['name'] . '&alt=' . "!!null!!" . '" class="red-button pcb">
        		<span style="color: black;">Clear</span>
        		</a>'; */
    }
    $j = 0;
    $a = array();
    $total_converted = 0;
    $total_conversions = 0;
    $total_particants = 0;
    $array_of_conversion_rates = array();
    echo "<div class=\"alternatives\">";
    foreach ($alternatives as $alt) {
        $p = $a[$alt]['participants'] = (int) ab_tests_total_participants_for_alternative($name, $alt);
        $c1 = $a[$alt]['conversions'] = (int) ab_tests_total_conversions_for_alternative($name, $alt);
        $c2 = $a[$alt]['converted'] = (int) ab_tests_total_converted_for_alternative($name, $alt);
        if ($p > 0) {
            $conv_rate = $c2 / $p * 100;
        } else {
            $conv_rate = 0;
        }
        $conv_rate = round($conv_rate, 3);
        $array_of_conversion_rates[] = array($j + 1, $conv_rate);
        echo "<h3>Alternative <span class=\"alternative\">" . $alt . "</span>:";
        if ($forced_alternative != $alt) {
            echo '  <a href="?force=true&test=' . urlencode($test['name']) . '&alt=' . urlencode($alt) . '#' . urlencode($name) . '" class="grey-button pcb">
			<span style="color: #666;">Show Always</span>
			</a>';
        } else {