/** * __construct Function * * Constructor function for this regression model. Takes two arrays * of data that are parallel arrays of independent and dependent * observations. * * @param array $datax The series of independent variables * @param array $datay The series of dependent variables * @param BasicStats $stats instance of basic stats * @return LinearRegression An object representing the regression model */ public function __construct(array $datax, array $datay, BasicStats $stats) { $this->beta = $stats->covariance($datax, $datay) / $stats->variance($datax); $this->alpha = $stats->average($datay) - $this->beta * $stats->average($datax); $this->r = $stats->correlation($datax, $datay); parent::__construct($datax, $datay, $stats); }
/** * __construct Function * * Constructor function for this regression model. Takes two arrays * of data that are parallel arrays of independent and dependent * observations. * * @param array $datax The series of independent variables * @param array $datay The series of dependent variables * @param BasicStats $stats instance of basic stats * @return LogarithmicRegression An object representing the regression model */ public function __construct($datax, $datay, BasicStats $stats) { $logx = array(); foreach ($datax as $x) { $logx[] = log($x); } $this->r = $stats->correlation($logx, $datay); $this->beta = $stats->covariance($logx, $datay) / $stats->variance($logx); $this->alpha = $stats->average($datay) - $this->beta * $stats->average($logx); parent::__construct($datax, $datay, $stats); }
/** * __construct Function * * Constructor function for this regression model. Takes two arrays * of data that are parallel arrays of independent and dependent * observations. * * @param array $datax The series of independent variables * @param array $datay The series of dependent variables * @param BasicStats $stats instance of basic stats * @return ExponentialRegression An object representing the regression model */ public function __construct(array $datax, array $datay, BasicStats $stats) { $logy = array(); foreach ($datay as $y) { $logy[] = log($y); } $this->r = $stats->correlation($datax, $logy); $logbeta = $stats->covariance($datax, $logy) / $stats->variance($datax); $logalpha = $stats->average($logy) - $logbeta * $stats->average($datax); $this->beta = exp($logbeta); $this->alpha = exp($logalpha); parent::__construct($datax, $datay, $stats); }
/** * Dot Multiply function * * Multiplies this matrix against a second matrix * * @param matrix $matrixA The first matrix in the multiplication * @param matrix $matrixB The second matrix in the multiplication * @return matrix The multiplied matrix */ public function dotMultiply(Matrix $matrixA, Matrix $matrixB) { $this->util->multiplyCheck($matrixA, $matrixB); $rows = $matrixA->getRows(); $columns = $matrixB->getColumns(); $newMatrix = $this->builder->zero($rows, $columns); for ($i = 1; $i <= $rows; $i++) { for ($j = 1; $j <= $columns; $j++) { $row = $matrixA->getRow($i); $column = array(); for ($k = 1; $k <= $rows; $k++) { $column[] = $matrixB->getElement($k, $j); } $newMatrix->setElement($i, $j, $this->basic->sumXY($row, $column)); } } return $newMatrix; }