[R] standardized/studentized residuals with loess

Joshua Wiley jwiley.psych at gmail.com
Wed Nov 10 20:21:51 CET 2010

```Hi Oliver,

As a warning, I may be missing something too.  I did not see something
explicit in base R or MASS.  In a quick scan of the fourth edition of
the MASS book, I did not read anything that it is
illogical/unreasonable to try to find standardized residuals (but my
knowledge of local regression approaches nil).  With that background,
I proceeded to blithely scavenge from other functions until I came up
with this:

loess.stdres <- function(model) {
res <- model\$residuals
s <- sqrt(sum(res^2)/(length(res) - model\$enp))
stdres <- res/(sqrt(1 - hat(res)) * s)
return(stdres)
}

## now for a half-baked check

## fit linear model and local regression
cars.lm <- lm(dist ~ speed, cars)
cars.lo <- loess(dist ~ speed, cars)

## these seem somewhat similar
rstandard(cars.lm)
c(scale(residuals(cars.lm)))

## these seem somewhat similar too
loess.stdres(cars.lo)
c(scale(cars.lo\$residuals))

Cheers,

Josh

On Wed, Nov 10, 2010 at 9:24 AM, Oliver Frings
> Hi all,
>
> I'm trying to apply loess regression to my data and then use the fitted
> model to get the *standardized/studentized residuals. I understood that for
> linear regression (lm) there are functions to do that:*
> *
> *
> fit1 = lm(y~x)
> stdres.fit1 = rstandard(fit1)
> studres.fit1 = rstudent(fit1)
>
> I was wondering if there is an equally simple way to get
> the standardized/studentized residuals for a loess model? BTW
> my apologies if there is something here that I'm missing.
>
> All the best,
> *
> *
> *Oliver *
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.
>

--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

```