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

Description Usage Arguments Value Examples

View source: R/Poly_Gibbs_TestAccuracy.R

Description

MultinomGibbs_Test_Accuracy Calculates Accuracy of Prediction on Test Set for Bayesian Ordered Multinomial Regression.

Usage

1
MultinomGibbs_Test_Accuracy(Predicted_Y, Test_Y, K)

Arguments

Predicted_Y

A (length(Test_Y)) X 1 vector of prediction for testset responses.

Test_Y

A (length(Test_Y)) X 1 vector of testset responses.

K

An integer giving no. of classes.

Value

Test_Accuracy A real no between 0 and 100 giving accuracy of prediction in 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
29
30
# Initialization
set.seed(250)
n <- 1000 # Total no of observations.
int1 <- -1 # gamma boundary
int2 <- 3  # gamma boundary
beta <- c(-.75, 1) # Regression Parameters for data generation.
X <- cbind(sample(1:4, n, replace = TRUE), rnorm(n, 0, 2)) # Generated design matrix
# Generation of Latent Variable Observations
eta <- X %*% beta
z <- rnorm(n, eta, 1)
# Generation of Responses depending on z
y <- rep(0, n)
y[z <= int1] <- 1
y[int1 <z & z <= int2] <- 2
y[int2 < z ] <- 3
#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, ]# Train Data Covariates
Test_X = X[-Train_ID, ]
Train_Y = y[Train_ID] # Train Data Response
Test_Y = y[-Train_ID] # Test Data Response
K = 3
nIter = 10000
burn_in = 5000
Result = MultinomGibbs_fit(Train_X, Train_Y, nIter, burn_in, K)
estimates = Result$estimates
gamma_estimates = Result$gamma_estimates
Result_Pred = MultinomGibbs_pred(estimates, gamma_estimates,Test_X )
Predicted_Y = Result_Pred
MultinomGibbs_Test_Accuracy(Predicted_Y, Test_Y, K)

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