Description Usage Arguments Value Examples
View source: R/Bayesian-function.R
This function computes predicted probabilities based on MCMC Beta samples generated by BLRM_fit_mwg function.
1 | predict_BLRM(Y.test, X.test, MCsamples)
|
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 |
a data frame of input binary data and corresponding predicted probabilities of being 1.
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.