<?php
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_scatter.php');
require_once ('jpgraph/jpgraph_line.php');
require_once ('jpgraph/jpgraph_utils.inc.php');
$datay = array();
$datax = array();
$a= 3.2;
$b= 2.5;
for($x=0; $x < 20; ++$x) {
$datax[$x] = $x;
$datay[$x] = $a + $b*$x + rand(-20,20);
}
$lr = new LinearRegression($datax, $datay);
list( $stderr, $corr ) = $lr->GetStat();
list( $xd, $yd ) = $lr->GetY(0,19);
$graph = new Graph(300,250);
$graph->SetScale('linlin');
$graph->title->Set("Linear regression");
$graph->title->SetFont(FF_ARIAL,FS_BOLD,14);
$graph->subtitle->Set('(stderr='.sprintf('%.2f',$stderr).', corr='.sprintf('%.2f',$corr).')');
$graph->subtitle->SetFont(FF_ARIAL,FS_NORMAL,12);
$graph->xaxis->SetPos('min');
$sp1 = new ScatterPlot($datay,$datax);
$sp1->mark->SetType(MARK_FILLEDCIRCLE);
$sp1->mark->SetFillColor("red");
$sp1->SetColor("blue");
$sp1->SetWeight(3);
$sp1->mark->SetWidth(4);
$lplot = new LinePlot($yd);
$lplot->SetWeight(2);
$lplot->SetColor('navy');
$graph->Add($sp1);
$graph->Add($lplot);
$graph->Stroke();
?> |