# NOT RUN {
#-- NOx levels example (see for details Myllymaki and Mrkvicka, 2019)
if(require("fda.usc", quietly=TRUE)) {
# Prepare data
data(poblenou)
Free <- poblenou$df$day.festive == 1 |
as.integer(poblenou$df$day.week) >= 6
MonThu <- poblenou$df$day.festive == 0 & poblenou$df$day.week %in% 1:4
Friday <- poblenou$df$day.festive == 0 & poblenou$df$day.week == 5
Type <- vector(length=length(Free))
Type[Free] <- "Free"
Type[MonThu] <- "MonThu"
Type[Friday] <- "Fri"
Type <- factor(Type, levels = c("MonThu", "Fri", "Free"))
# }
# NOT RUN {
# Plot of data
if(requireNamespace("ggplot2", quietly=TRUE)) {
df <- do.call(rbind, lapply(1:24, FUN = function(x) {
data.frame(Hour = x, NOx = poblenou[['nox']]$data[,x],
Type = Type, Date = rownames(poblenou[['nox']]$data))
}))
ggplot2::ggplot(df) + ggplot2::geom_line(ggplot2::aes(x = Hour, y = NOx, group = Date)) +
ggplot2::facet_wrap(ggplot2::vars(Type)) + GET:::ThemePlain()
}
# }
# NOT RUN {
# Graphical functional ANOVA
cset <- create_curve_set(list(r=0:23,
obs=t(log(poblenou[['nox']][['data']]))))
# }
# NOT RUN {
res.c <- graph.fanova(nsim = 2999, curve_set = cset,
groups = Type, variances = "unequal",
contrasts = TRUE)
# }
# NOT RUN {
plot(res.c, xlab = "Hour", ylab = "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
# }
# NOT RUN {
nsim <- 2499 # increase to reduce Monte Carlo error
# Test for unequal lag 1 covariances
res.cov1 <- graph.fanova(nsim = nsim, curve_set = cgec,
groups = attr(cgec, "group"),
test.equality = "cov", cov.lag = 1)
plot(res.cov1, ncol=3,
labels = paste("Group ", 1:3, sep=""),
xlab=substitute(paste(i, " (", italic(j), ")", sep=""), list(i="Year", j="r")),
ylab=expression(italic(bar(W)[i](r))))
# Test for equality of variances among groups
res.var <- graph.fanova(nsim = nsim, curve_set = cgec,
groups = attr(cgec, "group"),
test.equality = "var")
plot(res.var, ncol=3,
labels = paste("Group ", 1:3, sep=""),
xlab=substitute(paste(i, " (", italic(j), ")", sep=""), list(i="Year", j="r")),
ylab=expression(italic(bar(Z)[i](r))))
# Test for equality of means assuming equality of variances
# a) using 'means'
res <- graph.fanova(nsim = nsim, curve_set = cgec,
groups = attr(cgec, "group"),
variances = "equal",
contrasts = FALSE)
plot(res, ncol=3,
labels = paste("Group ", 1:3, sep=""),
xlab=substitute(paste(i, " (", italic(j), ")", sep=""), list(i="Year", j="r")),
ylab=expression(italic(bar(T)[i](r))))
# b) using 'contrasts'
res2 <- graph.fanova(nsim = nsim, curve_set = cgec,
groups = attr(cgec, "group"),
variances = "equal",
contrasts = TRUE)
# }
# NOT RUN {
plot(res2, ncol=3,
xlab=substitute(paste(i, " (", italic(j), ")", sep=""), list(i="Year", j="r")),
ylab=expression(italic(bar(T)[i](r)-bar(T)[j](r))))
# }
# NOT RUN {
#-- Rimov water temperatures example
# This is an example analysis of the water temperature data set
# in Mrkvicka et al. (arXiv:1612.03608v2).
data(rimov)
groups <- factor(c(rep(1, times=12), rep(2, times=12), rep(3, times=12)))
nsim <- 999
# Test for equality of variances in the groups
resV <- graph.fanova(nsim=nsim, curve_set=rimov, groups=groups, contrasts = FALSE,
test.equality="var")
plot(resV)
# Test for equality of lag 1 covariances in the groups
resC <- graph.fanova(nsim=nsim, curve_set=rimov, groups=groups, contrasts = FALSE,
test.equality="cov", cov.lag=1)
plot(resC)
# Test the equality of means in the groups (fANOVA), assuming equality of variances
res <- graph.fanova(nsim=nsim, curve_set=rimov, groups=groups, contrasts = FALSE)
plot(res)
res2 <- graph.fanova(nsim=nsim, curve_set=rimov, groups=groups, contrasts = TRUE)
plot(res2)
# }
Run the code above in your browser using DataLab