// Copyright 2003, Paul Meagher
// Distributed under GPL
function SimpleLinearRegression(X, Y, ConfidenceInterval="95") {
numX = count(X);
numY = count(Y);
if (numX != numY) {
die("Error: Size of X and Y vectors must be the same.");
}
if (numX <= 1) {
die("Error: Size of input array must be at least 2.");
}
this->n = numX;
this->X = X;
this->Y = Y;
this->ConfInt = ConfidenceInterval;
this->Alpha = (1 + (this->ConfInt / 100) ) / 2;
this->XMean = this->getMean(this->X);
this->YMean = this->getMean(this->Y);
this->SumXX = this->getSumXX();
this->SumYY = this->getSumYY();
this->SumXY = this->getSumXY();
this->Slope = this->getSlope();
this->YInt = this->getYInt();
this->PredictedY = this->getPredictedY();
this->Error = this->getError();
this->SquaredError = this->getSquaredError();
this->SumError = this->getSumError();
this->TotalError = this->getTotalError();
this->SumSquaredError = this->getSumSquaredError();
this->ErrorVariance = this->getErrorVariance();
this->StdErr = this->getStdErr();
this->SlopeStdErr = this->getSlopeStdErr();
this->YIntStdErr = this->getYIntStdErr();
this->SlopeTVal = this->getSlopeTVal();
this->YIntTVal = this->getYIntTVal();
this->R = this->getR();
this->RSquared = this->getRSquared();
this->DF = this->getDF();
this->SlopeProb = this->getStudentProb(this->SlopeTVal, this->DF);
this->YIntProb = this->getStudentProb(this->YIntTVal, this->DF);
this->AlphaTVal = this->getInverseStudentProb(this->Alpha, this->DF);
this->ConfIntOfSlope = this->getConfIntOfSlope();
return true;
}
?>
// Copyright 2003, Paul Meagher
// Distributed under GPL
class SimpleLinearRegression {
var RPath = "/usr/local/bin/R"; // Your path here
function getStudentProb(T, df) {
Probability = 0.0;
cmd = "echo 'dt(T, df)' | this->RPath --slave";
result = shell_exec(cmd);
list(LineNumber, Probability) = explode(" ", trim(result));
return Probability;
}
function getInverseStudentProb(alpha, df) {
InverseProbability = 0.0;
cmd = "echo 'qt(alpha, df)' | this->RPath --slave";
result = shell_exec(cmd);
list(LineNumber, InverseProbability) = explode(" ", trim(result));
return InverseProbability;
}
}
?>
// BurnoutStudy.php
// Copyright 2003, Paul Meagher
// Distributed under GPL
include "SimpleLinearRegression.php";
// Load data from burnout study
Concentration = array(20,60,38,88,79,87,
68,12,35,70,80,92,
77,86,83,79,75,81,
75,77,77,77,17,85,96);
ExhaustionIndex = array(100,525,300,980,310,900,
410,296,120,501,920,810,
506,493,892,527,600,855,
709,791,718,684,141,400,970);
slr = new SimpleLinearRegression(Concentration, ExhaustionIndex);
YInt = sprintf(slr->format, slr->YInt);
Slope = sprintf(slr->format, slr->Slope);
SlopeTVal = sprintf(slr->format, slr->SlopeTVal);
SlopeProb = sprintf("%01.6f", slr->SlopeProb);
?>
Equation: |
T: |
Prob > T: |