bplsr.predict {bplsr}R Documentation

Predict from a fitted BPLS regression model

Description

Generates predictions from the fitted BPLS regression model using Monte Carlo simulation.

Usage

bplsr.predict(model, newdata, PredInterval = 0.95)

Arguments

model

Output of bplsr.

newdata

Matrix of predictor variables to predict for.

PredInterval

Intended coverage of prediction intervals (between 0 and 1). Setting the value to 0 only produces point predictions without prediction intervals.

Details

Predictions of the responses are generated from the posterior predictive distribution, marginalising out the model parameters; see Section 3.5 of Urbas et al. (2024).

Value

A list of:

Ytest

Point predictions for new responses; if Xtest is provided.

Ytest_PI

Prediction intervals for new responses (by default 0.95 coverage); if Xtest is provided.

Ytest_dist

Posterior predictive distributions for new responses; if Xtest is provided.

References

Urbas, S., Lovera, P., Daly, R., O'Riordan, A., Berry, D., and Gormley, I. C. (2024). "Predicting milk traits from spectral data using Bayesian probabilistic partial least squares regression." The Annals of Applied Statistics, 18(4): 3486-3506. <\doi{10.1214/24-AOAS1947}>

Examples


# data(milk_MIR)
X = milk_MIR$xMIR
Y = milk_MIR$yTraits[, c('Casein_content','Fat_content')]

set.seed(1)
# fit model to 25% of data and predict on remaining 75%
idx = sample(seq(nrow(X)),floor(nrow(X)*0.25),replace = FALSE)

Xtrain = X[idx,];Ytrain = Y[idx,]
Xtest = X[-idx,];Ytest = Y[-idx,]

# fit the model (for default MCMC settings leave Qs and N_MCMC blank; can take longer)
bplsr_Fit = bplsr(Xtrain,Ytrain, Qs = 10, N_MCMC = 5000)

# generate predictions
bplsr_pred = bplsr.predict(model = bplsr_Fit, newdata = Xtest)

# point predictions
head(bplsr_pred$Ytest)

# lower and upper limits of prediction interval
head(bplsr_pred$Ytest_PI)

# plot of predictive posterior distribution for single test sample
hist(bplsr_pred$Ytest_dist[1,'Casein_content',], freq = FALSE,
     main = 'Posterior predictive density', xlab = 'Casein_content')

[Package bplsr version 1.0.4 Index]