# NOT RUN {
## Univariate FSSA Example on Callcenter data
require(Rfssa)
load_github_data("https://github.com/haghbinh/Rfssa/blob/master/data/Callcenter.RData")
## Define functional objects
D <- matrix(sqrt(Callcenter$calls), nrow = 240)
N <- ncol(D)
time <- seq(ISOdate(1999, 1, 1), ISOdate(1999, 12, 31), by = "day")
K <- nrow(D)
u <- seq(0, K, length.out = K)
d <- 22 # Optimal Number of basis elements
## Define functional time series
Y <- fts(list(D), list(list(d, "bspline")), list(u))
Y
plot(Y, mains = c("Sqrt of Call Center Data"))
## Univariate functional singular spectrum analysis
L <- 28
U <- fssa(Y, L)
plot(U, d = 13)
plot(U, d = 9, type = "lheats")
plot(U, d = 9, type = "lcurves")
plot(U, d = 9, type = "vectors")
plot(U, d = 10, type = "periodogram")
plot(U, d = 10, type = "paired")
plot(U, d = 10, type = "wcor")
gr <- list(1, 2:3, 4:5, 6:7, 8:20)
Q <- freconstruct(U, gr)
plot(Y, mains = "Sqrt of Call Center Data")
plot(Q[[1]], mains = "1st Component")
plot(Q[[2]], mains = "2nd Component")
plot(Q[[3]], mains = "3rd Component")
plot(Q[[4]], mains = "4th Component")
plot(Q[[5]], mains = "5th Component (Noise)")
## Other visualisation types for object of class "fts":
plot(Q[[1]], type = "3Dsurface", xlabels = "Intraday", tlabels = "Day", zlabels = "Output")
# Visualizing the first 60 observations in the reconstructed fts.
plot(Q[[2]][1:60], type = "heatmap", xlabels = "Intraday intervals")
plot(Q[[3]][1:60], type = "3Dline", xlabels = "Intraday", tlabels = "Day", zlabels = "Output")
## Multivariate FSSA Example on bivariate intraday
## temperature curves and smoothed images of vegetation
require(Rfssa)
load_github_data("https://github.com/haghbinh/Rfssa/blob/master/data/Montana.RData")
Temp <- Montana$Temp
NDVI <- Montana$NDVI
d_temp <- 11
d_NDVI <- 13
## Define functional time series
Y <- fts(
list(Temp / sd(Temp), NDVI), list(
list(d_temp, "bspline"),
list(d_NDVI, d_NDVI, "bspline", "bspline")
),
list(c(0, 23), list(c(1, 33), c(1, 33)))
)
# Plot the first 100 observations
plot(Y[1:100],
xlabels = c("Time", "Lon."), ylabels = c("Temperature (\u00B0C)", "Lat."),
zlabels = c("", "NDVI"), mains = c("Temperature Curves", "NDVI Images")
)
plot(Y, types = c("3Dline", "heatmap"), vars = c(1, 1))
plot(Y, types = "heatmap", vars = 2)
plot(Y, vars = c(2, 1))
L <- 45
## Multivariate functional singular spectrum analysis
U <- fssa(Y, L)
plot(U, type = "values", d = 10)
plot(U, type = "vectors", d = 4)
plot(U, type = "lheats", d = 4)
plot(U, type = "lcurves", d = 4, vars = c(1))
plot(U, type = "paired", d = 6)
plot(U, type = "wcor", d = 10)
plot(U, type = "periodogram", d = 4)
# Reconstruction of multivariate fts observed over different dimensional domains
Q <- freconstruct(U = U, groups = list(c(1), c(2:3), c(4)))
# Plotting reconstructions to show accuracy
plot(Q[[1]]) # mean
plot(Q[[2]]) # periodic
plot(Q[[3]]) # trend
# }
Run the code above in your browser using DataLab