/** * __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); }