fda.usc (version 2.0.1)

rp.flm.statistic: Statistics for testing the functional linear model using random projections

Description

Computes the Cramer-von Mises (CvM) and Kolmogorv-Smirnov (kS) statistics on the projected process $$T_{n,h}(u)=\frac{1}{n}\sum_{i=1}^n (Y_i-\langle X_i,\hat \beta\rangle)1_{\{\langle X_i, h\rangle\leq u\}},$$ designed to test the goodness-of-fit of a functional linear model with scalar response. NA's are not allowed neither in the functional covariate nor in the scalar response.

Usage

rp.flm.statistic(proj.X, residuals, proj.X.ord = NULL, F.code = TRUE)

Arguments

proj.X

matrix of size c(n, n.proj) containing, for each column, the projections of the functional data \(X_1,\ldots,X_n\) into a random direction \(h\). Not required if proj.X.ord is provided.

residuals

the residuals of the fitted funtional linear model, \(Y_i-\langle X_i,\hat \beta\rangle\). Either a vector of length n (same residuals for all projections) or a matrix of size c(n.proj, n) (each projection has an associated set residuals).

proj.X.ord

matrix containing the row permutations of proj.X which rearranges them increasingly, for each column. So, for example proj.X[proj.X.ord[, 1], 1] equals sort(proj.X[, 1]). If not provided, it is computed internally.

F.code

whether to use faster FORTRAN code or R code.

Value

A list containing:

  • list("statistic") a matrix of size c(n.proj, 2) with the the CvM (first column) and KS (second) statistics, for the n.proj different projections.

  • list("proj.X.ord")the computed row permutations of proj.X, useful for recycling in subsequent calls to rp.flm.statistic with the same projections but different residuals.

References

Cuesta-Albertos, J.A., Garcia-Portugues, E., Febrero-Bande, M. and Gonzalez-Manteiga, W. (2017). Goodness-of-fit tests for the functional linear model based on randomly projected empirical processes. arXiv:1701.08363. https://arxiv.org/abs/1701.08363

Examples

Run this code
# NOT RUN {
# Simulated example
set.seed(345678)
t <- seq(0, 1, l = 101)
n <- 100
X <- r.ou(n = n, t = t)
beta0 <- fdata(mdata = cos(2 * pi * t) - (t - 0.5)^2, argvals = t,
               rangeval = c(0,1))
Y <- inprod.fdata(X, beta0) + rnorm(n, sd = 0.1)

# Linear model
mod <- fregre.pc(fdataobj = X, y = Y, l = 1:3)

# Projections
proj.X1 <- inprod.fdata(X, r.ou(n = 1, t = t))
proj.X2 <- inprod.fdata(X, r.ou(n = 1, t = t))
proj.X12 <- cbind(proj.X1, proj.X2)

# Statistics
t1 <- rp.flm.statistic(proj.X = proj.X1, residuals = mod$residuals)
t2 <- rp.flm.statistic(proj.X = proj.X2, residuals = mod$residuals)
t12 <- rp.flm.statistic(proj.X = proj.X12, residuals = mod$residuals)
t1$statistic
t2$statistic
t12$statistic

# Recycling proj.X.ord
rp.flm.statistic(proj.X.ord = t1$proj.X.ord, residuals = mod$residuals)$statistic
t1$statistic

# Sort in the columns
cbind(proj.X12[t12$proj.X.ord[, 1], 1], proj.X12[t12$proj.X.ord[, 2], 2]) -
apply(proj.X12, 2, sort)

# FORTRAN and R code
rp.flm.statistic(proj.X = proj.X1, residuals = mod$residuals)$statistic -
rp.flm.statistic(proj.X = proj.X1, residuals = mod$residuals, 
                 F.code = FALSE)$statistic

# Matrix and vector residuals
rp.flm.statistic(proj.X = proj.X12, residuals = mod$residuals)$statistic
rp.flm.statistic(proj.X = proj.X12, 
                 residuals = rbind(mod$residuals, mod$residuals * 2))$statistic
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab