flm_stat {goffda}R Documentation

Projected Cramér–von Mises test statistic for the goodness-of-fit test of functional linear models

Description

Computation of the Projected Cramér–von Mises (PCvM) test statistic and its associated \mathbf{A}_\bullet matrix. For a sample of functional covariates X_1, \ldots, X_n, the test statistic is computed from \mathbf{x}_{1,p}, \ldots, \mathbf{x}_{n,p}, the coefficients (scores) of the sample in a p-truncated basis expansion, such as Functional Principal Components (FPC).

The PCvM statistic is defined as

\mathrm{PCvM}_{n,p,q} = c \cdot \mathrm{tr}(\hat{\mathbf{E}}_q' \mathbf{A}_\bullet \hat{\mathbf{E}}_q)

where

c = 2 \pi^{(p + q) / 2 - 1} / (q \Gamma(p / 2) \Gamma(q / 2) n^2),

\hat{\mathbf{E}}_q is the n \times q matrix of multivariate residuals, and \mathbf{A}_\bullet is a n \times n matrix whose ij-th element is \sum_{r = 1}^n A_{ijr}, for A_{ijr} depending on (\mathbf{x}_{i,p}, \mathbf{x}_{j,p}, \mathbf{x}_{r,p}). Its exact expression can be seen in Escanciano (2006) and García-Portugués et al. (2021).

Usage

flm_stat(E, p, Adot_vec, constant = TRUE)

Adot(X)

Arguments

E

the matrix of multivariate residuals, with dimension c(n, q). A vector if q = 1.

p

dimension of the covariates space. Must be a positive integer.

Adot_vec

output from Adot. A vector of length n * (n - 1) / 2 + 1. This corresponds to the most expensive computation in the test statistic.

constant

whether to include the constant of the PCvM test statistic, c, in its computation. Defaults to TRUE.

X

a matrix of size c(n, p) containing the coefficients (scores) of the functional data in a p-truncated orthonormal basis expansion, such as FPC. Must not contain repeated rows.

Details

Adot assumes that X does not have repeated rows or otherwise NaNs will be present in the result. If X has repeated rows, Adot will throw a warning.

The implementation of the PCvM test statistic for scalar response is addressed in García-Portugués et al. (2014), whereas García-Portugués et al. (2021) presents its multivariate extension and shows that \mathbf{A}_\bullet induces a weighted quadratic norm (if there are no repetitions in the sample). The PCvM statistic is rooted in the proposal by Escanciano (2006).

Both flm_stat and A_dot are coded in C++.

Value

Author(s)

Eduardo García-Portugués.

References

García-Portugués, E., Álvarez-Liébana, J., Álvarez-Pérez, G. and Gonzalez-Manteiga, W. (2021). A goodness-of-fit test for the functional linear model with functional response. Scandinavian Journal of Statistics, 48(2):502–528. doi:10.1111/sjos.12486

Escanciano, J. C. (2006) A consistent diagnostic test for regression models using projections. Econometric Theory, 22(6):1030–-1051. doi:10.1017/S0266466606060506

García-Portugués, E., González-Manteiga, W. and Febrero-Bande, M. (2014). A goodness-of-fit test for the functional linear model with scalar response. Journal of Computational and Graphical Statistics, 23(3):761–778. doi:10.1080/10618600.2013.812519

Examples

## flm_stat

# Generate data
n <- 200
q <- 2
p <- 3
E <- matrix(rnorm(n * q), nrow = n, ncol = q)
X_fdata <- r_ou(n = n, t = seq(0, 1, l = 101))

# Compute FPC
X_fpc <- fpc(X_fdata)

# Adot
Adot_vec <- Adot(X = X_fpc[["scores"]])

# Check equality
constant <- n^(-2) * 2 * pi^((p / 2) - 1) / gamma(p / 2)
constant * .Fortran("pcvm_statistic", n = as.integer(n),
                    Adot_vec = Adot_vec, residuals = E[, 2],
                    statistic = 0)$statistic
flm_stat(E = E[, 2, drop = FALSE], p = p, Adot_vec = Adot_vec,
         constant = FALSE)

## Adot

# Generate data
n <- 200
X_fdata <- r_ou(n = n, t = seq(0, 1, l = 101))

# Compute FPC
X_fpc <- fpc(X_fdata)

# Using inprod_fdata and Adot
Adot_vec <- Adot(X = X_fpc[["scores"]])

# Check with fda.usc::Adot with adequate inprod
head(drop(Adot_vec))
head(fda.usc::Adot(X_fdata))

# Obtention of the entire Adot matrix
Ad <- diag(rep(Adot_vec[1], n))
Ad[upper.tri(Ad, diag = FALSE)] <- Adot_vec[-1]
head(Ad <- t(Ad) + Ad - diag(diag(Ad)))

# Positive definite
eigen(Ad)$values

# # Warning if X contains repeated observations
# Adot(X = rbind(1:3, 1:3, 3:5))

# Comparison with .Fortran("adot", PACKAGE = "fda.usc")
n <- as.integer(n)
a <- as.double(rep(0, (n * (n - 1) / 2 + 1)))
inprod <- X_fpc[["scores"]] %*% t(X_fpc[["scores"]])
inprod <- inprod[upper.tri(inprod, diag = TRUE)]
X <- X_fpc[["scores"]]
microbenchmark::microbenchmark(
  .Fortran("adot", n = n, inprod = inprod, Adot_vec = a,
           PACKAGE = "fda.usc"),
  Adot(X = X),
  times = 50, control = list(warmup = 10))


[Package goffda version 0.1.2 Index]