/** * __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 * @return LogarithmicRegression An object representing the regression model */ public function __construct($datax, $datay) { $logx = array(); foreach ($datax as $x) { $logx[] = log($x); } $this->r = \PHPStats\Stats::correlation($logx, $datay); $this->beta = \PHPStats\Stats::covariance($logx, $datay) / \PHPStats\Stats::variance($logx); $this->alpha = \PHPStats\Stats::average($datay) - $this->beta * \PHPStats\Stats::average($logx); }
/** * __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 * @return ExponentialRegression An object representing the regression model */ public function __construct(array $datax, array $datay) { $logy = array(); foreach ($datay as $y) { $logy[] = log($y); } $this->r = \PHPStats\Stats::correlation($datax, $logy); $logbeta = \PHPStats\Stats::covariance($datax, $logy) / \PHPStats\Stats::variance($datax); $logalpha = \PHPStats\Stats::average($logy) - $logbeta * \PHPStats\Stats::average($datax); $this->beta = exp($logbeta); $this->alpha = exp($logalpha); }
/** * __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 * @return LinearRegression An object representing the regression model */ public function __construct(array $datax, array $datay) { $this->beta = \PHPStats\Stats::covariance($datax, $datay) / \PHPStats\Stats::variance($datax); $this->alpha = \PHPStats\Stats::average($datay) - $this->beta * \PHPStats\Stats::average($datax); $this->r = \PHPStats\Stats::correlation($datax, $datay); }
public function test_variance() { $this->assertEquals(2, Stats::variance($this->datax)); $this->assertEquals(2, Stats::variance($this->datay)); $this->assertEquals(526.0824, round(Stats::variance($this->dataz), 4)); }