crossval: Leave-one-out cross-validation

Description Usage Arguments Value References Examples

Description

It computes the cross-validation for a given lambda and k or find the optimal lambda for a given k (see below).

Usage

1
2
3
4
5
6
7
funcregCV(form, create_basis=create.bspline.basis, LD=2, lambda,
          k, CstInt=FALSE, regularized=TRUE, alpha=1e-5, data=NULL,
          obj=NULL, ...)

getFuncregLam(form, create_basis=create.bspline.basis, LD=2, lam0,
              k, regularized=TRUE, CstInt=FALSE, data=NULL, loglam=FALSE,
              method="BFGS", alpha=1e-5, optimArg=list(), ...)

Arguments

obj

An object of class "funcreg". If NULL, all other arguments must be set.

form

A formula for the functional regression. Arguments are objects of class "myfda" obtained either by coefEst or nlCoefEst, and must be in the local environment.

create_basis

The function used to create the basis object (see create.bspline.basis) for the functional parameters.

LD

Either a nonnegative integer defining an order of a derivative or a linear differential operator (see eval.penalty).

data

An optional list of myfda objects, which are the functional data included in the formula form

lambda

A vector of regularization parameters that penalizes for the absence of smoothness. The dimention is 2 times the number of regressors plus 1 if there is an intercept and if CstInt=FALSE. The first is for the intercept, the second and third for the first regressor and so on. If it is a scalar, it is assumed that the smoothing parameter is the same for all functional parameters.

lam0

Initial value of lambda for the minimization of the cross-validation

k

A vector of integers representing the number of basis for each functional parameter. The first is for the intercept (if there is an intercept and that Cstint=FALSE), the second for the first functional parameter and so on. If it is a scalar, it is assumed that the number of basis is the same for all functional parameters.

regularized

If TRUE, the system is regularized by add alpha to the main diagonal of the regression matrix

CstInt

If TRUE, the intercept is assumed constant. If FALSE, it is a one dimensional functional parameter.

loglam

If TRUE, lam0 is log10(lambda) and the function minimizes CV(10^lam). It prevents the lambda's from being negative.

method

The algorithm used by link{optim}

optimArg

A list of additional arguments to pass to link{optim}

alpha

The regularization parameter. The value is added to the diagonal of the regression matrix to make sure it is positive definite.

...

Additional arguments to be passed to create_basis (see create.bspline.basis).

Value

'funregCV' returns the value of the leave-one-out cross-validation. The attributes 'convergence', returns convergence code for each estimation.

'getFuncregLam' returns the fitted object of class 'funcreg' using the optimal lambda. The argument 'optimRes' gives the optim output from the minimization of the cross-validation.

References

Ramsay, James O., & Silverman, Bernard W. (2005), Functional Data Analysis, Springer, New York.

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
28
29
30
31
32
33
34
data(GDPv56) 

## We just create response and a covariate artificialy from the GDP
## series

y <- GDPv56[,1:30]
x <- GDPv56[,31:60]
t <- seq(0,1,len=nrow(y))

## First we create the "myfda" objects
yfd <- coefEst(y, t, .0004, 15, 2)
xfd <- coefEst(x, t, .0004, 15, 2)


## with the object
res <- funcreg(yfd~xfd, k=c(5,5), lambda=c(.001,.001,.001))
funcregCV(obj=res)

## without object
funcregCV(yfd~xfd, k=c(5,5), lambda=c(.001,.001,.001))

## With the default values
getFuncregLam(yfd~xfd, k=c(5,5), lam0=c(.001,.001,.001))

## With upper and lower bound
getFuncregLam(yfd~xfd, k=c(5,5), lam0=c(.001,.001,.001), method="L-BFGS-B",
             optimArg=list(lower=c(0,0,0),upper=c(200,200,200))) 

## With loglam
res <- getFuncregLam(yfd~xfd, k=c(5,5), lam0=c(-3,-3,-3), loglam=TRUE)
res

## Get info about the optim()
res$optimRes

funcreg documentation built on May 2, 2019, 5:45 p.m.

Related to crossval in funcreg...