David Paul
2014-Mar-07 16:45 UTC
[R] obtaining prediction intervals from lrm() in rms library
Hi, Apologies if this is a silly question -- I am just now learning how to use some of the basic functions in the rms library. I have been using foo.dist <- datadist(foo.frame) options(datadist='foo.dist') lrm.model <- lrm(binary.outcome ~ rcs(contin.var,5)+categ.var, data foo.frame, x=TRUE) lrm.predict <- predict(lrm.model, type = "fitted") to obtain the predicted probabilities from a logistic regression model, but now I need the associated 95% prediction intervals associated with these predicted probabilities. I've read the examples in the ?lrm help page, and from the information about "predict" from http://cran.r-project.org/web/packages/rms/rms.pdf I have tried predict(lrm.model, conf.int = 0.95, conf.type = c("individual")) but I get the error message Error in predictrms(object, ..., type = type, se.fit = se.fit) : conf.type="individual" requires that fit be from ols>From the same PDF, I have read the "predict.lrm" pages and was not able tofigure out how to get prediction intervals. Many thanks in advance for some help, David [[alternative HTML version deleted]]
Greg Snow
2014-Mar-08 19:20 UTC
[R] obtaining prediction intervals from lrm() in rms library
Depending on how you use the logistic regression this can be a silly question. Remember that the prediction interval is where you predict new observations to be. If you fit your logistic regression on data that is 0 or 1 (or FALSE/TRUE, etc.) then predictions for new data will be predictions of 0 or 1 (the confidence interval gives the interval for the probability or proportion, so it makes sense). Since new values can only be 0 or 1 the only possible prediction intervals are 0-0, 0-1, and 1-1, so they don't tend to be very interesting. One case where the question is not silly is if you are modeling a binomial with multiple possible events in a group, e.g. each subject took a 100 question quiz and you modeled the proportion correct, now you want to predict the number correct for a new subject on the 100 point quiz. Now a prediction interval makes sense because while the confidence interval is on the proportion correct, the prediction interval would be on how many questions most subjects would get correct taking into account all the uncertainty (both in the proportion and in the binomial around that proportion). However, this interval is not often called for and is more complex to calculate than the simple linear regression prediction interval, the combination of those 2 facts is probably why it is not implemented for lrm objects. The simplest way I know to create these prediction intervals is actually a Bayesian approach (or Bayes like) where you generate a probability from the posterior, then generate a random value from the binomial using that probability, repeat a bunch of times, then take the range of the middle 95% (or whatever percentage) as the prediction interval. On Fri, Mar 7, 2014 at 9:45 AM, David Paul <david.alan.paul1 at gmail.com> wrote:> Hi, > > Apologies if this is a silly question -- I am just now learning how to use > some of the basic functions in > the rms library. > > I have been using > > foo.dist <- datadist(foo.frame) > options(datadist='foo.dist') > lrm.model <- lrm(binary.outcome ~ rcs(contin.var,5)+categ.var, data > foo.frame, x=TRUE) > lrm.predict <- predict(lrm.model, type = "fitted") > > to obtain the predicted probabilities from a logistic regression model, but > now I need the associated 95% > prediction intervals associated with these predicted probabilities. I've > read the examples in the ?lrm > help page, and from the information about "predict" from > http://cran.r-project.org/web/packages/rms/rms.pdf > I have tried > > predict(lrm.model, conf.int = 0.95, conf.type = c("individual")) > > but I get the error message > > Error in predictrms(object, ..., type = type, se.fit = se.fit) : > conf.type="individual" requires that fit be from ols > > >From the same PDF, I have read the "predict.lrm" pages and was not able to > figure out how to get > prediction intervals. > > > > Many thanks in advance for some help, > > David > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com