| predict.sfpl | R Documentation |
predict method for the semi-functional partial linear model (SFPLM) fitted using sfpl.kernel.fit or sfpl.kNN.fit.
## 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, ...)
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. |
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 or h.opt and beta.est) to predict the functional nonparametric component of the model.
If option=2, we maintain beta.est, while the tuning parameter (h or k) 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 h or k.
In the case of sfpl.kNN objects if option=3, we maintain beta.est, while the tuning parameter k 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 k.
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.
German Aneiros Perez german.aneiros@udc.es
Silvia Novo Diaz snovo@est-econ.uc3m.es
sfpl.kernel.fit and sfpl.kNN.fit
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.