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


Sponsors





Useful Lists

Web Host
site hosted by netplex

Online Manuals

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

The instance variables

When modeling a statistical test or procedure, you need to figure out which instance variables to declare.

The selection of instance variables can be determined by noting the intermediate and summary values to be generated by the analytic procedure. Each intermediate and summary value can have a corresponding instance variable to hold its value as an object attribute.

I conducted such an analysis to determine which variables to declare for the SimpleLinearRegression class in Listing 1. A similiar analysis would be performed for a MultipleRegression, ANOVA, or TimeSeries procedure.

Listing 1. Instance variables for the SimpleLinearRegression class


<?php 

// Copyright 2003, Paul Meagher 
// Distributed under GPL   

class SimpleLinearRegression { 

  var $n; 
  var $X = array();
  var $Y = array();  
  var $ConfInt;  
  var $Alpha;
  var $XMean;
  var $YMean;
  var $SumXX;
  var $SumXY;
  var $SumYY;  
  var $Slope;
  var $YInt;  
  var $PredictedY   = array();
  var $Error        = array();
  var $SquaredError = array();
  var $TotalError;  
  var $SumError;
  var $SumSquaredError;  
  var $ErrorVariance;
  var $StdErr;
  var $SlopeStdErr;  
  var $SlopeVal;   // T value of Slope 
  var $YIntStdErr;    
  var $YIntTVal;   // T value for Y Intercept
  var $R;
  var $RSquared;    
  var $DF;         // Degrees of Freedom
  var $SlopeProb;  // Probability of Slope Estimate
  var $YIntProb;   // Probability of Y Intercept Estimate
  var $AlphaTVal;  // T Value for given alpha setting
  var $ConfIntOfSlope;        
  
  var $RPath  = "/usr/local/bin/R";  // Your path here
  
  var $format = "%01.2f"; // Used for formatting output 
  
}
?>


View Simple linear regression with PHP: Part 1 Discussion

Page:  1 2 3 4 5 6 7 8 Next Page: The constructor

First published by IBM developerWorks


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