sparseFLMM: Functional Linear Mixed Models for Irregularly or Sparsely...

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/call_all_functions.R

Description

Estimation of functional linear mixed models (FLMMs) for irregularly or sparsely sampled data based on functional principal component analysis (FPCA). The implemented models are special cases of the general FLMM

Y_i(t_{ij}) = μ(t_{ij},x_i) + z_i^T U(t_{ij}) + ε_i(t_{ij}), i = 1,...,n, j = 1,...,D_i,

with Y_i(t_{ij}) the value of the response of curve i at observation point t_{ij}, μ(t_{ij},x_i) is a mean function, which may depend on covariates x_i = (x_{i1},…,x_{ip})^T. z_i is a covariate vector, which is multiplied with the vector of functional random effects U(t_{ij}). ε_i(t_{ij}) is independent and identically distributed white noise measurement error with homoscedastic, constant variance. For more details, see references below.

The current implementation can be used to fit four special cases of the above general FLMM:

Usage

 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
35
36
37
38
39
40
41
42
43
44
45
46
47
sparseFLMM(
  curve_info,
  use_RI = FALSE,
  use_simple = FALSE,
  method = "fREML",
  use_bam = TRUE,
  bs = "ps",
  d_grid = 100,
  min_grid = 0,
  max_grid = 1,
  my_grid = NULL,
  bf_mean = 8,
  bf_covariates = 8,
  m_mean = c(2, 3),
  covariate = FALSE,
  num_covariates,
  covariate_form,
  interaction,
  which_interaction = matrix(NA),
  save_model_mean = FALSE,
  para_estim_mean = FALSE,
  para_estim_mean_nc = 0,
  bf_covs,
  m_covs,
  use_whole = FALSE,
  use_tri = FALSE,
  use_tri_constr = TRUE,
  use_tri_constr_weights = FALSE,
  np = TRUE,
  mp = TRUE,
  use_discrete_cov = FALSE,
  para_estim_cov = FALSE,
  para_estim_cov_nc = 0,
  var_level = 0.95,
  N_B = NA,
  N_C = NA,
  N_E = NA,
  use_famm = FALSE,
  use_bam_famm = TRUE,
  bs_int_famm = list(bs = "ps", k = 8, m = c(2, 3)),
  bs_y_famm = list(bs = "ps", k = 8, m = c(2, 3)),
  save_model_famm = FALSE,
  use_discrete_famm = FALSE,
  para_estim_famm = FALSE,
  para_estim_famm_nc = 0,
  nested = FALSE
)

Arguments

curve_info

data table in which each row represents a single observation point. curve_info needs to contain the following columns:

  • y_vec (numeric): the response values for each observation point

  • t (numeric): the observations point locations, i.e. t_{ij}

  • n_long (integer): unique identification number for each curve

  • subject_long (integer): unique identification number for each level of the first grouping variable (e.g. speakers for the phonetics data in the example below). In the case of independent functions, subject_long should be set equal to n_long.

For models with two crossed functional random intercepts, the data table additionally needs to have columns:

  • word_long (integer): unique identification number for each level of the second grouping variable (e.g. words for the phonetics data in the example below)

  • combi_long (integer): number of the repetition of the combination of the corresponding level of the first and of the second grouping variable.

For models with two nested functional random intercepts, the data table additionally needs to have columns: #'

  • word_long (integer): unique identification number for each level of the second grouping variable (e.g. phases of a randomized controled trial). Note that the nested model is only implemented for two levels in the second grouping variable.

  • combi_long (integer): number of the repetition of the combination of the corresponding level of the first and of the second grouping variable.

For models with covariates as part of the mean function μ(t_{ij},x_i), the covariate values (numeric) need to be in separate columns with names: covariate.1, covariate.2, etc.

use_RI

TRUE to specify a model with one functional random intercept for the first grouping variable (subject_long) and a smooth random error curve. Defaults to FALSE, which specifies a model with crossed functional random intercepts for the first and second grouping variable and a smooth error curve.

use_simple

TRUE to specify a model with only a smooth random error function, use_RI should then also be set to TRUE. Defaults to FALSE.

method

estimation method for gam or bam, see mgcv for more details. Defaults to "fREML".

use_bam

TRUE to use function bam instead of function gam (syntax is the same, bam is faster for large data sets). bam is recommended and set as default.

bs

spline basis function type for the estimation of the mean function and the auto-covariance, see s and te for more details. Defaults to penalized B-splines, i.e. bs = "ps". This choice is recommended as others have not been tested yet.

d_grid

pre-specified grid length for equidistant grid on which the mean, the auto-covariance surfaces, the eigenfunctions and the functional random effects are evaluated. NOTE: the length of the grid can be important for computation time (approx. quadratic influence). Defaults to d_grid = 100.

min_grid

minimum value of equidistant grid (should approx. correspond to minimum value of time interval). Defaults to min_grid = 0.

max_grid

maximum value of equidistant grid (should approx. correspond to maximum value of time interval). Defaults to max_grid = 1.

my_grid

optional evaluation grid, which can be specified and used instead of d_grid, min_grid, max_grid. NOTE: the grid should be equidistant.

bf_mean

basis dimension (number of basis functions) used for the functional intercept f_0(t_{ij}) in the mean estimation via bam/gam. Defaults to bf_mean = 8.

bf_covariates

basis dimension (number of basis functions) used for the functional effects of covariates in the mean estimation via bam/gam. Defaults to bf_covariates = 8. NOTE: in the current implementation, the same basis dimension for all covariates is used.

m_mean

order of the penalty for this term in bam/gam of mean estimation, for bs = "ps" spline and penalty order, defaults to m_mean = c(2, 3), i.e., cubic B-splines with third order difference penalty, see s for details.

covariate

TRUE to estimate covariate effects (as part of the mean function).

num_covariates

number of covariates that are included in the model. NOTE: not number of effects in case interactions of covariates are specified.

covariate_form

vector with entries for each covariate that specify the form in which the respective covariate enters the mean function. Possible forms are "by" for varying-coefficient (f(t_{ij})*covariate), which is possible for dummy coded covariates and metric covariates and "smooth" for smooth effect in t and in covariate (f(t_{ij}, covariate)), which is only possible for metric covariates! NOTE: metric covariates should be centered such that the global functional intercept f_0(t_{ij}) can be interpreted as global mean function and the effect can be interpreted as difference from the global mean.

interaction

TRUE to estimate interaction effects of covariates, which interactions, see which_interaction (below). Interactions are possible for dummy-coded covariates that act as varying coefficients.

which_interaction

symmetric matrix that specifies which interactions should be considered in case covariate = TRUE and interaction = TRUE. Entry which_interaction[k, l] specifies that the interaction between covariate.k and covariate.l is modeled (example below). NOTE: entries are redundant, which_interaction[l, k] should be set to the same as which_interaction[k, l] (symmetric). Defaults to which_interaction = matrix(NA) which should be specified when interaction = FALSE.

save_model_mean

TRUE to give out gam/bam object (attention: can be large!), defaults to FALSE.

para_estim_mean

TRUE to parallelize mean estimation (only possible using bam), defaults to FALSE.

para_estim_mean_nc

number of cores for parallelization of mean estimation (only possible using bam, only active if para_estim_mean = TRUE). Defaults to 0.

bf_covs

vector of marginal basis dimensions (number of basis functions) used for covariance estimation via bam/gam for each functional random effect (including the smooth error curve). In the case of multiple grouping variables, the first entry corresponds to the first grouping variable, the second vector entry corresponds to the second grouping variable, and the third to the smooth error curve.

m_covs

list of marginal orders of the penalty for bam/gam for covariance estimation, for bs = "ps" marginal spline and penalty order. As only symmetric surfaces are considered: same for both directions.
For crossed fRIs: list of three vectors, e.g. m_covs = list(c(2, 3), c(2, 3), c(2, 3)), where first and second entry correspond to first and second grouping variable, respectively and third entry corresponds to smooth error. For one fRI: list of two vectors, e.g. m_covs = list(c(2, 3), c(2, 3)), where first entry corresponds to (first) grouping variable and second entry corresponds to smooth error. For independent curves: list of one vector, e.g. m_covs = list(c(2,3)) corresponding to smooth error.

use_whole

TRUE to estimate the whole auto-covariance surfaces without symmetry constraint. Defaults to FALSE as is much slower than use_tri_constr and use_tri_constr_weights. For more details, see references below.

use_tri

TRUE to estimate only the upper triangle of the auto-covariance surfaces without symmetry constraint. Defaults to FALSE and not recommended. For more details, see references below.

use_tri_constr

TRUE to estimate only the upper triangle of the auto-covariance surfaces with symmetry constraint using the smooth class 'symm'. Defaults to TRUE. For more details, see references below.

use_tri_constr_weights

TRUE to estimate only the upper triangle of the auto-covariances with symmetry constraint, using the smooth class 'symm' and weights of 0.5 on the diagonal to use the same weights as for estimating the whole auto-covariance surfaces. Defaults to FALSE. For more details, see references below.

np

TRUE to use 'normal parameterization' for a tensor product smooth, see te for more details. Defaults to TRUE.

mp

FALSE to use Kronecker product penalty instead of Kronecker sum penalty with only one smoothing parameter (use_whole = TRUE and use_tri = TRUE), for details see te. For use_tri_constr = TRUE and use_tri_constr_weights = TRUE, only one smoothing parameter is estimated anyway. Defaults to TRUE.

use_discrete_cov

TRUE to further speed up the auto-covariance computation by discretization of covariates for storage and efficiency reasons, includes parallelization controlled by para_estim_cov_nc (below), see bam for more details. Defaults to FALSE.

para_estim_cov

TRUE to parallelize auto-covariance estimation (only possible using bam), defaults to FALSE.

para_estim_cov_nc

number of cores (if use_discrete_cov = FALSE) or number of threads (if use_discrete_cov = TRUE) for parallelization of auto-covariance estimation (only possible using bam, only active if para_estim_cov = TRUE). Defaults to 0.

var_level

pre-specified level of explained variance used for the choice of the number of the functional principal components (FPCs). Alternatively, a specific number of FPCs can be specified (see below). Defaults to var_level = 0.95.

N_B

number of components for B (fRI for first grouping variable) to keep, overrides var_level if not NA.

N_C

number of components for C (fRI for second grouping variable) to keep, overrides var_level if not NA.

N_E

number of components for E (smooth error) to keep, overrides var_level if not NA.

use_famm

TRUE to embed the model into the framework of functional additive mixed models (FAMMs) using re-estimation of the mean function together with the prediction of the FPC weights (scores). This allows for point-wise confidence bands for the covariate effects. Defaults to FALSE.

use_bam_famm

TRUE to use function bam instead of function gam in FAMM estimation (reduces computation time for large data sets), highly recommended. Defaults to TRUE.

bs_int_famm

specification of the estimation of the functional intercept f_0(t_{ij}) (as part of the mean function), see pffr for details. Defaults to bs_int = list(bs = "ps", k = 8, m = c(2, 3)), where bs: type of basis functions, k: number of basis functions, m: order of the spline and order of the penalty.

bs_y_famm

specification of the estimation of the covariates effects (as part of the mean function), see pffr for details. Defaults to bs_y_famm = list(bs = "ps", k = 8, m = c(2, 3)), where bs: type of basis functions, k: number of basis functions, m: order of the spline and order of the penalty.

save_model_famm

TRUE to give out the FAMM model object (attention: can be very large!). Defaults to FALSE.

use_discrete_famm

TRUE to further speed up the fpc-famm computation by discretization of # covariates for storage and efficiency reasons, includes parallelization controlled by para_estim_famm_nc (below), see bam for more details. Defaults to FALSE.

para_estim_famm

TRUE to parallelize FAMM estimation. Defaults to FALSE.

para_estim_famm_nc

number of cores (if use_discrete_famm = FALSE) or number of threads (if use_discrete_famm = TRUE) for parallelization of FAMM estimation (only possible using bam, only active if para_estim_famm = TRUE). Defaults to 0.

nested

TRUE to specify a model with nested functional random intercepts for the first and second grouping variable and a smooth error curve. Defaults to FALSE.

Details

The code can handle irregularly and possibly sparsely sampled data. Of course, it can also be used to analyze regular grid data, but as it is especially designed for the irregular case and there may be a more efficient way to analyze regular grid data.

The mean function is of the form

μ(t_{ij},x_i) = f_0(t_{ij}) + ∑_{k=1}^r f_k(t_{ij},x_{ik}),

where f_0(t_{ij}) is a functional intercept. Currently implemented are effects of dummy-coded and metric covariates which act as varying-coefficients of the form f_k(t_{ij})*x_{ik} and smooth effects of metric covariates (smooth in t and in the covariate) of the form f(t_{ij}, x_{ik}). NOTE: metric covariates should be centered such that the global functional intercept can be interpreted as global mean function and the effect can be interpreted as difference from the global mean. Interaction effects of dummy-coded covariates acting as varying coefficients are possible.

The estimation consists of four main steps:

  1. estimation of the smooth mean function (including covariate effects) under independence assumption using splines.

  2. estimation of the smooth auto-covariances of the functional random effects. A fast bivariate symmetric smoother implemented in the smooth class 'symm' can be used to speed up estimation (see below).

  3. eigen decomposition of the estimated auto-covariances, which are evaluated on a pre-specified equidistant grid. This yields estimated eigenvalues and eigenfunctions, which are rescaled to ensure orthonormality with respect to the L2-scalar product.

  4. prediction of the functional principal component weights (scores) yielding predictions for the functional random effects.

The estimation of the mean function and auto-covariance functions is based on package mgcv.
The functional principal component weights (scores) are predicted as best (linear) unbiased predictors. In addition, this implementation allows to embed the model in the general framework of functional additive mixed models (FAMM) based on package refund, which allows for the construction of point-wise confidence bands for covariate effects (in the mean function) conditional on the FPCA. Note that the estimation as FAMM may be computationally expensive as the model is re-estimated in a mixed model framework.

The four special cases of the general FLMM (two nested fRIs, two crossed fRIs, one fRI, independent curves) are implemented as follows:

Value

The function returns a list of two elements: time_all and results.
time_all contains the total system.time() for calling function sparseFLMM().
results is a list of all estimates, including:

For each auto-covariance smoothing alternative X (use_whole, use_tri, use_tri_constr, use_tri_constr_weights):

Author(s)

Jona Cederbaum

References

Cederbaum, Pouplier, Hoole, Greven (2016): Functional Linear Mixed Models for Irregularly or Sparsely Sampled Data. Statistical Modelling, 16(1), 67-88.

Cederbaum, Scheipl, Greven (2016): Fast symmetric additive covariance smoothing. Submitted on arXiv.

Scheipl, F., Staicu, A.-M. and Greven, S. (2015): Functional Additive Mixed Models, Journal of Computational and Graphical Statistics, 24(2), 477-501.

See Also

Note that sparseFLMM calls bam or gam directly.

For functional linear mixed models with complex correlation structures for data sampled on equal grids based on functional principal component analysis, see function denseFLMM in package denseFLMM.

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
## Not run: 
# subset of acoustic data (very small subset, no meaningful results can be expected and
# FAMM estimation does not work for this subset example. For FAMM estimation, see below.)
data("acoustic_subset")

acoustic_results <- sparseFLMM(curve_info = acoustic_subset, use_RI = FALSE, use_simple = FALSE,
              method = "fREML", use_bam = TRUE, bs = "ps", d_grid = 100, min_grid = 0,
              max_grid = 1, my_grid = NULL, bf_mean = 8, bf_covariates = 8, m_mean = c(2,3),
              covariate = TRUE, num_covariates = 4, covariate_form = rep("by", 4),
              interaction = TRUE,
              which_interaction = matrix(c(FALSE, TRUE, TRUE, TRUE, TRUE,
              FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE,
              FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE),
              byrow = TRUE, nrow = 4, ncol = 4),
              save_model_mean = FALSE, para_estim_mean = FALSE, para_estim_mean_nc = 0,
              bf_covs = c(5, 5, 5), m_covs = list(c(2, 3), c(2, 3), c(2, 3)),
              use_whole = FALSE, use_tri = FALSE, use_tri_constr = TRUE,
              use_tri_constr_weights = FALSE, np = TRUE, mp = TRUE,
              use_discrete_cov = FALSE,
              para_estim_cov = FALSE, para_estim_cov_nc = 5,
              var_level = 0.95, N_B = NA, N_C = NA, N_E = NA,
              use_famm = FALSE, use_bam_famm = TRUE,
              bs_int_famm = list(bs = "ps", k = 8, m = c(2, 3)),
              bs_y_famm = list(bs = "ps", k = 8, m = c(2, 3)),
              save_model_famm = FALSE, use_discrete_famm = FALSE,
              para_estim_famm = FALSE, para_estim_famm_nc = 0)
## End(Not run)

## Not run: 
# whole data set with estimation in the FAMM framework

data("acoustic")
acoustic_results <- sparseFLMM(curve_info = acoustic, use_RI = FALSE, use_simple = FALSE,
              method = "fREML", use_bam = TRUE, bs = "ps", d_grid = 100, min_grid = 0,
              max_grid = 1, my_grid = NULL, bf_mean = 8, bf_covariates = 8, m_mean = c(2,3),
              covariate = TRUE, num_covariates = 4, covariate_form = rep("by", 4),
              interaction = TRUE,
              which_interaction = matrix(c(FALSE, TRUE, TRUE, TRUE, TRUE,
              FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE,
              FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE),
              byrow = TRUE, nrow = 4, ncol = 4),
              save_model_mean = FALSE, para_estim_mean = FALSE, para_estim_mean_nc = 0,
              bf_covs = c(5, 5, 5), m_covs = list(c(2, 3), c(2, 3), c(2, 3)),
              use_whole = FALSE, use_tri = FALSE, use_tri_constr = TRUE,
              use_tri_constr_weights = FALSE, np = TRUE, mp = TRUE,
              use_discrete_cov = FALSE,
              para_estim_cov = TRUE, para_estim_cov_nc = 5,
              var_level = 0.95, N_B = NA, N_C = NA, N_E = NA,
              use_famm = TRUE, use_bam_famm = TRUE,
              bs_int_famm = list(bs = "ps", k = 8, m = c(2, 3)),
              bs_y_famm = list(bs = "ps", k = 8, m = c(2, 3)),
              save_model_famm = FALSE, use_discrete_famm = FALSE,
              para_estim_famm = TRUE, para_estim_famm_nc = 5)
## End(Not run)

sparseFLMM documentation built on June 19, 2021, 5:06 p.m.