Title: | Multiple Contrast Tests for Functional Data |
---|---|
Description: | The provided package implements multiple contrast tests for functional data (Munko et al., 2023, <arXiv:2306.15259>). These procedures enable us to evaluate the overall hypothesis regarding equality, as well as specific hypotheses defined by contrasts. In particular, we can perform post hoc tests to examine particular comparisons of interest. Different experimental designs are supported, e.g., one-way and multi-way analysis of variance for functional data. |
Authors: | Marc Ditzhaus [aut], Merle Munko [aut], Markus Pauly [aut], Lukasz Smaga [aut, cre], Jin-Ting Zhang [aut] |
Maintainer: | Lukasz Smaga <[email protected]> |
License: | LGPL-2 | LGPL-3 | GPL-2 | GPL-3 |
Version: | 0.1.0 |
Built: | 2024-10-29 03:46:18 UTC |
Source: | https://github.com/cran/multiFANOVA |
The function multiFANOVA()
calculates the globalizing pointwise Hotelling's -test
(GPH) statistic for the global null hypothesis and multiple local null hypotheses.
Respective
-values are obtained by a parametric bootstrap strategy.
multiFANOVA( x, gr_label, h, n_boot = 1000, alpha = 0.05, parallel = FALSE, n_cores = NULL )
multiFANOVA( x, gr_label, h, n_boot = 1000, alpha = 0.05, parallel = FALSE, n_cores = NULL )
x |
matrix of observations |
gr_label |
a vector with group labels; the integer labels (from 1 to a number of groups) should be used. |
h |
contrast matrix. For Dunnett’s and Tukey’s contrasts, it can be created by
the |
n_boot |
number of bootstrap samples. |
alpha |
significance level. |
parallel |
a logical indicating whether to use parallelization. |
n_cores |
if |
The function multiFANOVA()
concerns the tests for the heteroscedastic
contrast testing problem for functional data. The details are presented in Munko et al. (2023),
but here we present some summary of the problem and its solutions implemented in the package.
Suppose we have independent functional samples
,
which consist of independent and identically distributed stochastic processes defined
on interval
with mean function
and covariance function
for each
. Note that the covariance functions
of the different groups may differ from each other, i.e., heteroscedasticity is explicitly allowed.
We consider the null and alternative hypothesis
where
denotes a known contrast matrix, i.e.,
,
is the vector of the mean functions.
The formulation of this testing framework is very general
and contains many special cases like the analysis of variance for functional data
(FANOVA) problem. In detail, we may choose
for the one-way FANOVA problem
to test the null hypothesis of no main effect, where
with
denoting the unit matrix and
denoting the matrix of ones. However, there are different possible choices of the
contrast matrix
which lead to this global null hypothesis.
Many-to-one comparisons can be considered by choosing Dunnett's contrast matrix
, where the mean
functions
are compared to the mean function
of the first group regarding the different contrasts. To compare all pairs
of mean functions
with
, the Tukey's contrast matrix:
can be used.
For this testing problem, we consider the pointwise Hotelling's -test statistic
for all , where
denotes the vector of all mean function estimators,
denotes the
Moore-Penrose inverse of the matrix
, and
,
is the sample covariance function for the
-th group,
.
Based on this pointwise Hotelling's
-test statistic, we construct the globalizing
pointwise Hotelling's
-test (GPH) statistic by integrating over the pointwise
Hotelling's
-test statistic, that is
We consider the parametric bootstrap test based on this test statistic. However, for better post hoc
analysis, we also consider the multiple contrast testing procedures. The main idea of multiple contrast
tests is to split up the global null hypothesis with matrix
into
single contrast
tests with contrast vectors
.
This leads to the multiple testing problem with null hypotheses
To verify this family of null hypotheses, we adopt two approaches. First, we simply apply
the above test to each hypothesis , and the resulting
-values
are then corrected by the Bonferroni's method. However, this approach, denoted in the package as
GPH, may give conservative test and loss of power. Thus, we also consider the test adopting the
idea for the construction of simultaneous confidence bands proposed by Buhlmann (1998).
This test is denoted by mGPH in the package and is a more powerful solution than the GPH
procedure, which was shown in Munko et al. (2023).
Note that the value of the test statistic for the mGPH test for global hypotheses is equals to
where are the quantiles calculated using
the adaptation of the method by Buhlmann (1998). The critical value for it is always 1.
Please have a look at a summary function designed for this package. It can be used
to simplify the output of multiFANOVA()
function.
A list of class multifanova
containing the following components:
res_global |
a data frame containing the results for testing the global null hypothesis,
i.e., test statistics and |
res_multi |
all results of multiple contrasts tests for particular hypothesis in
a contrast matrix |
k |
a number of groups. |
j |
a number of design time points. |
n |
a vector of sample sizes. |
h |
an argument |
h_boot |
an argument |
alpha |
an argument |
Buhlmann P. (1998) Sieve bootstrap for smoothing in nonstationary time series. Annals of Statistics 26, 48-83.
Dunnett C. (1955) A multiple comparison procedure for comparing several treatments with a control. Journal of the American Statistical Association 50, 1096-1121.
Munko M., Ditzhaus M., Pauly M., Smaga L., Zhang J.T. (2023) General multiple tests for functional data. Preprint https://arxiv.org/abs/2306.15259
Tukey J.W. (1953) The problem of multiple comparisons. Princeton University.
# Some of the examples may run some time. # Canadian weather data set # There are three samples of mean temperatures for # fifteen weather stations in Eastern Canada, # another fifteen in Western Canada, and # the remaining five in Northern Canada. library(fda) data_set <- t(CanadianWeather$dailyAv[,, "Temperature.C"]) k <- 3 gr_label <- rep(c(1, 2, 3), c(15, 15, 5)) # trajectories of mean temperatures matplot(t(data_set), type = "l", col = gr_label, lty = 1, xlab = "Day", ylab = "Temperature (C)", main = "Canadian weather data set") legend("bottom", legend = c("Eastern Canada", "Western Canada", "Northern Canada"), col = 1:3, lty = 1) # Tukey's contrast matrix h_tukey <- GFDmcv::contr_mat(k, type = "Tukey") # testing without parallel computing res <- multiFANOVA(data_set, gr_label, h_tukey) summary(res, digits = 3) # plots for pointwise Hotelling's T^2-test statistics oldpar <- par(mfrow = c(2, 2), mar = c(2, 2, 2, 0.1)) plot(ph_test_statistic(data_set, gr_label, h_tukey), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Global hypothesis") plot(ph_test_statistic(data_set, gr_label, matrix(h_tukey[1, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Contrast 1") plot(ph_test_statistic(data_set, gr_label, matrix(h_tukey[2, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Contrast 2") plot(ph_test_statistic(data_set, gr_label, matrix(h_tukey[3, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Contrast 3") par(oldpar) # testing with parallel computing library(doParallel) res <- multiFANOVA(data_set, gr_label, h_tukey, parallel = TRUE, n_cores = 2) summary(res, digits = 3) # Dunnett's contrast matrix h_dunnett <- GFDmcv::contr_mat(k, type = "Dunnett") res <- multiFANOVA(data_set, gr_label, h_dunnett) summary(res, digits = 3) # plots for pointwise Hotelling's T^2-test statistics oldpar <- par(mfrow = c(3, 1), mar = c(2, 2, 2, 0.1)) plot(ph_test_statistic(data_set, gr_label, h_dunnett), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_dunnett))), main = "Global hypothesis") plot(ph_test_statistic(data_set, gr_label, matrix(h_dunnett[1, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_dunnett))), main = "Contrast 1") plot(ph_test_statistic(data_set, gr_label, matrix(h_dunnett[2, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_dunnett))), main = "Contrast 2") par(oldpar)
# Some of the examples may run some time. # Canadian weather data set # There are three samples of mean temperatures for # fifteen weather stations in Eastern Canada, # another fifteen in Western Canada, and # the remaining five in Northern Canada. library(fda) data_set <- t(CanadianWeather$dailyAv[,, "Temperature.C"]) k <- 3 gr_label <- rep(c(1, 2, 3), c(15, 15, 5)) # trajectories of mean temperatures matplot(t(data_set), type = "l", col = gr_label, lty = 1, xlab = "Day", ylab = "Temperature (C)", main = "Canadian weather data set") legend("bottom", legend = c("Eastern Canada", "Western Canada", "Northern Canada"), col = 1:3, lty = 1) # Tukey's contrast matrix h_tukey <- GFDmcv::contr_mat(k, type = "Tukey") # testing without parallel computing res <- multiFANOVA(data_set, gr_label, h_tukey) summary(res, digits = 3) # plots for pointwise Hotelling's T^2-test statistics oldpar <- par(mfrow = c(2, 2), mar = c(2, 2, 2, 0.1)) plot(ph_test_statistic(data_set, gr_label, h_tukey), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Global hypothesis") plot(ph_test_statistic(data_set, gr_label, matrix(h_tukey[1, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Contrast 1") plot(ph_test_statistic(data_set, gr_label, matrix(h_tukey[2, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Contrast 2") plot(ph_test_statistic(data_set, gr_label, matrix(h_tukey[3, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Contrast 3") par(oldpar) # testing with parallel computing library(doParallel) res <- multiFANOVA(data_set, gr_label, h_tukey, parallel = TRUE, n_cores = 2) summary(res, digits = 3) # Dunnett's contrast matrix h_dunnett <- GFDmcv::contr_mat(k, type = "Dunnett") res <- multiFANOVA(data_set, gr_label, h_dunnett) summary(res, digits = 3) # plots for pointwise Hotelling's T^2-test statistics oldpar <- par(mfrow = c(3, 1), mar = c(2, 2, 2, 0.1)) plot(ph_test_statistic(data_set, gr_label, h_dunnett), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_dunnett))), main = "Global hypothesis") plot(ph_test_statistic(data_set, gr_label, matrix(h_dunnett[1, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_dunnett))), main = "Contrast 1") plot(ph_test_statistic(data_set, gr_label, matrix(h_dunnett[2, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_dunnett))), main = "Contrast 2") par(oldpar)
-test statisticThe function ph_test_statistic()
calculates the pointwise Hotelling's -test statistic.
ph_test_statistic(x, gr_label, h)
ph_test_statistic(x, gr_label, h)
x |
matrix of observations |
gr_label |
a vector with group labels; the integer labels (from 1 to a number of groups) should be used. |
h |
contrast matrix. For Dunnett’s and Tukey’s contrasts, it can be created by
the |
For details, see the documentation of the multiFANOVA()
function or
the paper Munko et al. (2023).
A vector of values of the pointwise Hotelling's -test statistic.
Dunnett C. (1955) A multiple comparison procedure for comparing several treatments with a control. Journal of the American Statistical Association 50, 1096-1121.
Munko M., Ditzhaus M., Pauly M., Smaga L., Zhang J.T. (2023) General multiple tests for functional data. Preprint https://arxiv.org/abs/2306.15259
Tukey J.W. (1953) The problem of multiple comparisons. Princeton University.
# Some of the examples may run some time. # Canadian weather data set # There are three samples of mean temperatures for # fifteen weather stations in Eastern Canada, # another fifteen in Western Canada, and # the remaining five in Northern Canada. library(fda) data_set <- t(CanadianWeather$dailyAv[,, "Temperature.C"]) k <- 3 gr_label <- rep(c(1, 2, 3), c(15, 15, 5)) # trajectories of mean temperatures matplot(t(data_set), type = "l", col = gr_label, lty = 1, xlab = "Day", ylab = "Temperature (C)", main = "Canadian weather data set") legend("bottom", legend = c("Eastern Canada", "Western Canada", "Northern Canada"), col = 1:3, lty = 1) # Tukey's contrast matrix h_tukey <- GFDmcv::contr_mat(k, type = "Tukey") # testing without parallel computing res <- multiFANOVA(data_set, gr_label, h_tukey) summary(res, digits = 3) # plots for pointwise Hotelling's T^2-test statistics oldpar <- par(mfrow = c(2, 2), mar = c(2, 2, 2, 0.1)) plot(ph_test_statistic(data_set, gr_label, h_tukey), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Global hypothesis") plot(ph_test_statistic(data_set, gr_label, matrix(h_tukey[1, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Contrast 1") plot(ph_test_statistic(data_set, gr_label, matrix(h_tukey[2, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Contrast 2") plot(ph_test_statistic(data_set, gr_label, matrix(h_tukey[3, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Contrast 3") par(oldpar)
# Some of the examples may run some time. # Canadian weather data set # There are three samples of mean temperatures for # fifteen weather stations in Eastern Canada, # another fifteen in Western Canada, and # the remaining five in Northern Canada. library(fda) data_set <- t(CanadianWeather$dailyAv[,, "Temperature.C"]) k <- 3 gr_label <- rep(c(1, 2, 3), c(15, 15, 5)) # trajectories of mean temperatures matplot(t(data_set), type = "l", col = gr_label, lty = 1, xlab = "Day", ylab = "Temperature (C)", main = "Canadian weather data set") legend("bottom", legend = c("Eastern Canada", "Western Canada", "Northern Canada"), col = 1:3, lty = 1) # Tukey's contrast matrix h_tukey <- GFDmcv::contr_mat(k, type = "Tukey") # testing without parallel computing res <- multiFANOVA(data_set, gr_label, h_tukey) summary(res, digits = 3) # plots for pointwise Hotelling's T^2-test statistics oldpar <- par(mfrow = c(2, 2), mar = c(2, 2, 2, 0.1)) plot(ph_test_statistic(data_set, gr_label, h_tukey), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Global hypothesis") plot(ph_test_statistic(data_set, gr_label, matrix(h_tukey[1, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Contrast 1") plot(ph_test_statistic(data_set, gr_label, matrix(h_tukey[2, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Contrast 2") plot(ph_test_statistic(data_set, gr_label, matrix(h_tukey[3, ], 1)), type = "l", ylim = c(0, max(ph_test_statistic(data_set, gr_label, h_tukey))), main = "Contrast 3") par(oldpar)
Prints the summary of the global and multiple contrasts testing for functional data.
## S3 method for class 'multifanova' summary(object, ...)
## S3 method for class 'multifanova' summary(object, ...)
object |
a "multifanova" object. |
... |
integer indicating the number of decimal places to be used to present the numerical results.
It can be named |
The function prints out the information about the number of samples,
number of observations in each sample, number of design time points, contrasts used,
test statistics, critical values, -values of tests performed by the
multiFANOVA()
function. It also gives the decisions.
No return value, called for side effects.
# Some of the examples may run some time. # Canadian weather data set # There are three samples of mean temperatures for # fifteen weather stations in Eastern Canada, # another fifteen in Western Canada, and # the remaining five in Northern Canada. library(fda) data_set <- t(CanadianWeather$dailyAv[,, "Temperature.C"]) k <- 3 gr_label <- rep(c(1, 2, 3), c(15, 15, 5)) # Tukey's contrast matrix h_tukey <- GFDmcv::contr_mat(k, type = "Tukey") # testing without parallel computing res <- multiFANOVA(data_set, gr_label, h_tukey) summary(res, digits = 3)
# Some of the examples may run some time. # Canadian weather data set # There are three samples of mean temperatures for # fifteen weather stations in Eastern Canada, # another fifteen in Western Canada, and # the remaining five in Northern Canada. library(fda) data_set <- t(CanadianWeather$dailyAv[,, "Temperature.C"]) k <- 3 gr_label <- rep(c(1, 2, 3), c(15, 15, 5)) # Tukey's contrast matrix h_tukey <- GFDmcv::contr_mat(k, type = "Tukey") # testing without parallel computing res <- multiFANOVA(data_set, gr_label, h_tukey) summary(res, digits = 3)