- Trauma Data Example Again
- Parameter Estimation with MCSE
- Reference Priors for Binomial Regression
- O-Ring Data Presentations
Dr. Turner Osler, a trauma surgeon and former head of the Burn Unit at the University of New Mexico Trauma Center, provided data on survival of patients admitted to the University of New Mexico Trauma Center between 1991 and 1994.
# trauma <- read.table("http://www.ics.uci.edu/~wjohnson/BIDA/Ch8/trauma300.txt, # yheader=TRUE) traumadata <- read.table("trauma300.txt", header=TRUE) attach(traumadata) head(traumadata)
## ID death ISS TI RTS AGE ## 1 2979 0 1 1 7.8408 25 ## 2 1167 0 9 0 7.8408 63 ## 3 116 0 29 0 2.9304 32 ## 4 1118 0 10 0 7.8408 61 ## 5 3126 0 2 1 7.8408 43 ## 6 2173 0 9 0 7.8408 27
Dr. Osler proposed a logistic regression model to estimate the probability of a patient's death using an intercept; the predictors ISS, RTS, AGE, and TI; and an interaction between AGE and TI. AGE is viewed as a surrogate for a patient's physiologic reserve, i.e., their ability to withstand trauma.
The model \[ \text{logit}(\theta_i) = \beta_1 + \beta_2 ISS_i + \beta_3 RTS_i + \beta_4 AGE_i + \beta_5 TI_i + \beta_6 (AGE*TI)_i \] is similar to logistic models used by trauma centers throughout the United States.
Introduce \(x_{i6} = (AGE*TI)_i\) and correct for the mean values of all the continuous predictor variables, then the model becomes \[ \text{logit}(\theta_i) = \alpha + \beta_2 x_{i2} + \beta_3 x_{i3} + \beta_4 x_{i4} + \beta_5 x_{i5} + \beta_6 x_{i6}. \]
x.check <- cbind(ISS-mean(ISS), RTS-mean(RTS), AGE-mean(AGE), TI, AGE*TI-mean(AGE*TI)) colnames(x.check) <- c("x2", "x3", "x4", "x5", "x6") head(x.check)
## x2 x3 x4 x5 x6 ## [1,] -13.28 0.553934 -6.41 1 17.633333 ## [2,] -5.28 0.553934 31.59 0 -7.366667 ## [3,] 14.72 -4.356466 0.59 0 -7.366667 ## [4,] -4.28 0.553934 29.59 0 -7.366667 ## [5,] -12.28 0.553934 11.59 1 35.633333 ## [6,] -5.28 0.553934 -4.41 0 -7.366667
model2 <- glm(death ~ x.check, family = binomial(), x = TRUE)
x <- model2$x y <- model2$y lupost <- function(beta, x, y) { eta <- as.numeric(x %*% beta) logp <- ifelse(eta < 0, eta - log1p(exp(eta)), - log1p(exp(- eta))) logq <- ifelse(eta < 0, - log1p(exp(eta)), - eta - log1p(exp(- eta))) logl <- sum(logp[y == 1]) + sum(logq[y == 0]) return(logl - sum(beta^2) / 50) }
mcmc
package and metrop
function to obtain posterior simulations.library(mcmc) set.seed(1) beta.init <- as.numeric(coefficients(model2)) out <- metrop(lupost, beta.init, 5e4, scale=0.03, x = x, y = y) out$accept
## [1] 0.19804
library(mcmcse)
## mcmcse: Monte Carlo Standard Errors for MCMC ## Version 1.3-2 created on 2017-07-03. ## copyright (c) 2012, James M. Flegal, University of California, Riverside ## John Hughes, University of Colorado, Denver ## Dootika Vats, University of Warwick ## Ning Dai, University of Minnesota ## For citation information, type citation("mcmcse"). ## Type help("mcmcse-package") to get started.
plot(ts(out$batch))
ess(out$batch)
## [1] 228.1051 485.8939 269.3972 614.3843 225.2397 403.7840
multiESS(out$batch)
## [1] 968.6197
scale
.out <- metrop(out, scale=c(.1, .03, .1, .03, .1, .03), x = x, y = y) out$accept
## [1] 0.17346
out$time
## user system elapsed ## 5.736 1.297 7.062
plot(ts(out$batch))
ess(out$batch)
## [1] 265.4184 789.0774 650.0411 686.0127 232.3179 322.1590
multiESS(out$batch)
## [1] 1116.557
acf(out$batch[,1:3])
acf(out$batch[,4:6])
minESS
to ascertain what is the minimum effective sample size needed for stable analysis.p
is the dimension of the estimation problem.alpha
is the confidence level.eps
is the tolerance level. Default is .05. Reasonable levels are anywhere from .01 to .05. The smaller the tolerance, the larger the minimum effective samples. eps
represents a tolerance level relative to the variability in the target distribution. It is akin to the idea of margin-of-error.minESS(p = 6, alpha = .05, eps = .05)
## minESS ## 8708
out <- metrop(out, nbatch=2e5, x = x, y = y) out$accept
## [1] 0.177515
out$time
## user system elapsed ## 22.780 5.017 27.955
ess(out$batch)
## [1] 573.0223 2089.4155 2142.8925 1234.9522 472.3659 626.1789
multiESS(out$batch)
## [1] 3401.668
round(mcse.mat(out$batch), 4)
## est se ## [1,] -4.1892 0.0259 ## [2,] 0.0859 0.0006 ## [3,] -0.5821 0.0038 ## [4,] 0.0571 0.0005 ## [5,] 1.6485 0.0667 ## [6,] -0.0142 0.0015
metrop
function with the O-Ring Data.scale
and illustrate the correlation in your sampler.