# [R] Selecting ridge regression coefficients for minimum GCV

William Dunlap wdunlap at tibco.com
Sun Apr 28 01:53:33 CEST 2013

Using a reproducible example:
> library(MASS)
> fits <- lm.ridge(y ~ ., longley, lambda=seq(0,.2,len=9))
> whichIsBest <- which.min(fits\$GCV)
> coef(fits)[whichIsBest,] # no need to refit
GNP    Unemployed  Armed.Forces    Population          Year
-1.454883e+03  1.063399e-01  1.285758e-02  8.194928e-03 -7.715296e-01  8.126372e-01
Employed
1.743916e-01
I imagine that help(lm.ridge) contains this information.  You can also
look at str(fits) to see what is in the output of lm.ridge() and how it
relates to what is in the standard printout.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Preetam Pal
> Sent: Saturday, April 27, 2013 4:32 PM
> To: r-help at r-project.org
> Subject: [R] Selecting ridge regression coefficients for minimum GCV
>
> Hi all,
>
> I have run a ridge regression as follows:
>
> reg=lm.ridge(final\$l~final\$lag1+final\$lag2+final\$g+final\$u,
> lambda=seq(0,10,0.01))
>
> Then I enter :
>
> select(reg)   and it returns: modified HKB estimator is 19.3409
>                                        modified L-W estimator is 36.18617
>                                        smallest value of GCV  at 10
>
> I think it means that it is advisable to use the results of regression
> corresponding to lambda= 10;
> so the next thing I do is:
>
> reg=lm.ridge(final\$l~final\$lag1+final\$lag2+final\$g+final\$u, lambda=10)
>
> which yields:
>
>                              final\$lag1    final\$lag2       final\$g
>     final\$u
>  3.147255e-04  1.802505e-01 -4.461005e-02 -1.728046e-09 -5.154932e-04
>
>
> The main issue is that I want to access these coefficient values
> automatically, i.e. R should run the regression and automatically provide
> me these values after taking into consideration that lambda which minimizes
> the GCV.   Kindly advise me how I can proceed.
>
>
> Thanks and regards,
> Preetam
>
>
> --
> Preetam Pal
> (+91)-9432212774
> M-Stat 2nd Year,                                             Room No. N-114
> Statistics Division,                                           C.V.Raman
> Hall
> Indian Statistical Institute,                                 B.H.O.S.
> Kolkata.
>
> 	[[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.