[R] rms package: residual df for penalised ols

Mark Seeto markseeto at gmail.com
Wed Oct 28 01:57:42 CET 2015


Dear R-help,

In the rms package, when using the ols function with a penalty, the
df.residual appears to always be n-1 (with n being the sample size).
That seems strange to me, but I don't have much knowledge in this
area.

Here's an example:

library(rms)

set.seed(1)

n <- 50

d <- data.frame(x1 = rnorm(n),
                x2 = rnorm(n, 0, 5),
                x3 = rnorm(n))
d$y <- with(d, 1 + 0.8*x1 + 0.5*x2 - 0.5*x3) + rnorm(n)

ols1 <- ols(y ~ x1 + x2 + x3, data=d)
ols2 <- ols(y ~ x1 + x2 + x3, data=d, penalty=10)

ols1$stats["d.f."]  # 3
ols2$stats["d.f."]  # 5.2

ols1$df.residual    # 46 = n - 3 - 1
ols2$df.residual    # 49


I would be grateful if someone could give a brief explanation of why
df.residual is n-1. The reason I'm interested in this is that
confidence intervals for predicted values use the df.residual value.

Thanks,
Mark



More information about the R-help mailing list