Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Conduct Web experiments using PHP, Part 2

By Paul Meagher
2005-03-18


Binomial sampling model

If 18 of the last 400 visitors to your Web site responded to your offer, then the maximum likelihood estimate (MLE) of the probability of responding p can be mathematically shown to be 18 / 400 = 0.045 with a Beta distribution for the p parameter. (This is illustrated further in "Implement Bayesian inference using PHP: Part 2.") This result also agrees with your common sense intuitions about the best estimate of p to use and the shape of your uncertainty about the estimate (represented by the Beta distribution).

Given this limited amount of information about your sample, you can construct a null effects binomial sampling model for your contingency table data by instantiating four separate binomial distributions with the same parameter values, as in Listing 1:

Listing 1. Sampling model consisting of four independent binomial distributions with same parameter values

<?php
require_once "config.php";
require_once PHPMATH . "/PDL/PoissonDistribution.php";

$trials = 100;
$p = 0.045;

$bin1 = new BinomialDistribution($trials, $p);
$bin2 = new BinomialDistribution($trials, $p);
$bin3 = new BinomialDistribution($trials, $p);
$bin4 = new BinomialDistribution($trials, $p);
?>


If you then call a binomial random number generator 100 times (as in, $bin->RNG(100)) for each instantiated binomial, you can obtain a simulated cell count by summing the returned array of 0s and 1s, as in Listing 2:

Listing 2. Simulating cell counts under null effect binomial sampling model

<?php
$cell1 = array_sum($bin1->RNG($trials));
$cell2 = array_sum($bin2->RNG($trials));
$cell3 = array_sum($bin3->RNG($trials));
$cell4 = array_sum($bin4->RNG($trials));
?>


You can use the values returned from your null effects binomial sampling model to simulate your contingency table data under the assumption that your experimental factors have no differential effect.

Conversely, a binomial effects sampling model can be implemented by instantiating your four binomial distributions with different p values to represent the differential effectiveness of your factors in eliciting a response.

Tutorial Pages:
» Categorical data analysis
» 2x2 contingency tables
» Sampling model
» Discrete probability distributions
» Binomial sampling model
» Poisson sampling model
» Envisioning your results
» Eliciting your prior distribution
» Model fitting with chi-square
» Null effects model
» Independence model
» Prior model
» DOE explorer
» Explorer output
» Conclusions
» Resources


First published by IBM developerWorks


 | Bookmark
Related Tutorials:
» Zend Framework Tutorial
» Port Scanning and Service Status Checking in PHP
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1

Ask A Question
characters left.