| Gzu521.com我的学习网 |
|
构造函数 simplelinearregression 类的构造函数方法接受一个 x 和一个 y 向量,每个向量都有相同数量的值。您还可以为您预计的 y 值设置一个缺省为 95% 的置信区间(confidence interval)。 构造函数方法从验证数据形式是否适合于处理开始。一旦输入向量通过了“大小相等”和“值大于 1”测试,就执行算法的核心部分。 执行这项任务涉及到通过一系列 getter 方法计算统计过程的中间值和汇总值。将每个方法调用的返回值赋给该类的一个实例变量。用这种方法存储计算结果确保了前后链接的计算中的调用例程可以使用中间值和汇总值。还可以通过调用该类的输出方法来显示这些结果,如清单 2 所描述的那样。 <?php // 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(); oi:^!e,w,](资/料来.源,于:gzu521学;习/网:电脑课堂;LINUX教程 ]gzu521.comoi:^!e,w,] $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; } ?> 清单 2. 调用类输出方法 |
责任编辑:gzu521