graph.fanova: One-way graphical functional ANOVA

View source: R/graphfanova.r

graph.fanovaR Documentation

One-way graphical functional ANOVA

Description

One-way ANOVA tests for functional data with graphical interpretation

Usage

graph.fanova(
  nsim,
  curve_set,
  groups,
  typeone = c("fwer", "fdr"),
  variances = "equal",
  contrasts = FALSE,
  n.aver = 1L,
  mirror = FALSE,
  savefuns = FALSE,
  test.equality = c("mean", "var", "cov"),
  cov.lag = 1,
  ...
)

Arguments

nsim

The number of random permutations.

curve_set

The original data (an array of functions) provided as a curve_set object (see create_curve_set) or a fdata object (see fdata). The curve set should include the argument values for the functions in the component r, and the observed functions in the component obs.

groups

The original groups (a factor vector representing the assignment to groups).

typeone

Character string indicating which type I error rate to control, either the familywise error rate ('fwer') or false discovery rate ('fdr'). Further arguments to the FWER or FDR envelope can be passed in argument GET.args. If 'fwer', the type of the envelope can be chosen by specifying the argument type in GET.args.

variances

Either "equal" or "unequal". If "unequal", then correction for unequal variances as explained in details will be done. Only relevant for the case test.equality = "means" (default).

contrasts

Logical. FALSE and TRUE specify the two test functions as described in description part of this help file.

n.aver

If variances = "unequal", there is a possibility to use variances smoothed by appying moving average to the estimated sample variances. n.aver determines how many values on each side do contribute (incl. value itself).

mirror

The complement of the argument circular of filter. Another parameter for the moving average to estimate sample variances (see n.aver).

savefuns

Logical. If TRUE, then the functions from permutations are saved to the attribute simfuns.

test.equality

A character with possible values mean (default), var and cov. If mean, the functional ANOVA is performed to compare the means in the groups. If var, then the equality of variances of the curves in the groups is tested by performing the graphical functional ANOVA test on the functions

Z_{ij}(r) = T_{ij}(r) - \bar{T}_j(r).

If cov, then the equality of lag cov.lag covariance is tested by performing the fANOVA with

|V_{ij}(r)| sign(V_{ij}(r)),

where

V_{ij}(r) = (T_{ij}(r) - \bar{T}_j(r))((T_{ij}(r+s) - \bar{T}_j(r+s))).

See Mrkvicka et al. (2020) for more details.

cov.lag

The lag of the covariance for testing the equality of covariances, see test.equality.

...

Additional parameters to be passed to global_envelope_test (if typeone = "fwer") or fdr_envelope (if typeone = "fdr").

Details

This function can be used to perform one-way graphical functional ANOVA tests described in Mrkvička et al. (2020). Both 1d and 2d functions are allowed in curve sets.

The tests assume that there are J groups which contain n1, ..., nJ functions T_{ij}, i=1,...,J, j=1,...,nj. The functions should be given in the argument curve_set, and the groups in the argument groups. The tests assume that T_{ij}, i=1,...,n_j is an iid sample from a stochastic process with mean function μ_j and covariance function γ_j(s,t) for s,t in R and j = 1,..., J.

To test the hypothesis

H0: μ_1(r) = μ_2(r) = ... = μ_J(r),

you can use the test function

T = (\bar{T}_1(r), \bar{T}_2(r), ..., \bar{T}_J(r))

where \bar{T}_i(r) is a vector of mean values of functions in the group j. This test function is used when contrasts = FALSE (default).

The hypothesis can equivalently be written as

H0: μ_i(r) - μ_j(r) = 0, i=1,...,J-1, j=i,...,J.

and, alternatively, one can use the test function (vector) taken to consist of the differences of the group averages,

T' = (\bar{T}_1(r)-\bar{T}_2(r), \bar{T}_1(r)-\bar{T}_3(r), ..., \bar{T}_{J-1}(r)-\bar{T}_J(r)).

The choice is available with the option contrasts = TRUE. This test corresponds to the post-hoc test done usually after an ANOVA test is significant, but it can be directed tested by means of the combined rank test (Mrkvička et al., 2017) with this test vector.

The test as such assumes that the variances are equal across the groups of functions. To deal with unequal variances, the differences are rescaled as the first step as follows

S_{ij}(r) = ( T_{ij}(r) - \bar{T}(r) ) / Sd(T_j(r)) * Sd(T(r)) + \bar{T}(r))

where \bar{T}(r) is the overall sample mean and Sd(T(r)) is the overall sample standard deviation. This scaling of the test functions can be obtained by giving the argument variances = "unequal".

References

Mrkvička, T., Myllymäki, M., Jilek, M. and Hahn, U. (2020) A one-way ANOVA test for functional data with graphical interpretation. Kybernetika 56 (3), 432-458. doi: 10.14736/kyb-2020-3-0432

Mrkvička, T., Myllymäki, M., and Hahn, U. (2017). Multiple Monte Carlo testing, with applications in spatial point processes. Statistics and Computing 27 (5): 1239-1255. doi:10.1007/s11222-016-9683-9

Myllymäki, M and Mrkvička, T. (2020). GET: Global envelopes in R. arXiv:1911.06583 [stat.ME]

See Also

frank.fanova

Examples

#-- NOx levels example (see for details Myllymaki and Mrkvicka, 2020)
if(require("fda.usc", quietly=TRUE)) {
  # Prepare data
  data("poblenou")
  fest <- poblenou$df$day.festive; week <- as.integer(poblenou$df$day.week)
  Type <- vector(length=length(fest))
  Type[fest == 1 | week >= 6] <- "Free"
  Type[fest == 0 & week %in% 1:4] <- "MonThu"
  Type[fest == 0 & week == 5] <- "Fri"
  Type <- factor(Type, levels = c("MonThu", "Fri", "Free"))

  # (log) Data as a curve_set
  cset <- create_curve_set(list(r = 0:23,
             obs = t(log(poblenou[['nox']][['data']]))))
  # Graphical functional ANOVA
  nsim <- 2999
  
  res.c <- graph.fanova(nsim = nsim, curve_set = cset,
                        groups = Type, variances = "unequal",
                        contrasts = TRUE)
  plot(res.c) + ggplot2::labs(x = "Hour", y = "Diff.")
}

#-- Centred government expenditure centralization ratios example
# This is an example analysis of the centred GEC in Mrkvicka et al.
data("cgec")

# Number of simulations
nsim <- 2499 # increase to reduce Monte Carlo error


# Test for unequal lag 1 covariances
res.cov1 <- graph.fanova(nsim = nsim, curve_set = cgec$cgec,
                         groups = cgec$group,
                         test.equality = "cov", cov.lag = 1)
plot(res.cov1)
# Add labels
plot(res.cov1, labels = paste("Group ", 1:3, sep="")) +
  ggplot2::xlab(substitute(paste(italic(i), " (", j, ")", sep=""), list(i="r", j="Year")))
# Test for equality of variances among groups
res.var <- graph.fanova(nsim = nsim, curve_set = cgec$cgec,
                        groups = cgec$group,
                        test.equality = "var")
plot(res.var)

# Test for equality of means assuming equality of variances
# a) using 'means'
res <- graph.fanova(nsim = nsim, curve_set = cgec$cgec,
                    groups = cgec$group,
                    variances = "equal", contrasts = FALSE)
plot(res)
# b) using 'contrasts'
res2 <- graph.fanova(nsim = nsim, curve_set = cgec$cgec,
                     groups = cgec$group,
                     variances = "equal", contrasts = TRUE)
plot(res2)

# Image set examples
data("imageset3")

res <- graph.fanova(nsim = 19, # Increase nsim for serious analysis!
                    curve_set = imageset3$image_set,
                    groups = imageset3$Group)
plot(res)
# Contrasts
res.c <- graph.fanova(nsim = 19, # Increase nsim for serious analysis!
                      curve_set = imageset3$image_set, groups = imageset3$Group,
                      contrasts = TRUE)
plot(res.c)

GET documentation built on Nov. 16, 2022, 5:09 p.m.