library("masbayes")
# Train/test split
fit <- run_bayesr(W_train, y_train, wtw_train, wty_train,
sigma2_e_init = var(y_train)/2,
sigma2_ah = var(y_train)/2)
pred <- predict(fit, W_test, y_test) # test-set evaluation
pred$metrics$accuracy
pred$metrics$RMSE
fc <- predict(fit, W_unknown) # forecast only, no y
fc$GEBV
insamp <- predict(fit) # in-sample reference
insamp$metrics$R2Predict from a BayesR Fit
Predict from a BayesR Fit
Description
Computes genomic estimated breeding values (GEBVs) and prediction metrics. Works identically for full-fit, train/test split, and k-fold CV — the caller is responsible for data partitioning; predict() only evaluates the trained model on whatever data it receives.
Usage
## S3 method for class 'masbayes_bayesr'
predict(object, newdata = NULL, y_new = NULL, X_new = NULL, ...)
Arguments
object
|
An object of class masbayes_bayesr.
|
newdata
|
Optional numeric design matrix. If NULL, the training GEBVs (object$pred_train) are returned.
|
y_new
|
Optional response vector for newdata. When supplied, prediction metrics are computed.
|
…
|
Unused. |
Details
Three usage modes:
- In-sample (full-fit)
-
Call
predict(fit). Returns training GEBVs and the in-sample metrics already stored in the fit object. - Forecast only
-
Call
predict(fit, W_new)withouty_new. Returns GEBVs for the new design matrix; metrics are skipped. - Test evaluation
-
Call
predict(fit, W_test, y_test). Returns test-set GEBVs plusR2, RMSE, accuracy/AUC, bias.
For test sets built with construct_wah_matrix, pass the training matrix structure as reference_structure so that newdata has identical columns to the training matrix.
Value
An object of class masbayes_prediction: a list with GEBV (liability scale for binary), prob (binary only: P(y = 1) = pnorm(GEBV), otherwise NULL), metrics (R2, RMSE, accuracy/AUC, bias or NULL; for binary, computed on the observed/probability scale so bias is the calibration slope), h2, sigma2_g, sigma2_e, variance_components, response_type, model_type, eval_scope, and has_truth.
See Also
run_bayesr, summary.masbayes_bayesr