MathPHP\Statistics\RandomVariable::sumOfSquaresDeviations PHP Method

sumOfSquaresDeviations() public static method

∑⟮xᵢ - μ⟯²
public static sumOfSquaresDeviations ( array $numbers ) : number
$numbers array
return number
    public static function sumOfSquaresDeviations(array $numbers)
    {
        if (empty($numbers)) {
            return null;
        }
        $μ = Average::mean($numbers);
        $∑⟮xᵢ − μ⟯² = array_sum(array_map(function ($xᵢ) use($μ) {
            return pow($xᵢ - $μ, 2);
        }, $numbers));
        return $∑⟮xᵢ − μ⟯²;
    }

Usage Example

Example #1
0
 /**
  * SSreg - The Sum Squares of the regression (Explained sum of squares)
  *
  * The sum of the squares of the deviations of the predicted values from
  * the mean value of a response variable, in a standard regression model.
  * https://en.wikipedia.org/wiki/Explained_sum_of_squares
  *
  * SSreg = ∑(ŷᵢ - ȳ)²
  * When a constant is fit to the regression, the average of y = average of ŷ.
  *
  * In the case where the constant is not fit, we use the sum of squares of the predicted value
  * SSreg = ∑ŷᵢ²
  *
  * @return number
  */
 public function sumOfSquaresRegression()
 {
     if ($this->fit_constant == 1) {
         return RandomVariable::sumOfSquaresDeviations($this->Yhat());
     }
     return array_sum(Single::square($this->reg_Yhat));
 }
All Usage Examples Of MathPHP\Statistics\RandomVariable::sumOfSquaresDeviations