BinaryGibbs_Test_Accuracy: Calculation of Accuracy of Prediction on Test Set for...

Description Usage Arguments Value Examples

View source: R/Binary__Gibbs_TrainingAccuracy.R

Description

BinaryGibbs_Test_Accuracy Calculates Accuracy of Prediction on Test Set for Bayesian Probit Regression.

Usage

1
BinaryGibbs_Test_Accuracy(Predicted_Y, Test_Y)

Arguments

Predicted_Y

a nrow(Test_X) X 1 vector of predicted responses.

Test_Y

a nrow(Test_X) X 1 vector of actual responses.(ordering is assumed)

Value

Test_Accuracy A scalar giving the accuracy on the test set.

Examples

 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
26
27
28
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)
Output = BinaryGibbs_fit(Train_X, Train_Y, nIter, prior, burn_in, prior_mean, prior_var )
estimates = Output$estimates
Predicted_Y = BinaryGibbs_Pred(estimates, Test_X)
BinaryGibbs_Test_Accuracy(Predicted_Y, Test_Y)

zovialpapai/PolyGibbs documentation built on Dec. 9, 2019, 6:52 a.m.