Learn R Programming

fda (version 2.1.3)

fRegress.CV: Computes Cross-validated Error Sum of Integrated Squared Errors for a Functional Regression Model

Description

For a functional regression model, a cross-validated error sum of squares is computed. For a functional dependent variable this is the sum of integrated squared errors. For a scalar response, this function has been superceded by the OCV and gcv elements returned by fRegress. This function aids the choice of smoothing parameters in this model using the cross-validated error sum of squares criterion.

Usage

fRegress.CV(y, xfdlist, betalist, CVobs=NULL, ...)

Arguments

y
the dependent variable object. It may be an object of three possible classes:

  • scalar
{ a vector if the dependent variable is scalar.} fd{ a functional data object if the dependent variable is functional.

Value

  • A list containing
  • SSE.CVThe sum of squared errors, or integrated squared errors
  • errfd.cvEither a vector or a functional data object giving the cross-validated errors.

item

  • xfdlist
  • betalist
  • CVobs
  • ...

code

fRegress

See Also

fRegress, fRegress.stderr

Examples

Run this code
#### A scalar response example.

annualprec <- log10(apply(CanadianWeather$dailyAv[,,
                              "Precipitation.mm"], 2,sum))
# The simplest 'fRegress' call is singular with more bases
# than observations, so we use a small basis for this example
smallbasis  <- create.fourier.basis(c(0, 365), 25)
# There are other ways to handle this,
# but we will not discuss them here
tempfd <- smooth.basis(day.5,
          CanadianWeather$dailyAv[,,"Temperature.C"], smallbasis)$fd

# Set up a list of predictors

xfdlist <- list(const=rep(1, 35), tempfd=tempfd)

# And some functional parameter objects to define the coefficient
# functions.  The intercept must be constant for a scalar response
betabasis1 <- create.constant.basis(c(0, 365))
betafd1    <- fd(0, betabasis1)
betafdPar1 <- fdPar(betafd1)

betafd2     <- with(tempfd, fd(basisobj=basis, fdnames=fdnames))
# convert to an fdPar object
betafdPar2  <- fdPar(betafd2)

betalist <- list(const=betafdPar1, tempfd=betafdPar2)

# Now call fRegress.

precip.Temp <- fRegress(annualprec, xfdlist, betalist)

precip.cv = fRegress.CV(annualprec,xfdlist,betalist)


# Are the temperature profiles different accross regions,
# a functional response model

region.contrasts <- model.matrix(~factor(CanadianWeather$region))
rgnContr3 <- region.contrasts
dim(rgnContr3) <- c(1, 35, 4)
rgns <- paste('region', c('Atlantic', 'Continental', 'Pacific'),
              sep='.')
dimnames(rgnContr3) <- list('', CanadianWeather$place, c('const', rgns))

const365 <- create.constant.basis(c(0, 365))
region.fd.Atlantic <- fd(matrix(rgnContr3[,,2], 1), const365)region.fd.Continental <- fd(matrix(rgnContr3[,,3], 1), const365)
region.fd.Pacific <- fd(matrix(rgnContr3[,,4], 1), const365)
region.fdlist <- list(const=rep(1, 35),
     region.Atlantic=region.fd.Atlantic,
     region.Continental=region.fd.Continental,
     region.Pacific=region.fd.Pacific)
beta1 <- with(tempfd, fd(basisobj=basis, fdnames=fdnames))
beta0 <- fdPar(beta1)
betalist <- list(const=beta0, region.Atlantic=beta0,
             region.Continental=beta0, region.Pacific=beta0)

TempRgn <- fRegress(tempfd, region.fdlist, betalist)

temprgn.ocv <- fRegress.CV(tempfd, region.fdlist, betalist)

Run the code above in your browser using DataLab