[R] influence.measures(stats): hatvalues(model, ...)

Peter Ehlers ehlers at ucalgary.ca
Sun Nov 8 12:45:01 CET 2009


Sigmund Freud wrote:
> Hello:
> 
> I am trying to understand the method 'hatvalues(...)', which returns something similar to the diagonals of the plain vanilla hat matrix [X(X'X)^(-1)X'], but not quite. 
> 
> A Fortran programmer I am not, but tracing through the code it looks like perhaps some sort of correction based on the notion of 'leave-one-out' variance is being applied. 
> 

I can't see what the problem is. Using the LifeCycleSavings
example from ?influence.measures:

   lm.SR <- lm(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings)
   X <- model.matrix(lm.SR)
   H <- X %*% solve(t(X) %*% X) %*% t(X)
   hats1 <- diag(H)
   hats2 <- hatvalues(lm.SR)
   all.equal(hats1, hats2)
   #[1] TRUE

> Whatever the difference, in simulations 'hatvalues' appears to perform much better in the context of identifying outiers using Cook's Distance than the diagonals of the plain vanilla hat matrix. (As in http://en.wikipedia.org/wiki/Cook's_distance).
> 
> Would prefer to understand a little more when using this method. I have downloaded the freely available references cited in the help and am in the process of digesting them. If someone with knowledge could offer a pointer on the most efficient way to get at why 'hatvalues' does what it does, that would be great.
> 
In a nutshell, hatvalues are a measure of how unusual
a point is in predictor space, i.e. to what extent it
"sticks out" in one or more of the X-dimensions.

  -Peter Ehlers

> Thanks,
> Jean Yarrington
> Independent consultant.
> 
> 
> 
>       
> 	[[alternative HTML version deleted]]
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list