Description Usage Arguments Value Examples
View source: R/Binary_Gibbs_Functions.R
BinaryGibbs_fit
does Implementation of Probit Regression for Binary Responses via data augmentation and Gibbs sampling.
1 | BinaryGibbs_fit(Train_X, Train_Y, nIter, prior, burn_in, prior_mean, prior_var)
|
Train_X |
n X p matrix of continuous covarites of training set. |
Train_Y |
n X 1 vector of responses of training set. (takes values 0 or 1). |
nIter |
An integer, No of iterations for the Gibbs Sampler. |
prior |
choice of prior (1: diffuse prior,2: proper conjugate prior). |
burn_in |
An integer, No of iterations neglected at begining of the chain in calculation of posterior mean. |
prior_mean |
a (p+1) X 1 vector specifying mean of the normal conjugate prior, if prior = 2. |
prior_var |
a (p+1) X (p+1) matrix specifying variance of the normal conjugate prior, if prior = 2. |
beta_matrix
a nIter X (p+1) matrix of beta estimate chains.
estimates
a (p+1) X 1 vector of beta estimates.
Train_Accuracy
a nIter X 1 vector of accuracy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | set.seed(250)
require(truncnorm)
require(MASS)
N <- 500
x1 <- seq(-1, 1, length.out = N)
x2 <- rnorm(N, 0, 1)
D <- 3
X <- matrix(c(rep(1, N), x1, x2), ncol = D)
true_theta <- c(- 0.5, 3.3, 2)
p <- pnorm(X %*% true_theta)
y <- rbinom(N, 1, p)
N1 <- sum(y) # Number of successes
N0 <- N - N1 # Number of failures
#Spliting The Data in Train and Test in 80:20 ratio
Train_ID = sample(1:nrow(X), round(nrow(X) * 0.8), replace = FALSE) # Train Data IDS
Train_X = X[Train_ID, -1] # Train Data Covariates
Test_X = X[-Train_ID, -1] # Test Data Covarites
Train_Y = y[Train_ID] # Train Data Response
Test_Y = y[-Train_ID] # Test Data Response
nIter = 10000
burn_in = round(nIter * 0.5)
prior = 2
prior_mean = rep(1, 3)
prior_var = diag(10, 3)
BinaryGibbs_fit(Train_X, Train_Y, nIter, prior, burn_in, prior_mean, prior_var )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.