predict.bbl {bbl} | R Documentation |
bbl
ModelMake prediction of response group identity based on trained model
## S3 method for class 'bbl'
predict(object, newdata, type = "link", verbose = 1, progress.bar = FALSE, ...)
object |
Object of class |
newdata |
Data frame of new data for which prediction is to
be made. Columns must contain all of those in |
type |
Return value type. If |
verbose |
Verbosity level |
progress.bar |
Display progress of response group probability. Useful for large samples. |
... |
Other arguments to methods |
This method uses a new data set for predictors and trained bbl
model
parameters to compute posterior probabilities of response group
identity.
Data frame of predicted posterior probabilities with samples in rows and response groups in columns. The last column is the predicted response group with maximum probability.
set.seed(154)
m <- 5
L <- 3
n <- 1000
predictors <- list()
for(i in 1:m) predictors[[i]] <- seq(0,L-1)
names(predictors) <- paste0('v',1:m)
par <- list(randompar(predictors=predictors, dJ=0.5),
randompar(predictors=predictors, h0=0.1, J0=0.1, dJ=0.5))
dat <- randomsamp(predictors=predictors, response=c('ctrl','case'), par=par,
nsample=n)
dat <- dat[sample(n),]
dtrain <- dat[seq(n/2),]
dtest <- dat[seq(n/2+1,n),]
model <- bbl(y ~ .^2, data=dtrain)
pred <- predict(model, newdata=dtest)
score <- mean(dtest$y==pred$yhat)
score
auc <- pROC::roc(response=dtest$y, predictor=pred$case, direction='<')$auc
auc