predictExposureEff {fkbma} | R Documentation |
Predict Exposure Effect
Description
This function predicts the exposure effect for new data based the Reversible Jump MCMC (rjMCMC) results.
Usage
predictExposureEff(results, newdata = NULL)
Arguments
results |
An object of class rjMCMC containing the output from the
|
newdata |
A data frame for which predicted values are to be computed If NA, the original fitted data is used. |
Details
The function:
Checks if the required columns in
results$candinter
are present innewdata
.Computes the fitted posterior exposure effect based on main exposure effects, spline interactions, and binary interactions.
Adds noise to the fitted posterior using the residual variance
results$sigma_sq
to generate predictive posterior samples.
Spline interactions are handled by interpolating the spline coefficients for the values in newdata
.
Value
A matrix of predictive posterior samples for the exposure effect, where each row corresponds to a posterior sample
and each column corresponds to an observation in newdata
.
Examples
# Example dataset
data("simulated_data")
candsplinevars <- c("X_1")
candbinaryvars <- paste0("Z_", 1:5)
candinter <- c(candsplinevars, candbinaryvars)
results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter,
outcome = "Y", factor_var = "trt")
newdata = data.frame(Z_1 = 1, Z_2 = 1, Z_3 = 1, Z_4 = 1, Z_5 = 1,
trt = 1, X_1 = seq(0,1,by=0.01))
predictExposureEff(results)
predictExposureEff(results,newdata)