Search code examples
rregressionmodelingloess

Extract Residual Standard error from loess regression results in R


I am trying to extract the Residual Standard Error from the output summary of loess regression model.

> summary(fit.loess[[i]])
Call:
loess(formula = dfcpm[, ncol(dfcpm)] ~ dfcpm[, i], data = dfcpm, 
    span = 0.5, degree = 1, normalize = FALSE, family = "gaussian")

Number of Observations: 88 
Equivalent Number of Parameters: 4.7 
Residual Standard Error: 21.7 
Trace of smoother matrix: 5.53  (exact)

Control settings:
  span     :  0.5 
  degree   :  1 
  family   :  gaussian
  surface  :  interpolate     cell = 0.2
  normalize:  FALSE
 parametric:  FALSE
drop.square:  FALSE 

Now I want to extract the Residual Standard Error of this model. How do I extract it ? I cannot find this value (i.e. 21.7) anywhere in the model object.

> names(fit.loess[[i]])
 [1] "n"         "fitted"    "residuals" "enp"       "s"         "one.delta" "two.delta" "trace.hat"
 [9] "divisor"   "robust"    "pars"      "kd"        "call"      "terms"     "xnames"    "x"        
[17] "y"         "weights" 

Solution

  • It is the s element in the return from loess.

    > lo <- loess(mpg ~ wt, data=mtcars)
    > print(lo)
    #Call:
    #loess(formula = mpg ~ wt, data = mtcars)
    #
    #Number of Observations: 32 
    #Equivalent Number of Parameters: 5 
    #Residual Standard Error: 2.711 
    > lo$s
    #[1] 2.711351