3
# Example of penalty from help page using lrm:
5
n <- 1000 # define sample size
6
set.seed(17) # so can reproduce the results
7
age <- rnorm(n, 50, 10)
8
blood.pressure <- rnorm(n, 120, 15)
9
cholesterol <- rnorm(n, 200, 25)
10
sex <- factor(sample(c('female','male'), n,TRUE))
11
# Specify population model for log odds that Y=1
12
L <- .4*(sex=='male') + .045*(age-50) +
13
(log(cholesterol - 10)-5.2)*(-2*(sex=='female') + 2*(sex=='male'))
14
# Simulate binary y to have Prob(y=1) = 1/[1+exp(-L)]
15
y <- ifelse(runif(n) < plogis(L), 1, 0)
18
f <- lrm(y ~ blood.pressure + sex * (age + rcs(cholesterol,4)),
20
p <- pentrace(f, seq(.2,1,by=.05))
22
p$diag # may learn something about fractional effective d.f.
23
# for each original parameter
26
# Example modified for ols:
28
fols <- ols(blood.pressure ~sex * (age + rcs(cholesterol,4)), x=TRUE, y=TRUE)
29
pols <- pentrace(fols, seq(0,10,by=.5))
32
update(fols,penalty=10)