Created
June 4, 2015 00:28
-
-
Save dceoy/3c858d4769cd2991ed71 to your computer and use it in GitHub Desktop.
[R] Logistic Regression using MCMCpack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env Rscript | |
sapply(c('dplyr', 'data.table', 'MASS', 'MCMCpack'), function(p) require(p, character.only = TRUE)) | |
# Biopsy Data on Breast Cancer Patients | |
# | |
# variables: | |
# 'V1' clump thickness. | |
# 'V4' marginal adhesion. | |
# 'class' "benign" or "malignant". | |
dt <- data.table(biopsy) %>% mutate(outcome = ifelse(class == 'malignant', 1, 0)) | |
# | |
# Logistic Regression via MCMC | |
# | |
m <- MCMClogit(outcome ~ V1 + V4, data = dt, burnin = 1000, mcmc = 5000) | |
print(summary(m)) | |
# | |
# Iterations = 1001:6000 | |
# Thinning interval = 1 | |
# Number of chains = 1 | |
# Sample size per chain = 5000 | |
# | |
# 1. Empirical mean and standard deviation for each variable, | |
# plus standard error of the mean: | |
# | |
# Mean SD Naive SE Time-series SE | |
# (Intercept) -7.4592 0.58191 0.008229 0.025924 | |
# V1 0.9207 0.08803 0.001245 0.003848 | |
# V4 0.8182 0.08750 0.001237 0.004141 | |
# | |
# 2. Quantiles for each variable: | |
# | |
# 2.5% 25% 50% 75% 97.5% | |
# (Intercept) -8.6666 -7.8185 -7.4571 -7.0591 -6.372 | |
# V1 0.7567 0.8597 0.9173 0.9796 1.104 | |
# V4 0.6570 0.7588 0.8136 0.8723 1.002 | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment