predict.mfplm.PVS {fsemipar}R Documentation

Prediction for MFPLM

Description

predict method for the multi-functional partial linear model (MFPLM) fitted using PVS.kernel.fit or PVS.kNN.fit.

Usage

## S3 method for class 'PVS.kernel'
predict(object, newdata.x = NULL, newdata.z = NULL,
  y.test = NULL, option = NULL, ...)
## S3 method for class 'PVS.kNN'
predict(object, newdata.x = NULL, newdata.z = NULL, 
  y.test = NULL, option = NULL, knearest.n = object$knearest, 
  min.knn.n = object$min.knn, max.knn.n = object$max.knn.n, 
  step.n = object$step, ...)

Arguments

object

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

newdata.x

A matrix containing new observations of the functional covariate in the functional nonparametric component, collected by row.

newdata.z

Matrix containing the new observations of the scalar covariates derived from the discretisation of a curve, collected by row.

y.test

(optional) A vector containing the new observations of the response.

option

Allows the selection among the choices 1, 2 and 3 for PVS.kernel objects, and 1, 2, 3, and 4 for PVS.kNN objects. The default setting is 1. See the section Details.

...

Further arguments.

knearest.n

Only used for objects PVS.kNN if option=2, option=3 or option=4: sequence in which the number of nearest neighbours k.opt is selected. The default is object$knearest.

min.knn.n

Only used for objects PVS.kNN if option=2, option=3 or option=4: minumum value of the sequence in which the number of nearest neighbours k.opt is selected (thus, this number must be smaller than the sample size). The default is object$min.knn.

max.knn.n

Only used for objects PVS.kNN if option=2, option=3 or option=4: maximum value of the sequence in which the number of nearest neighbours k.opt is selected (thus, this number must be larger than min.kNN and smaller than the sample size). The default is object$max.knn.

step.n

Only used for objects PVS.kNN if option=2, option=3 or option=4: positive integer used to build the sequence of k-nearest neighbours in the following way: min.knn, min.knn + step.n, min.knn + 2*step.n, min.knn + 3*step.n,.... The default is object$step.

Details

To obtain the predictions of the response for newdata.x and newdata.z, the following options are provided:

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 option=3, two sets of predictions (and two MSEPs) are provided, corresponding to the items a) and b) mentioned in the section Details. 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

PVS.kernel.fit, sfpl.kernel.fit and predict.sfpl.kernel or PVS.kNN.fit, sfpl.kNN.fit and predict.sfpl.kNN.

Examples


data(Sugar)

y<-Sugar$ash
x<-Sugar$wave.290
z<-Sugar$wave.240

#Outliers
index.y.25 <- y > 25
index.atip <- index.y.25
(1:268)[index.atip]

#Dataset to model
x.sug <- x[!index.atip,]
z.sug<- z[!index.atip,]
y.sug <- y[!index.atip]

train<-1:216
test<-217:266

#Fit
fit.kernel<- PVS.kernel.fit(x=x.sug[train,],z=z.sug[train,], 
              y=y.sug[train],train.1=1:108,train.2=109:216,
              lambda.min.h=0.03,lambda.min.l=0.03,
              max.q.h=0.35, nknot=20,criterion="BIC",
              max.iter=5000)
fit.kNN<- PVS.kNN.fit(x=x.sug[train,],z=z.sug[train,], y=y.sug[train],
            train.1=1:108,train.2=109:216,lambda.min.h=0.07, 
            lambda.min.l=0.07, nknot=20,criterion="BIC",
            max.iter=5000)

#Preditions
predict(fit.kernel,newdata.x=x.sug[test,],newdata.z=z.sug[test,],y.test=y.sug[test],option=2)
predict(fit.kNN,newdata.x=x.sug[test,],newdata.z=z.sug[test,],y.test=y.sug[test],option=2)


[Package fsemipar version 1.1.1 Index]