Learn R Programming

fsemipar (version 1.1.1)

predict.sfpl: 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 sfpl.kernel
predict(object, newdata.x = NULL, newdata.z = NULL,
  y.test = NULL, option = NULL, ...)
# S3 method for sfpl.kNN
predict(object, newdata.x = NULL, newdata.z = NULL, 
  y.test = NULL, option = NULL, ...)

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.

Arguments

object

Output of the functions mentioned in the Description (i.e. an object of the class sfpl.kernel or sfpl.kNN.

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 sfpl.kernel objects, and 1, 2 and 3 for sfpl.kNN objects. The default setting is 1. See the section Details.

...

Further arguments passed to or from other methods.

Author

German Aneiros Perez german.aneiros@udc.es

Silvia Novo Diaz snovo@est-econ.uc3m.es

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 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\).

See Also

sfpl.kernel.fit and sfpl.kNN.fit

Examples

Run this code
# \donttest{
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)
# }

Run the code above in your browser using DataLab