MultinomGibbs_fit: Fitting Bayesian Ordered Multinomial Regression

Description Usage Arguments Value Examples

View source: R/Poly_Gibbs_ModelFitting.R

Description

MultinomGibbs_fit does Implementation of Multinomial Regression for Ordered Categorical Responses via data augmentation and Gibbs sampling.

Usage

1
MultinomGibbs_fit(Train_X, Train_Y, nIter, burn_in, K)

Arguments

Train_X

n X p matrix of continuous covarites of training set. (Without Intercept)

Train_Y

n X 1 vector of responses of training set. (takes values 1, 2, 3, . K)

nIter

An integer, No of iterations for the Gibbs Sampler

burn_in

An integer, No of iterations neglected at begining of the chain in calculation of posterior mean

K

no of categories. (1,2,3,..K)

Value

estimates A p X 1 vector of estimated posterior mean.

gamma_estimates A (K + 1) X 1 vector of estimated gamma boundaries of Latent Variable Z, starting with -Inf and ending with +Inf.

Train_Accuracy A nIter X 1 vector of Training Accuracy over all iterations.

beta_matrix A nIter X p matrix of beta updates over all iterations.

gamma_update A nIter X (K + 1) matrix of gamma updates over all iterations with first and last columns being all -Inf s and +Inf s respectively.

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
# 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
MultinomGibbs_fit(Train_X, Train_Y, nIter, burn_in, K)

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