O'Reilly Databases

oreilly.comSafari Books Online.Conferences.

We've expanded our coverage and improved our search! Search for all things Database across O'Reilly!

Search Search Tips

advertisement
AddThis Social Bookmark Button

Listen Print Discuss Subscribe to Databases Subscribe to Newsletters

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.

Test Score by Anxiety Level
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
lowmoderatehigh
mean48.4048.0057.50
stdev12.6411.639.29
n101010

Pages: 1, 2, 3, 4

Next Pagearrow




Tagged Articles

Post to del.icio.us

This article has been tagged:

php

Articles that share the tag php:

Understanding MVC in PHP (477 tags)

The PHP Scalability Myth (123 tags)

The Dynamic Duo of PEAR::DB and Smarty (53 tags)

PHP Form Handling (43 tags)

Very Dynamic Web Interfaces (39 tags)

View All

statistics

Articles that share the tag statistics:

Calculating Entropy for Data Mining (3 tags)

Using Bloom Filters (2 tags)

Analyzing Baseball Stats with R (2 tags)

ANOVA Statistical Programming with PHP (2 tags)

View All

Sponsored Resources

  • Inside Lightroom

Related to this Article

Understanding Oracle Clinical Understanding Oracle Clinical
by Joan M. Johnson
May 2007
$9.99 USD

Inside SQLite Inside SQLite
by Sibsankar Haldar
April 2007
$9.99 USD

Advertisement
O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com