Page 1 of 1

hat values in regression?

Posted: Tue Feb 22, 2022 1:58 am
by sfcheung
In the standard module for linear regression, there is an option to save Cook's distance, predicted values, and residuals.
Is there also an option to save hat values? I searched but have not yet found this option, if it exists. I thought it should be somewhere, given that the module can save Cook's distance, and hatvalues() is in the stats package.

Thanks.

-- Shu Fai

Re: hat values in regression?

Posted: Wed Feb 23, 2022 6:30 pm
by bcollins
Yes. In the current version you can save all three. Aren't hat values the same as predicted values?

Re: hat values in regression?

Posted: Thu Feb 24, 2022 3:12 am
by sfcheung
Sorry for the confusion caused. By hat values I meant the values of leverage reported in SPSS or hatvalues() in the stats package (previously in the car package, if I recall correctly). This is an example:

Code: Select all

set.seed(487053)
n <- 100
x <- rnorm(n)
y <- .6 * x + rnorm(n, 0, sqrt(1 - .6^2))
fit <- lm(y ~ x)
head(fitted(fit))
#>           1           2           3           4           5           6 
#> -0.76511150  0.22895093  0.05261076  0.36833248  0.24762286 -0.66486406
head(hatvalues(fit))
#>          1          2          3          4          5          6 
#> 0.02376032 0.01138044 0.01009515 0.01345880 0.01160445 0.02034855