predict.sfpl {fsemipar} | R Documentation |
Predictions for SFPLM
Description
predict
method for the semi-functional partial linear model (SFPLM) fitted using sfpl.kernel.fit
or sfpl.kNN.fit
.
Usage
## S3 method for class 'sfpl.kernel'
predict(object, newdata.x = NULL, newdata.z = NULL,
y.test = NULL, option = NULL, ...)
## S3 method for class 'sfpl.kNN'
predict(object, newdata.x = NULL, newdata.z = NULL,
y.test = NULL, option = NULL, ...)
Arguments
object |
Output of the functions mentioned in the |
newdata.x |
Matrix containing new observations of the functional covariate collected by row. |
newdata.z |
Matrix containing the new observations of the scalar covariate collected by row. |
y.test |
(optional) A vector containing the new observations of the response. |
option |
Allows the selection among the choices 1 and 2 for |
... |
Further arguments passed to or from other methods. |
Details
The following options are provided to obtain the predictions of the response for newdata.x
and newdata.z
:
If
option=1
, we maintain all the estimations (k.opt
orh.opt
andbeta.est
) to predict the functional nonparametric component of the model.If
option=2
, we maintainbeta.est
, while the tuning parameter (or
) is selected again to predict the functional nonparametric component of the model. This selection is performed using the leave-one-out cross-validation (LOOCV) criterion in the associated functional nonparametric model, obtaining a global selection for
or
.
In the case of sfpl.kNN
objects if option=3
, we maintain beta.est
, while the tuning parameter is seleted again to predict the functional nonparametric component of the model. This selection is performed using the LOOCV criterion in the associated functional nonparametric model, performing a local selection for
.
Value
The function returns the predicted values of the response (y
) for newdata.x
and newdata.z
. If !is.null(y.test)
, it also provides the mean squared error of prediction (MSEP
) computed as mean((y-y.test)^2)
.
If is.null(newdata.x)
or is.null(newdata.z)
, then the function returns the fitted values.
Author(s)
German Aneiros Perez german.aneiros@udc.es
Silvia Novo Diaz snovo@est-econ.uc3m.es
See Also
sfpl.kernel.fit
and sfpl.kNN.fit
Examples
data("Tecator")
y<-Tecator$fat
X<-Tecator$absor.spectra
z1<-Tecator$protein
z2<-Tecator$moisture
#Quadratic, cubic and interaction effects of the scalar covariates.
z.com<-cbind(z1,z2,z1^2,z2^2,z1^3,z2^3,z1*z2)
train<-1:160
test<-161:215
#Fit
fit.kernel<-sfpl.kernel.fit(x=X[train,], z=z.com[train,], y=y[train],q=2,
max.q.h=0.35,lambda.min.l=0.01, factor.pn=2,
criterion="BIC", range.grid=c(850,1050), nknot=20, max.iter=5000)
fit.kNN<-sfpl.kNN.fit(y=y[train],x=X[train,], z=z.com[train,],q=2,
max.knn=20,lambda.min.l=0.01, factor.pn=2,
criterion="BIC",range.grid=c(850,1050), nknot=20, max.iter=5000)
#Predictions
predict(fit.kernel,newdata.x=X[test,],newdata.z=z.com[test,],y.test=y[test],
option=2)
predict(fit.kNN,newdata.x=X[test,],newdata.z=z.com[test,],y.test=y[test],
option=2)