I want to use Generalized Cross Validation to compute the optimal ridge parameter for a ridge regression.
The formula due to Golub et al (1979) is
GCV(k)=(1/n Sum_i=1^n e_i(k)^2)/(1/n Sum_i=1^n(1-h_ii(k)))^2
where e_1(k)....e_n(k)
are the residuals from applying the ridge regression for a given k.
H(K)=X(X'X+kI)^{-1}X'
.
where X is the design matrix.
and h_ii(k)
are the digonal elelments of H(k)
.
I have the ridge regression formula so I can easily compute the numerator.
However I am not sure how to compute the denominator?
I found this set of tools which features a function gcv() but I can't understand how it it calculating the G function?
Indeed it does not appear to be using x in it's calculations? Is this function going what I want above? If so can someone please explain to me how it works?