Developer Forums | About Us | Site Map
Search  
HOME > TUTORIALS > SERVER SIDE CODING > PHP TUTORIALS > SIMPLE LINEAR REGRESSION WITH PHP: PART 2


Sponsors





Useful Lists

Web Host
site hosted by netplex

Online Manuals

Simple linear regression with PHP: Part 2
By Paul Meagher - 2004-05-21 Page:  1 2 3 4 5 6 7 8 9

Data-exploration script

The data-exploration tool consists of a single script (explore.php) that calls methods from the SimpleLinearRegressionHTML class and the JpGraph libary.

The script uses a simple processing logic. The first part of the script performs basic validation on submitted form data. If the form data validates, then the second part of the script is executed.

The second part of the script contains code for analyzing the data and displaying summary results in HTML and graphics formats. The essential structure of the explore.php script is shown in Listing 4:

Listing 4. The structure of explore.php

<?php 

  // explore.php 

  if (!empty($x_values)) { 
    $X    = explode(",", $x_values); 
    $numX = count($X); 
  }   

  if (!empty($y_values)) { 
    $Y    = explode(",", $y_values); 
    $numY = count($Y); 
  }   

  // display entry data entry form if variables not set 

  if ( (empty($title)) OR (empty($x_name)) OR (empty($x_values)) OR  
       (empty($y_name)) OR (empty($conf_int)) OR (empty($y_values)) OR  
       ($numX != $numY) ) {          

    // Omitted code for displaying entry form 
     
  } else { 
     
    include_once "slr/SimpleLinearRegressionHTML.php";                       
    $slr = new SimpleLinearRegressionHTML($X, $Y, $conf_int);    

    echo "<h2>$title</h2>"; 
     
    $slr->showTableSummary($x_name, $y_name); 
    echo "<br><br>"; 
     
    $slr->showAnalysisOfVariance();   
    echo "<br><br>"; 

    $slr->showParameterEstimates($x_name, $y_name);  
    echo "<br>"; 

    $slr->showFormula($x_name, $y_name); 
    echo "<br><br>"; 

    $slr->showRValues($x_name, $y_name); 
    echo "<br>"; 

    include ("jpgraph/jpgraph.php"); 
    include ("jpgraph/jpgraph_scatter.php"); 
    include ("jpgraph/jpgraph_line.php");   
                       
    // The code for displaying the graphics is inline in the 
    // explore.php script.  The code for these two line plots 
    // finishes off the script: 
     
    // Omitted code for displaying scatter plus line plot 
    // Omitted code for displaying residuals plot 
     
  } 

  ?>



View Simple linear regression with PHP: Part 2 Discussion

Page:  1 2 3 4 5 6 7 8 9 Next Page: Fire damage study

First published by IBM developerWorks


Copyright 2004-2017 GrindingGears.com. All rights reserved.
Article copyright and all rights retained by the author.