predict.engression {engression} | R Documentation |
Prediction Function for Engression Models
Description
This function computes predictions from a trained engression model. It allows for the generation of point estimates, quantiles, or samples from the estimated distribution.
Usage
## S3 method for class 'engression'
predict(
object,
Xtest,
type = c("mean", "sample", "quantile")[1],
trim = 0.05,
quantiles = 0.1 * (1:9),
nsample = 200,
drop = TRUE,
...
)
Arguments
object |
A trained engression model returned from engression, engressionBagged or engressionfit functions. |
Xtest |
A matrix or data frame representing the predictors in the test set. |
type |
The type of prediction to make. "mean" for point estimates, "sample" for samples from the estimated distribution, or "quantile" for quantiles of the estimated distribution (default: "mean"). |
trim |
The proportion of extreme values to trim when calculating the mean (default: 0.05). |
quantiles |
The quantiles to estimate if type is "quantile" (default: 0.1*(1:9)). |
nsample |
The number of samples to draw if type is "sample" (default: 200). |
drop |
A boolean indicating whether to drop dimensions of length 1 from the output (default: TRUE). |
... |
additional arguments (currently ignored) |
Value
A matrix or array of predictions.
Examples
n = 1000
p = 5
X = matrix(rnorm(n*p),ncol=p)
Y = (X[,1]+rnorm(n)*0.1)^2 + (X[,2]+rnorm(n)*0.1) + rnorm(n)*0.1
Xtest = matrix(rnorm(n*p),ncol=p)
Ytest = (Xtest[,1]+rnorm(n)*0.1)^2 + (Xtest[,2]+rnorm(n)*0.1) + rnorm(n)*0.1
## fit engression object
engr = engression(X,Y)
print(engr)
## prediction on test data
Yhat = predict(engr,Xtest,type="mean")
cat("\n correlation between predicted and realized values: ", signif(cor(Yhat, Ytest),3))
plot(Yhat, Ytest,xlab="prediction", ylab="observation")
## quantile prediction
Yhatquant = predict(engr,Xtest,type="quantiles")
ord = order(Yhat)
matplot(Yhat[ord], Yhatquant[ord,], type="l", col=2,lty=1,xlab="prediction", ylab="observation")
points(Yhat[ord],Ytest[ord],pch=20,cex=0.5)
## sampling from estimated model
Ysample = predict(engr,Xtest,type="sample",nsample=1)