predict_BLRM: Bayesian Logistic Regression Model Prediction on MCMC Beta...

Description Usage Arguments Value Examples

View source: R/Bayesian-function.R

Description

This function computes predicted probabilities based on MCMC Beta samples generated by BLRM_fit_mwg function.

Usage

1
predict_BLRM(Y.test, X.test, MCsamples)

Arguments

Y.test

a vector of binary data

X.test

a design matrix that has the same number of columns with the dimension of Beta

MCsamples

a matrix of MCMC sampled Betas stacked in rows

Value

a data frame of input binary data and corresponding predicted probabilities of being 1.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## simulate data

set.seed(1);
N  = 1000;
p  = 10;

X.test    = matrix(data = rnorm(N*p), nrow=N, ncol=p)
beta_true = c(rep(1,p/2),rep(0,p/2))
eta       = X.test %*% beta_true
pi        = exp(eta) / (1 + exp(eta))
Y.test    = rbinom(N,1,pi)

## simulate MCMC beta samples (beta_true + N(0, 0.5) random errors)

M = 1000
MCsamples = matrix(data = rep(beta_true, M), nrow = M, ncol = p, byrow = T) + matrix(data = rnorm(M*p, sd = 0.5), nrow=M, ncol=p)

## predict based on MCMC beta samples

prediction = predict_BLRM(Y.test, X.test, MCsamples)

## Classification Metrics with cutoff = 0.5
caret::confusionMatrix(data = factor(prediction$data), reference = factor(ifelse(prediction$pred.prob > 0.5, 1, 0)), positive = "1")

lcw68/G3proj documentation built on Dec. 21, 2021, 9:46 a.m.