Login   Register  
PHP Classes
elePHPant
Icontem

File: examples/TestFit.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jose Gomez  >  Linear Fit  >  examples/TestFit.php  >  Download  
File: examples/TestFit.php
Role: Example script
Content type: text/plain
Description: Multivariate linear fitting example
Class: Linear Fit
Perform linear regression on a set of data values
Author: By
Last change:
Date: 2013-10-29 11:04
Size: 960 bytes
 

Contents

Class file image Download
<?
    
require('../LinearFit.php');

    
$oFit=new LinearFit;
    
$oFit->SetData(array(array(0), array(1), array(2), array(3)), array(0,0.95,2.1,3));
    
$oFit->AddData(array(4), 4);
    
$aCoeffs=$oFit->Fit();
    
$aConf=$oFit->ConfInterval(0.95);
    
$aRes=$oFit->GetValues(array(5));
    if (
php_sapi_name()=='cli')
    {
        echo 
"Equation: y=a0";
        for (
$i=1$i<count($aCoeffs); $i++)
        {
            echo 
"+a$i*x$i";
        }
        echo 
"\n";
        for (
$i=0$i<count($aCoeffs); $i++)
        {
            echo 
"a$i=" $aCoeffs[$i] . "±" $aConf[$i] . "\n";
        }
        echo 
"r2=" .  $oFit->R2() . "\n";
        echo 
"x1=5 -> y=" $aRes "\n";
    }
    else
    {
        echo 
"Equation: y=a<sub>0</sub>";
        for (
$i=1$i<count($aCoeffs); $i++)
        {
            echo 
"+a<sub>$i</sub>*x<sub>$i</sub>";
        }
        echo 
"<br>";
        for (
$i=0$i<count($aCoeffs); $i++)
        {
            echo 
"a<sub>$i</sub>=" $aCoeffs[$i] . "&#177;" $aConf[$i] . "</br>";
        }
        echo 
"r<sup>2</sup>=" .  $oFit->R2() . "</br>";
        echo 
"x<sub>1</sub>=5 -> y=" $aRes "</br>";
    }
?>