ssmean: Sum of Squares

ssmeanR Documentation

Sum of Squares

Description

Calculate sum of squared residuals from the mean (not RSS).

Usage

ssmean(x, na.rm = FALSE)

Arguments

x

a numeric vector.

na.rm

whether NA values should be stripped.

Value

Sum of squared residuals from the mean, as a single number.

Note

RSS = ss0(resid), not ssmean(resid).

Similar speed in a benchmark with 1e5 calls of length 100:

  1. sumx<-sum(x); output<-sum(x*x)-sumx*sumx/length(x)

  2. output<-.Internal(cov(x,NULL,1,FALSE))*(length(x)-1), which is the same as var(x)*(length(x)-1)

  3. x_xbar<-x-.Internal(mean(x)); output<-sum(x_xbar*x_xbar)

These are all 3 x faster than output<-sum((x-mean(x))^2).

Implementation 1 is used here, since the algorithm can be used in other languages.


arnima-github/arni documentation built on Oct. 28, 2023, 6:18 p.m.