sim-frmfr: Sampling functional regression models with functional...

sim-frmfrR Documentation

Sampling functional regression models with functional responses

Description

Simulation of a Functional Regression Model with Functional Response (FRMFR) comprised of an additive mix of a linear and nonlinear terms:

Y(t) = \int_a^b X(s) \beta(s,t) ds + \Delta(X)(t) + \varepsilon(t),

where X is a random variable in the Hilbert space of square-integrable functions in [a, b], L^2([a, b]), \beta is the bivariate kernel of the FRMFR, \varepsilon is a random variable in L^2([c, d]), and \Delta(X) is a nonlinear term.

In particular, the scenarios considered in García-Portugués et al. (2021) can be easily simulated.

Usage

r_frm_fr(n, scenario = 3, X_fdata = NULL, error_fdata = NULL,
  beta = NULL, s = seq(0, 1, l = 101), t = seq(0, 1, l = 101),
  std_error = 0.15, nonlinear = NULL, concurrent = FALSE,
  int_rule = "trapezoid", n_fpc = 50, verbose = FALSE, ...)

nl_dev(X_fdata, t = seq(0, 1, l = 101), nonlinear = NULL,
  int_rule = "trapezoid", equispaced = equispaced, verbose = FALSE)

Arguments

n

sample size, only required when scenario is given.

scenario

an index from 1 to 3 (default) denoting one of the scenarios (S1, S2 or S3) simulated in García-Portugués et al. (2021) (see details below). If scenario = NULL, X_fdata, error_fdata, and beta have to be provided. Otherwise, X_fdata, error_fdata, and beta will be ignored.

X_fdata

sample of functional covariates X(s) as fdata objects of length n, with s in [a, b]. Defaults to NULL.

error_fdata

sample of functional errors \varepsilon(t) as fdata objects of length n, with t in [c, d]. If concurrent = TRUE, X_fdata and error_fdata must be valued in the same grid. Defaults to NULL.

beta

matrix containing the values \beta(s, t), for each grid point s in [a, b] and t in [c, d]. If concurrent = TRUE (see details below), a row/column vector must be introduced, valued in the same grid as error_fdata. If beta = NULL (default), scenario != NULL is required.

s, t

grid points. If X_fdata, error_fdata and beta are provided, s and t are ignored. Default to s = seq(0, 1, l = 101) and t = seq(0, 1, l = 101), respectively.

std_error

standard deviation of the random variables involved in the generation of the functional error error_fdata. Defaults to 0.15.

nonlinear

nonlinear term. Either a character string ("exp", "quadratic" or "sin") or an fdata object of length n, valued in the same grid as error_fdata. If nonlinear = NULL (default), the nonlinear part is set to zero.

concurrent

flag to consider a concurrent FLRFR (degenerate case). Defaults to FALSE.

int_rule

quadrature rule for approximating the definite unidimensional integral: trapezoidal rule (int_rule = "trapezoid") and extended Simpson rule (int_rule = "Simpson") are available. Defaults to "trapezoid".

n_fpc

number of components to be considered for the generation of functional variables. Defaults to 50.

verbose

flag to display information about the sampling procedure. Defaults to FALSE.

...

further parameters passed to r_cm2013_flmfr, r_gof2021_flmfr and
r_ik2018_flmfr, depending on the chosen scenario.

equispaced

flag to indicate if X_fdata$data is valued in an equispaced grid or not. Defaults to FALSE.

Details

  • r_frm_fr samples the above regression model, where the nonlinear term \Delta(X) is computed by nl_dev. Functional covariates, errors, and \beta are generated automatically from the scenarios in García-Portugués et al. (2021) when scenario != NULL (see the documentation of r_gof2021_flmfr). If scenario = NULL, covariates, errors and \beta must be provided.

    When concurrent = TRUE, the concurrent FRMFR

    Y(t) = X(t) \beta(t) + \Delta(X)(t) + \varepsilon(t)

    is considered.

  • nl_dev computes a nonlinear deviation \Delta(X): \exp(\sqrt{X(a + (t - c) ((b - a) / (d - c)))}) (for "exp"), (X^2 (a + (t - c) ((b - a) / (d - c))) - 1) ("quadratic") or (\sin(2\pi t) - \cos(2 \pi t)) \| X \|^2 ("sin"). Also, \Delta(X) can be manually set as an fdata object of length n and valued in the same grid as error_fdata.

Value

A list with the following elements:

X_fdata

functional covariates, an fdata object of length n.

Y_fdata

functional responses, an fdata object of length n.

error_fdata

functional errors, an fdata object of length n.

beta

either the matrix with \beta(s, t) evaluated at the argvals of X_fdata and Y_fdata (if concurrent = FALSE) or a vector with \beta(t) evaluated at the argvals of X_fdata (if concurrent = TRUE).

nl_dev

nonlinear term, an fdata object of length n.

Author(s)

Javier Álvarez-Liébana.

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. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/sjos.12486")}

Examples

## Generate samples for the three scenarios

# Equispaced grids and Simpson's rule

s <- seq(0, 1, l = 101)
samp <- list()
old_par <- par(mfrow = c(3, 5))
for (i in 1:3) {
  samp[[i]] <- r_frm_fr(n = 100, scenario = i, s = s, t = s,
                        int_rule = "Simpson")
  plot(samp[[i]]$X_fdata)
  plot(samp[[i]]$error_fdata)
  plot(samp[[i]]$Y_fdata)
  plot(samp[[i]]$nl_dev)
  image(x = s, y = s, z = samp[[i]]$beta, col = viridisLite::viridis(20))
}
par(old_par)

## Linear term as a concurrent model

# The grids must be have the same number of grid points for a given
# nonlinear term and a given beta function

s <- seq(1, 2, l = 101)
t <- seq(0, 1, l = 101)
samp_c_1 <- r_frm_fr(n = 100, scenario = 3, beta = sin(t) - exp(t),
                     s = s, t = t, nonlinear = fda.usc::fdata(mdata =
                       t(matrix(rep(sin(t), 100), nrow = length(t))),
                       argvals = t),
                     concurrent = TRUE)
old_par <- par(mfrow = c(3, 2))
plot(samp_c_1$X_fdata)
plot(samp_c_1$error_fdata)
plot(samp_c_1$Y_fdata)
plot(samp_c_1$nl_dev)
plot(samp_c_1$beta)
par(old_par)

## Sample for given X_fdata, error_fdata, and beta

# Non equispaced grids with sinusoidal nonlinear term and intensity 0.5
s <- c(seq(0, 0.5, l = 50), seq(0.51, 1, l = 101))
t <- seq(2, 4, len = 151)
X_fdata <- r_ou(n = 100, t = s, alpha = 2, sigma = 4, x0 = 1:100)
error_fdata <- r_ou(n = 100, t = t, alpha = 1, sigma = 1, x0 = 1:100)
beta <- r_gof2021_flmfr(n = 100, s = s, t = t)$beta
samp_Xeps <- r_frm_fr(scenario = NULL, X_fdata = X_fdata,
                      error_fdata = error_fdata, beta = beta,
                      nonlinear = "exp", int_rule = "trapezoid")
old_par <- par(mfrow = c(3, 2))
plot(samp_Xeps$X_fdata)
plot(samp_Xeps$error_fdata)
plot(samp_Xeps$Y_fdata)
plot(samp_Xeps$nl_dev)
image(x = s, y = t, z = beta, col = viridisLite::viridis(20))
par(old_par)

goffda documentation built on Oct. 14, 2023, 5:08 p.m.