far.cv: Cross Validation for FARX(1) model

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/far.R

Description

Cross Validation for FAR(1) and FARX(1) models

Usage

1
far.cv(data, y, x, kn, ncv, cvcrit, center=TRUE, na.rm=TRUE, joined=FALSE)

Arguments

data

A fdata object.

y

A vector giving the name(s) of the endogenous variable(s) of the model.

x

A vector giving the name(s) of the exogenous variable(s) of the model.

kn

A vector giving the maximum values of the various kn (dimension of plug-in in the algorithm). If it not supplied, the number of discretization point is used.

ncv

Number of observations used to the cross validation

cvcrit

A vector of characters. Name of the variable used to measure the errors (y by default).

center

Logical. Does the observation need to be centered.

na.rm

Logical. Does the n.a. need to be removed.

joined

Logical. If TRUE, the joined (whole) far model is computed, otherwise the model work with the separated variables.

Details

In order to perform good forecasting with a FAR or FARX model, you need to determine the dimensions kn of the subspace in which the linear operator is estimated (see far for more details).

This function helps the user to do this choice by performing a cross validation on a test sample. The usage is close of the far function, so we will discuss about the options which differ.

First, the kn option is used to restrict the values searched: this is a vector containing the maxima values. As in far, the dimension of this vector is function of the number of variables involved in the model and the type of estimation done (joined or not).

ncv is the number of observation used to test the models. If it is not provided, the function use the last fifth of the observations in data. In such a case, the four first fifth are used to estimates the models. This is in general a good compromise.

Finally, cvcrit list the variables used to test the models. If more than one variable is provided, the test is calculated as a mean of the errors over all the variables.

The criteria used to test the (functional) errors are the norms L1, L2, L infinite, L1 on the maxima, L2 on the maxima, and L infinite on the maxima.

Value

It is a LIST with the following elements

cv

Matrix giving the various errors (L1, L2, L infinite, L1 on the maxima, L2 on the maxima, L infinite on the maxima) for the tested values of kn

minL1

A vector corresponding to the row of cv where the L1 error minima is obtained

minL2

A vector corresponding to the row of cv where the L2 error minima is obtained

minLinf

A vector corresponding to the row of cv where the L infinite error minima is obtained

minL1max

A vector corresponding to the row of cv where the L1 maxima's error minima is obtained

minL2max

A vector corresponding to the row of cv where the L2 maxima's error minima is obtained

minLinfmax

A vector corresponding to the row of cv where the L infinite maxima's error minima is obtained

Author(s)

J. Damon

See Also

far, fdata

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  # Simulation of a FARX process
  data1 <- simul.farx(m=10,n=400,base=base.simul.far(20,5),
                base.exo=base.simul.far(20,5),
                d.a=matrix(c(0.5,0),nrow=1,ncol=2),
                alpha.conj=matrix(c(0.2,0),nrow=1,ncol=2),
                d.rho=diag(c(0.45,0.90,0.34,0.45)),
                alpha=diag(c(0.5,0.23,0.018)),
                d.rho.exo=diag(c(0.45,0.90,0.34,0.45)),
                cst1=0.0)

  # Cross validation (joined and separate)
  model1.cv <- far.cv(data=data1, y="X", x="Z", kn=8, ncv=10, cvcrit="X",
                center=FALSE, na.rm=FALSE, joined=TRUE)
  model2.cv <- far.cv(data=data1, y="X", x="Z", kn=c(4,4), ncv=10, cvcrit="X",
                center=FALSE, na.rm=FALSE, joined=FALSE)
  print(model1.cv)
  print(model2.cv)
  k1 <- model1.cv$minL2[1]
  k2 <- model2.cv$minL2[1:2]

  # Modelization of the FARX process (joined and separate)
  model1 <- far(data=data1, y="X", x="Z", kn=k1,
                center=FALSE, na.rm=FALSE, joined=TRUE)
  model2 <- far(data=data1, y="X", x="Z", kn=k2,
                center=FALSE, na.rm=FALSE, joined=FALSE)
  print(model1)
  print(model2)

Example output

Loading required package: nlme
far library : Modelization for Functional AutoRegressive processes

version 0.6-4 (2014-12-07)

$cv
     k1        L1        L2      Linf     L1max     L2max   Linfmax
[1,]  1 0.3639407 0.4204178 0.6806899 0.3913738 0.5182750 1.2095343
[2,]  2 0.3919939 0.4575799 0.7497994 0.5091259 0.6196362 1.1641795
[3,]  3 0.3757759 0.4254760 0.6567897 0.3529375 0.4321720 0.9714574
[4,]  4 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[5,]  5 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[6,]  6 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[7,]  7 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[8,]  8 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979

$minL1
       k1        L1        L2      Linf     L1max     L2max   Linfmax 
1.0000000 0.3639407 0.4204178 0.6806899 0.3913738 0.5182750 1.2095343 

$minL2
     k1        L1        L2      Linf     L1max     L2max   Linfmax
[1,]  5 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[2,]  7 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[3,]  8 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979

$minLinf
       k1        L1        L2      Linf     L1max     L2max   Linfmax 
5.0000000 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979 

$minL1max
       k1        L1        L2      Linf     L1max     L2max   Linfmax 
3.0000000 0.3757759 0.4254760 0.6567897 0.3529375 0.4321720 0.9714574 

$minL2max
       k1        L1        L2      Linf     L1max     L2max   Linfmax 
3.0000000 0.3757759 0.4254760 0.6567897 0.3529375 0.4321720 0.9714574 

$minLinfmax
       k1        L1        L2      Linf     L1max     L2max   Linfmax 
4.0000000 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979 

$cv
      k1 k2        L1        L2      Linf     L1max     L2max   Linfmax
 [1,]  1  1 0.3923343 0.4575261 0.7495119 0.5109755 0.6218949 1.1641540
 [2,]  1  2 0.3923343 0.4575261 0.7495119 0.5109755 0.6218949 1.1641540
 [3,]  1  3 0.3923343 0.4575261 0.7495119 0.5109755 0.6218949 1.1641540
 [4,]  1  4 0.3923343 0.4575261 0.7495119 0.5109755 0.6218949 1.1641540
 [5,]  2  1 0.3751891 0.4247165 0.6552114 0.3521493 0.4317305 0.9713117
 [6,]  2  2 0.3751891 0.4247165 0.6552114 0.3521493 0.4317305 0.9713117
 [7,]  2  3 0.3751891 0.4247165 0.6552114 0.3521493 0.4317305 0.9713117
 [8,]  2  4 0.3751891 0.4247165 0.6552114 0.3521493 0.4317305 0.9713117
 [9,]  3  1 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[10,]  3  2 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[11,]  3  3 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[12,]  3  4 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[13,]  4  1 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[14,]  4  2 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[15,]  4  3 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[16,]  4  4 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979

$minL1
     k1 k2        L1        L2      Linf     L1max     L2max   Linfmax
[1,]  3  1 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[2,]  3  2 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[3,]  3  3 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[4,]  3  4 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979

$minL2
     k1 k2        L1        L2      Linf     L1max     L2max   Linfmax
[1,]  3  1 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[2,]  3  2 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[3,]  3  3 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[4,]  3  4 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[5,]  4  1 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[6,]  4  2 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[7,]  4  3 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[8,]  4  4 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979

$minLinf
     k1 k2        L1        L2      Linf     L1max     L2max   Linfmax
[1,]  3  1 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[2,]  3  2 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[3,]  3  3 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[4,]  3  4 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979

$minL1max
     k1 k2        L1        L2      Linf     L1max     L2max   Linfmax
[1,]  2  1 0.3751891 0.4247165 0.6552114 0.3521493 0.4317305 0.9713117
[2,]  2  2 0.3751891 0.4247165 0.6552114 0.3521493 0.4317305 0.9713117
[3,]  2  3 0.3751891 0.4247165 0.6552114 0.3521493 0.4317305 0.9713117
[4,]  2  4 0.3751891 0.4247165 0.6552114 0.3521493 0.4317305 0.9713117

$minL2max
     k1 k2        L1        L2      Linf     L1max     L2max   Linfmax
[1,]  2  1 0.3751891 0.4247165 0.6552114 0.3521493 0.4317305 0.9713117
[2,]  2  2 0.3751891 0.4247165 0.6552114 0.3521493 0.4317305 0.9713117
[3,]  2  3 0.3751891 0.4247165 0.6552114 0.3521493 0.4317305 0.9713117
[4,]  2  4 0.3751891 0.4247165 0.6552114 0.3521493 0.4317305 0.9713117

$minLinfmax
     k1 k2        L1        L2      Linf     L1max     L2max   Linfmax
[1,]  3  1 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[2,]  3  2 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[3,]  3  3 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979
[4,]  3  4 0.3691782 0.4185356 0.6384524 0.3584994 0.4379681 0.9680979

Functional Autoregressive Model
Call:  far(data = data1, y = "X", x = "Z", kn = k1, center = FALSE,      na.rm = FALSE, joined = TRUE) 

Joined variable
Dimension of the subspace:  5 
Explained Variance:  100 %
Estimated first Eigen values of the Covariance:  4.540e-01 2.565e-01 1.188e-01 8.698e-03 3.077e-17 

Estimated correlation Matrix in adequate subspace: 
       [,1]   [,2]   [,3]   [,4] [,5]
[1,]  0.578 -0.069 -0.010 -0.359    0
[2,] -0.247  0.525 -0.017 -0.180    0
[3,]  0.015 -0.017  0.907  0.095    0
[4,]  0.006  0.008 -0.010  0.277    0
[5,]  0.000  0.000  0.000  0.000    0

Functional Autoregressive Model
Call:  far(data = data1, y = "X", x = "Z", kn = k2, center = FALSE,      na.rm = FALSE, joined = FALSE) 

Variable:  X 
Dimension of the subspace:  3 
Explained Variance:  100 %
Estimated first Eigen values of the Covariance:  0.55931 0.23753 0.01742 

Variable:  Z 
Dimension of the subspace:  3 
Explained Variance:  100 %
Estimated first Eigen values of the Covariance:  8.617e-01 3.720e-17 2.779e-17 

Estimated correlation Matrix in adequate subspace: 
       [,1]   [,2]   [,3]   [,4] [,5] [,6]
[1,]  0.633 -0.015 -0.046  0.227    0    0
[2,] -0.022  0.907  0.092 -0.005    0    0
[3,]  0.006 -0.010  0.279 -0.008    0    0
[4,]  0.049  0.019  0.401  0.468    0    0
[5,]  0.000  0.000  0.000  0.000    0    0
[6,]  0.000  0.000  0.000  0.000    0    0

far documentation built on May 2, 2019, 9:28 a.m.

Related to far.cv in far...