ssmean | R Documentation |
Calculate sum of squared residuals from the mean (not RSS).
ssmean(x, na.rm = FALSE)
x |
a numeric vector. |
na.rm |
whether |
Sum of squared residuals from the mean, as a single number.
RSS = ss0(resid)
, not ssmean(resid)
.
Similar speed in a benchmark with 1e5 calls of length 100:
sumx<-sum(x); output<-sum(x*x)-sumx*sumx/length(x)
output<-.Internal(cov(x,NULL,1,FALSE))*(length(x)-1)
, which is
the same as var(x)*(length(x)-1)
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.