Sum of Squared Error

sum_squares(x, y = x)

Arguments

x

numeric vector

y

optional, numeric vector, same length as x

Value

either the sum of squared errors for x (if y is left out), or the cross-product of two vectors x with y

Details

The sum of squared errors for a length \(n\) vector \(x\) will equal

$$S_{xx} = \sum_i^n(x - \overline{x})^2,$$

where \(\overline{x}\) is the mean of \(x\).

The cross-product is

$$S_{xy} = \sum_i^n (x - \overline{x})(y - \overline{y})$$

Examples

# the sum of squared errors for x x <- rnorm(10) sum_squares(x)
#> [1] 6.209723
# a cross-product y <- rnorm(10) sum_squares(x, y)
#> [1] 3.532127