R/estimateNoise.R

Defines functions estimateNoise

# Compute the usual unbiased estimate of the variance in a linear model.
estimateNoise <- function(x, y, intercept = TRUE) {
  n <- NROW(x)
  p <- NCOL(x)

  stopifnot(n > p)

  fit <- stats::lm.fit(x, y)
  sqrt(sum(fit$residuals^2) / (n-p+intercept))
}
straw-boy/solvers documentation built on Sept. 5, 2020, 6:28 a.m.