Code Updates for Regression Modeling Strategies First Edition

Problems at end of Chapter 7, p. 144

Replace code in (c) with the following

require(rms)
getHdata(support)
totcst <- support$totcst
totcst <- ifelse(totcst == 0., NA, totcst)

doplot <- function(predictor, type=c('spline','quadratic')) {
  type <- match.arg(type)
  r <- range(predictor, na.rm=T)
  xs <- seq(r[1], r[2], length=150)
  f <- switch(type,
              spline   = ols(log(totcst) ~ rcs(predictor, 5)),
              quadratic= ols(log(totcst) ~ pol(predictor, 2)))
  print(f)
  print(anova(f))
  p <- Predict(f, predictor=xs)
  pan <- function(...) {
    plsmo(predictor, log(totcst), add=T, trim=0, col='green', lwd=3, grid=TRUE)
    scat1d(predictor, grid=TRUE)
  }
  print(plot(p, predictor=xs, xlab=label(predictor), addpanel=pan,
             main=paste('n=', f$stats['n']), adj=0))
  invisible()
}

with(support,
     {
       doplot(pafi)
       doplot(scoma, 'quadratic')
     } )

This topic: Main > WebHome > StatComp > RmS > NewVersionsOfRCode
Topic revision: 12 Apr 2014, FrankHarrell
 
This site is powered by FoswikiCopyright © 2013-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback