Conduct Web experiments using PHP, Part 2
By Paul Meagher2005-03-18
DOE explorer
* Simulates the contingency table data that you might observe if you were to run a Web offer experiment
* Performs a chi-square test on the simulated contingency table data
Use the doe_explorer.php script during the planning stages of a Web experiment to:
* Determine the number of subjects required to detect an hypothesized effect of a given size.
* Elicit rigorous subjective estimates of the poisson lambda parameters. These estimates can compute the expected cell counts to use in your test for the information value of the experiment.
* Determine whether possible findings warrant the expenditure of time and resources to run the Web experiment.
Listing 4 presents the doe_explorer.php source. The output of this script is displayed in the next section, "Explorer output."
Listing 4. Source code of doe_explorer.php
<?php
/**
* @package CHI
*
* Simulates and analyzes data from a hypothetical Web offer study.
*
* @author Paul Meagher
* @license PHP v3.0
* @version 0.3
*/
require_once "config.php";
require_once PHPMATH ."/PDL/PoissonDistribution.php";
require_once PHPMATH ."/CHI/Chi2D.php";
$chi = new Chi2D;
// Step 1. Load factors names and factor levels.
$factors["image"] = array("person", "product");
$factors["text"] = array("short", "long");
$chi->setFactors($factors);
// Step 2. Simulate the outcome of a Web offer study.
$lambda1 = 0.05; $lambda2 = 0.02;
$lambda3 = 0.02; $lambda4 = 0.03;
$trials = 500;
$pois1 = new PoissonDistribution($lambda1);
$pois2 = new PoissonDistribution($lambda2);
$pois3 = new PoissonDistribution($lambda3);
$pois4 = new PoissonDistribution($lambda4);
$cell1 = array_sum($pois1->RNG($trials));
$cell2 = array_sum($pois2->RNG($trials));
$cell3 = array_sum($pois3->RNG($trials));
$cell4 = array_sum($pois4->RNG($trials));
$obs_freqs["person"]["short"] = $cell1;
$obs_freqs["person"]["long"] = $cell2;
$obs_freqs["product"]["short"] = $cell3;
$obs_freqs["product"]["long"] = $cell4;
// Step 3. Load simulated observed frequencies.
$chi->setObservedFrequencies($obs_freqs);
// Step 4. Analyze the simulated data.
$chi->analyze();
// Step 5. Show cross tabulated
$chi->showContingencyTable();
echo "<br />";
// Step 6. Show residuals.
$chi->showResiduals();
// Step 7. Show bar graph of results
$params["figureTitle"] = "Web Offer Analysis";
$params["plotWidth"] = 300;
$params["plotHeight"] = 200;
$params["yTitle"] = "Responses";
$params["yMin"] = 0;
$params["yMax"] = 50;
$params["yTicks"] = 5;
$params["yHideMajor"] = false;
$params["yHideMinor"] = true;
$params["xTitle"] = "Offer Variants";
$params["xLabels"] = array("PER-SH","PER-LO","PRD-SH","PRD-LO");
$params["xHideMajor"] = true;
$params["xHideMinor"] = true;
$params["yData"] = array($cell1, $cell2, $cell3, $cell4);
$chi->showBarGraph($params);
echo "<br />";
// Step 8. Show line graph of results
$params["xTitle"] = "Image Factor";
$params["xLabels"] = array("PERSON","PRODUCT");
$params["yData1"] = array($cell1, $cell3);
$params["yData2"] = array($cell2, $cell4);
$chi->showLineGraph($params);
?>
Note that I selected the lambda parameters ($lambda1=0.05, $lambda2=0.02, $lambda3=0.02, $lambda4=0.03) and the trial parameters ($trials=500) in Listing 4 to illustrate how to simulate an interaction. I used empirically reasonable estimates of the lambda parameter sizes (0.05 success rate or less for responding to an ad banner).
The trials parameter value of 500 represents a reasonable estimate of the number of trials (sample size per condition) you would need to run in order to reliably observe the hypothesized interaction given your effect sizes (specified through different lambda settings). Without the doe_explorer.php tool, it would be more difficult to obtain a rigorous and intuitive sense of how sample size and effect sizes might interact in your experiment and what parameter estimates are reasonable to use.
First published by IBM developerWorks
|
|||||||||
You might also want to check these out:
|
Leave a Comment on "Conduct Web experiments using PHP, Part 2"
You must be logged in to post a comment.
Link to This Tutorial Page!

