~ubuntu-branches/ubuntu/trusty/r-cran-rms/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/lrm.ols.penalty.r

  • Committer: Package Import Robot
  • Author(s): Dirk Eddelbuettel
  • Date: 2014-01-22 14:16:13 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20140122141613-frc51dglkjfisik0
Tags: 4.1-1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require(rms)
 
2
 
 
3
# Example of penalty from help page using lrm:
 
4
 
 
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)
 
16
 
 
17
 
 
18
f <- lrm(y ~ blood.pressure + sex * (age + rcs(cholesterol,4)),
 
19
         x=TRUE, y=TRUE)
 
20
p <- pentrace(f, seq(.2,1,by=.05))
 
21
plot(p)
 
22
p$diag      # may learn something about fractional effective d.f. 
 
23
# for each original parameter
 
24
update(f,penalty=.02)
 
25
 
 
26
# Example modified for ols:
 
27
 
 
28
fols <- ols(blood.pressure ~sex * (age + rcs(cholesterol,4)), x=TRUE, y=TRUE)
 
29
pols <- pentrace(fols, seq(0,10,by=.5))
 
30
plot(pols)
 
31
pols$diag
 
32
update(fols,penalty=10)