ANOVA Statistical Programming with PHP
Pages: 1, 2, 3, 4
Step 3: Show Box Plot
Early in your analysis you should graph your data so that you are being
guided by proper overall intuitions about your data. A commonly recommended way
to visualize ANOVA data is to use side-by-side box plots for each treatment
level. To generate these box plots we need to compute a five-number
summary for each treatment level, consisting of the minimum value, first
quartile, median, third quartile, and maximum value. The
showBoxPlot($params) method computes these summary values and uses
them to generate the treatment-level box plots.

Figure 2 — box plot of test anxiety data
The showBoxPlot($params) method is actually a wrapper around
JpGraph library methods. The $params argument allows us to supply
parameter values needed to fine tune JpGraph's output as you can see if you
examine the method source code:
<?php
/**
* The showBoxPlot method is a wrapper for JPGRAPH methods.
* The JpGraph constant defining to the root of the JpGraph
* library is specified in the config.php file.
*
* I only do very basic $params array handling in this method. There
* is a lot of room for improvement in making parameter handling more
* extensive (i.e., so you have more control over aspects of your plot)
* and more intelligent.
*/
function showBoxPlot($params=array()) {
include_once JPGRAPH . "/src/JpGraph.php";
include_once JPGRAPH . "/src/jpgraph_stock.php";
$summary = $this->getFiveNumberSummary();
$yData = array();
foreach($this->levels AS $level) {
// Data must be in the format : q1, q3, min, max, median.
$plot_parts = array("q1","q3","min","max","median");
foreach($plot_parts AS $part) {
$yData[] = $summary[$level][$part];
}
}
$figureTitle = $params["figureTitle"];
$xTitle = $params["xTitle"];
$yTitle = $params["yTitle"];
if(!isset($figureTitle))
$figureTitle = "Figure 1";
if(!isset($xTitle))
$xTitle = "x-level";
if(!isset($yTitle))
$yTitle = "y-level";
$plotWidth = 400;
$plotHeight = 300;
$yMin = $params["yMin"];
$yMax = $params["yMax"];
$yTicks = $params["yTicks"];
$yMargin = 35;
$xMargin = 15;
$xLabels = $this->levels;
$graph = new Graph($plotWidth, $plotHeight);
$graph->SetFrame(false);
$graph->SetMarginColor('white');
$graph->title->Set($figureTitle);
$graph->SetScale("textlin", $yMin, $yMax);
$graph->yscale->ticks->Set($yTicks);
$graph->xaxis->SetTickLabels($xLabels);
$graph->xaxis->SetTitle($xTitle,"center");
$graph->xaxis->SetTitleMargin($xMargin);
$graph->yaxis->SetTitle($yTitle, "center");
$graph->yaxis->SetTitleMargin($yMargin);
// Create a new box plot.
$bp = new BoxPlot($yData);
// Indent bars so they don’t start and end at the edge of the plot area.
$bp->SetCenter();
// Width of the bars in pixels.
$bp->SetWidth(25);
// Set bar colors
$bp->SetColor('black','white','black','white');
// Set median colors
$bp->SetMedianColor('black','black');
$graph->Add($bp);
if (isset($params["outputFile"])) {
$outputFile = $params["outputFile"];
$graph_name = "temp/$outputfile";
} else {
$graph_name = "temp/boxplot.png";
}
$graph->Stroke($graph_name);
echo "<img src='$graph_name' vspace='15' alt='$figureTitle'>";
}
?>
Step 4: Show Descriptive Statistics
Another report that we will want to see early in our analysis is a
descriptive statistics report. The descriptive statistics table comes directly
from the showDescriptiveStatistics() method.
Table 2. Show Descriptive Statistics
| Anxiety Levels | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|



