[R] applying summary() to an object created with ols()
Benjamin Volland
volland at econ.mpg.de
Fri Aug 21 19:01:42 CEST 2009
Hello R-list,
I am trying to calculate a ridge regression using first the *lm.ridge()*
function from the MASS package and then applying the obtained Hoerl
Kennard Baldwin (HKB) estimator as a penalty scalar to the *ols()*
function provided by Frank Harrell in his Design package.
It looks like this:
> rrk1<-lm.ridge(lnbcpc ~ lntex + lnbeerp + lnwinep + lntemp + pop,
subset(aa, Jahr>=1957 & Jahr<=1966))
> f <- ols(lnbcpc ~ lntex + lnbeerp + lnwinep + lntemp + pop,
subset(aa, Jahr>=1957 & Jahr<=1966), penalty = rrk$kHKB)
> f
which returns
>Linear Regression Model
>
>ols(formula = lnbcpc ~ lntex + lnbeerp + lnwinep + lntemp + pop,
> data = subset(aa, Jahr >= 1957 & Jahr <= 1966), penalty = rrk$kHKB)
>
> n Model L.R. d.f. R2 Sigma
> 10 38.59 8.814 0.9839 0.02796
>
>Residuals:
> 1 2 3 4 5 6
7 8 9 10
>-0.014653 -0.002787 0.017515 -0.018145 -0.008757 -0.008035 0.006066
0.045826 -0.001244 -0.015786
>
>Coefficients:
> Value Std. Error t Pr(>|t|)
>Intercept 1.5240 3.3034 0.4613 0.8496
>lntex 0.3722 0.2071 1.7975 0.6801
>lnbeerp 0.9085 0.5760 1.5771 0.6964
>lnwinep -0.1458 0.1874 -0.7781 0.7863
>lntemp -0.0772 0.1344 -0.5743 0.8240
>pop -4.1889 1.9286 -2.1720 0.6571
>
>Adjusted R-Squared: 0.2227
All in all beautiful (leaving aside that the results suck). The problem
starts when I want to write the obtained coefficients (incl. Std.
Errors, t-, and p-values) into a matrix.
Via the *f$coef* command I can only access the betas (1st column) and
using the *summary(f)* function I get
> summary(f)
>Fehler in summary.Design(f) :
>adjustment values not defined here or with datadist for lntex lnbeerp
lnwinep lntemp pop
Does anyone know how I can set the *datadist()* and the *options()* such
that I will get access to all coefficients?
I tried:
> options(datadist=NULL)
> f <- ols(lnbcpc ~ lntex + lnbeerp + lnwinep + lntemp + pop,
subset(aa, Jahr>=1957 & Jahr<=1966), penalty = rrk$kHKB)
> d <- datadist(f)
but got:
> Fehler in sort.list(unique(y)) : 'x' must be atomic for 'sort.list'
> Have you called 'sort' on a list?
In the R documentation on ?ols() it states concerning the values
returned: "the same objects returned from |lm| (/unless |penalty| or
|penalty.matrix| are given/ - then an abbreviated list is returned since
|lm.pfit| is used as a fitter)..." Unfortunately no information seems to
be available on lm.pfit.
Does anyone know why the using that function leads to an abbreviated
return list? Is there a trick to circumvent that?
Thanks
Benjamin Volland
P.S. Currently using R-version 2.7.1 on a Windows PC.
More information about the R-help
mailing list