Title: | Autocorrelation Function for Functional Time Series |
---|---|
Description: | Quantify the serial correlation across lags of a given functional time series using the autocorrelation function and a partial autocorrelation function for functional time series proposed in Mestre et al. (2021) <doi:10.1016/j.csda.2020.107108>. The autocorrelation functions are based on the L2 norm of the lagged covariance operators of the series. Functions are available for estimating the distribution of the autocorrelation functions under the assumption of strong functional white noise. |
Authors: | Guillermo Mestre Marcos [aut, cre], José Portela González [aut], Gregory Rice [aut], Antonio Muñoz San Roque [ctb], Estrella Alonso Pérez [ctb] |
Maintainer: | Guillermo Mestre Marcos <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.0 |
Built: | 2024-11-01 03:26:23 UTC |
Source: | https://github.com/gmestrem/fdaacf |
A dataset containing the hourly electricity prices for Spain in the Day-Ahead Market (MIBEL)
elec_prices
elec_prices
A data frame with 365 rows and 24 variables:
Electricity price for hour 1
Electricity price for hour 2
Electricity price for hour 3
Electricity price for hour 4
Electricity price for hour 5
Electricity price for hour 6
Electricity price for hour 7
Electricity price for hour 8
Electricity price for hour 9
Electricity price for hour 10
Electricity price for hour 11
Electricity price for hour 12
Electricity price for hour 13
Electricity price for hour 14
Electricity price for hour 15
Electricity price for hour 16
Electricity price for hour 17
Electricity price for hour 18
Electricity price for hour 19
Electricity price for hour 20
Electricity price for hour 21
Electricity price for hour 22
Electricity price for hour 23
Electricity price for hour 24
https://www.esios.ree.es/es/analisis/600
Estimate the distribution of the autocorrelation function under the hypothesis of strong functional white noise. This function uses Imhof's method to estimate the distribution.
estimate_iid_distr_Imhof(Y, v, autocovSurface, matindex, figure = FALSE, ...)
estimate_iid_distr_Imhof(Y, v, autocovSurface, matindex, figure = FALSE, ...)
Y |
Matrix containing the discretized values
of the functional time series. The dimension of the
matrix is |
v |
Discretization points of the curves, by default
|
autocovSurface |
An |
matindex |
A vector containing the L2 norm of
the autocovariance function. It can be obtained by calling
function |
figure |
Logical. If |
... |
Further arguments passed to the |
Return a list with:
ex
: Knots where the
distribution has been estimated
ef
: Discretized values of
the estimated distribution.
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 1 autocovSurface <- obtain_autocovariance(Y,nlags) matindex <- obtain_suface_L2_norm (v,autocovSurface) # Remove lag 0 matindex <- matindex[-1] Imhof_dist <- estimate_iid_distr_Imhof(Y,v,autocovSurface,matindex) plot(Imhof_dist$ex,Imhof_dist$ef,type = "l",main = "ecdf obtained by Imhof's method") grid() # Example 2 N <- 400 v <- seq(from = 0, to = 1, length.out = 50) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) autocovSurface <- obtain_autocovariance(Y,nlags) matindex <- obtain_suface_L2_norm (v,autocovSurface) # Remove lag 0 matindex <- matindex[-1] Imhof_dist <- estimate_iid_distr_Imhof(Y,v,autocovSurface,matindex) plot(Imhof_dist$ex,Imhof_dist$ef,type = "l",main = "ecdf obtained by Imhof's method") grid()
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 1 autocovSurface <- obtain_autocovariance(Y,nlags) matindex <- obtain_suface_L2_norm (v,autocovSurface) # Remove lag 0 matindex <- matindex[-1] Imhof_dist <- estimate_iid_distr_Imhof(Y,v,autocovSurface,matindex) plot(Imhof_dist$ex,Imhof_dist$ef,type = "l",main = "ecdf obtained by Imhof's method") grid() # Example 2 N <- 400 v <- seq(from = 0, to = 1, length.out = 50) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) autocovSurface <- obtain_autocovariance(Y,nlags) matindex <- obtain_suface_L2_norm (v,autocovSurface) # Remove lag 0 matindex <- matindex[-1] Imhof_dist <- estimate_iid_distr_Imhof(Y,v,autocovSurface,matindex) plot(Imhof_dist$ex,Imhof_dist$ef,type = "l",main = "ecdf obtained by Imhof's method") grid()
Estimate the distribution of the autocorrelation function under the hypothesis of strong functional white noise. This function uses Montecarlo's method to estimate the distribution.
estimate_iid_distr_MC(Y, v, autocovSurface, matindex, nsimul = 10000, figure = FALSE, ...)
estimate_iid_distr_MC(Y, v, autocovSurface, matindex, nsimul = 10000, figure = FALSE, ...)
Y |
Matrix containing the discretized values
of the functional time series. The dimension of the
matrix is |
v |
Discretization points of the curves, by default
|
autocovSurface |
An |
matindex |
A vector containing the L2 norm of
the autocovariance function. It can be obtained by calling
function |
nsimul |
Positive integer indicating the number of
MC simulations that will be used to estimate the distribution
of the statistic. Increasing the number of simulations will
improve the estimation, but it will increase the computational
time.
By default, |
figure |
Logical. If |
... |
Further arguments passed to the |
Return a list with:
ex
: Knots where the
distribution has been estimated
ef
: Discretized values of
the estimated distribution.
Reig
: Raw values of the i.i.d.
statistic for each MC simulation.
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 1 autocovSurface <- obtain_autocovariance(Y,nlags) matindex <- obtain_suface_L2_norm (v,autocovSurface) # Remove lag 0 matindex <- matindex[-1] MC_dist <- estimate_iid_distr_MC(Y,v,autocovSurface,matindex) plot(MC_dist$ex,MC_dist$ef,type = "l",main = "ecdf obtained by MC simulation") grid() # Example 2 N <- 400 v <- seq(from = 0, to = 1, length.out = 50) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 20 autocovSurface <- obtain_autocovariance(Y,nlags) matindex <- obtain_suface_L2_norm (v,autocovSurface) # Remove lag 0 matindex <- matindex[-1] MC_dist <- estimate_iid_distr_MC(Y,v,autocovSurface,matindex) plot(MC_dist$ex,MC_dist$ef,type = "l",main = "ecdf obtained by MC simulation") grid()
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 1 autocovSurface <- obtain_autocovariance(Y,nlags) matindex <- obtain_suface_L2_norm (v,autocovSurface) # Remove lag 0 matindex <- matindex[-1] MC_dist <- estimate_iid_distr_MC(Y,v,autocovSurface,matindex) plot(MC_dist$ex,MC_dist$ef,type = "l",main = "ecdf obtained by MC simulation") grid() # Example 2 N <- 400 v <- seq(from = 0, to = 1, length.out = 50) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 20 autocovSurface <- obtain_autocovariance(Y,nlags) matindex <- obtain_suface_L2_norm (v,autocovSurface) # Remove lag 0 matindex <- matindex[-1] MC_dist <- estimate_iid_distr_MC(Y,v,autocovSurface,matindex) plot(MC_dist$ex,MC_dist$ef,type = "l",main = "ecdf obtained by MC simulation") grid()
The fdaACF package provides diagnostic and analysis tools to quantify the serial autocorrelation across lags of a given functional time series in order to improve the identification and diagnosis of functional ARIMA models. The autocorrelation function is based on the L2 norm of the lagged covariance operators of the series. Several real-world datasets are included to illustrate the application of these techniques.
Fit an model to a given functional
time series. The fitted model is based on the model proposed
in (Aue et al, 2015), first decomposing the original
functional observations into a vector time series of
n_harm
FPCA scores, and then fitting a vector autoregressive
model of order (
) to the time series
of the scores. Once fitted, the Karhunen-Loève expansion
is used to re-transform the fitted values into functional
observations.
fit_ARHp_FPCA(y, v, p, n_harm, show_varprop = T)
fit_ARHp_FPCA(y, v, p, n_harm, show_varprop = T)
y |
Matrix containing the discretized values
of the functional time series. The dimension of the
matrix is |
v |
Numeric vector that contains the discretization points of the curves. |
p |
Numeric value specifying the order of the functional autoregressive model to be fitted. |
n_harm |
Numeric value specifying the number
of functional principal components to be used when fitting
the |
show_varprop |
Logical. If |
Aue, A., Norinho, D. D., Hormann, S. (2015). On the Prediction of Stationary Functional Time Series Journal of the American Statistical Association, 110, 378–392. https://doi.org/10.1080/01621459.2014.909317
# Example 1 # Simulate an ARH(1) process N <- 250 dv <- 20 v <- seq(from = 0, to = 1, length.out = 20) phi <- 1.3 * ((v) %*% t(v)) persp(v,v,phi, ticktype = "detailed", main = "Integral operator") set.seed(3) white_noise <- simulate_iid_brownian_bridge(N, v = v) y <- matrix(nrow = N, ncol = dv) y[1,] <- white_noise[1,] for(jj in 2:N){ y[jj,] <- white_noise[jj,]; y[jj,]=y[jj,]+integral_operator(operator_kernel = phi, v = v, curve = y[jj-1,]) } # Fit an ARH(1) model mod <- fit_ARHp_FPCA(y = y, v = v, p = 1, n_harm = 5) # Plot results plot(v, y[50,], type = "l", lty = 1, ylab = "") lines(v, mod$y_est[50,], col = "red") legend("bottomleft", legend = c("real","est"), lty = 1, col = c(1,2))
# Example 1 # Simulate an ARH(1) process N <- 250 dv <- 20 v <- seq(from = 0, to = 1, length.out = 20) phi <- 1.3 * ((v) %*% t(v)) persp(v,v,phi, ticktype = "detailed", main = "Integral operator") set.seed(3) white_noise <- simulate_iid_brownian_bridge(N, v = v) y <- matrix(nrow = N, ncol = dv) y[1,] <- white_noise[1,] for(jj in 2:N){ y[jj,] <- white_noise[jj,]; y[jj,]=y[jj,]+integral_operator(operator_kernel = phi, v = v, curve = y[jj-1,]) } # Fit an ARH(1) model mod <- fit_ARHp_FPCA(y = y, v = v, p = 1, n_harm = 5) # Plot results plot(v, y[50,], type = "l", lty = 1, ylab = "") lines(v, mod$y_est[50,], col = "red") legend("bottomleft", legend = c("real","est"), lty = 1, col = c(1,2))
Estimate both the autocorrelation and partial autocorrelation function for a given functional time series and its distribution under the hypothesis of strong functional white noise. Both correlograms are plotted to ease the identification of the dependence structure of the functional time series.
FTS_identification(Y, v, nlags, n_harm = NULL, ci = 0.95, estimation = "MC", figure = TRUE, ...)
FTS_identification(Y, v, nlags, n_harm = NULL, ci = 0.95, estimation = "MC", figure = TRUE, ...)
Y |
Matrix containing the discretized values
of the functional time series. The dimension of the
matrix is |
v |
Discretization points of the curves. |
nlags |
Number of lagged covariance operators of the functional time series that will be used to estimate the autocorrelation functions. |
n_harm |
Number of principal components
that will be used to fit the ARH(p) models. If
this value is not supplied, |
ci |
A value between 0 and 1 that indicates
the confidence interval for the i.i.d. bounds
of the partial autocorrelation function. By default
|
estimation |
Character specifying the method to be used when estimating the distribution under the hypothesis of functional white noise. Accepted values are:
By default, |
figure |
Logical. If |
... |
Further arguments passed to the |
Return a list with:
Blueline
: The upper prediction
bound for the i.i.d. distribution.
rho_FACF
: Autocorrelation
coefficients for
each lag of the functional time series.
rho_FPACF
: Partial autocorrelation
coefficients for
each lag of the functional time series.
Mestre G., Portela J., Rice G., Muñoz San Roque A., Alonso E. (2021). Functional time series model identification and diagnosis by means of auto- and partial autocorrelation analysis. Computational Statistics & Data Analysis, 155, 107108. https://doi.org/10.1016/j.csda.2020.107108
Mestre, G., Portela, J., Muñoz-San Roque, A., Alonso, E. (2020). Forecasting hourly supply curves in the Italian Day-Ahead electricity market with a double-seasonal SARMAHX model. International Journal of Electrical Power & Energy Systems, 121, 106083. https://doi.org/10.1016/j.ijepes.2020.106083
Kokoszka, P., Rice, G., Shang, H.L. (2017). Inference for the autocovariance of a functional time series under conditional heteroscedasticity Journal of Multivariate Analysis, 162, 32–50. https://doi.org/10.1016/j.jmva.2017.08.004
# Example 1 (Toy example) N <- 50 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 set.seed(15) Y <- simulate_iid_brownian_bridge(N, v, sig) FTS_identification(Y,v,3) # Example 2 data(elec_prices) v <- seq(from = 1, to = 24) nlags <- 30 FTS_identification(Y = as.matrix(elec_prices), v = v, nlags = nlags, ci = 0.95, figure = TRUE)
# Example 1 (Toy example) N <- 50 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 set.seed(15) Y <- simulate_iid_brownian_bridge(N, v, sig) FTS_identification(Y,v,3) # Example 2 data(elec_prices) v <- seq(from = 1, to = 24) nlags <- 30 FTS_identification(Y = as.matrix(elec_prices), v = v, nlags = nlags, ci = 0.95, figure = TRUE)
Compute the integral transform of the
curve with respect to a given integral
operator
. The transformation is given by
integral_operator(operator_kernel, curve, v)
integral_operator(operator_kernel, curve, v)
operator_kernel |
Matrix with the values
of the kernel surface of the integral operator.
The dimension of the matrix is |
curve |
Vector containing the discretized values
of a functional observation. The dimension of the
matrix is |
v |
Numerical vector specifying the discretization points of the curves. |
Returns a matrix the same size as
curve
with the transformed values.
# Example 1 v <- seq(from = 0, to = 1, length.out = 20) set.seed(10) curve <- sin(v) + rnorm(length(v)) operator_kernel <- 0.6*(v %*% t(v)) hat_curve <- integral_operator(operator_kernel,curve,v)
# Example 1 v <- seq(from = 0, to = 1, length.out = 20) set.seed(10) curve <- sin(v) + rnorm(length(v)) operator_kernel <- 0.6*(v %*% t(v)) hat_curve <- integral_operator(operator_kernel,curve,v)
This function returns a fd
object
obtained from the discretized functional observations
contained in mat_obj
.
It is assumed that the functional observations
contained in mat_obj
are real observations,
hence a poligonal base will be used to obtain
the functional object.
mat2fd(mat_obj, range_val = c(0, 1), argvals = NULL)
mat2fd(mat_obj, range_val = c(0, 1), argvals = NULL)
mat_obj |
A matrix that contains the discretized functional observations. |
range_val |
A numeric vector of length 2
that contains the range of the observed functional
data. By default |
argvals |
Optinal argument that contains
a strictly increasing vector
of argument values at which line segments join
to form a polygonal line. If |
A fd object obtained from the functional
observations in mat_obj
.
# Example 1 N <- 100 dv <- 30 v <- seq(from = 0, to = 1, length.out = dv) set.seed(150) # For replication mat_func_obs <- matrix(rnorm(N*dv), nrow = N, ncol = dv) fd_func_obs <- mat2fd(mat_obj = mat_func_obs, range_val = range(v), argvals = v) plot(fd_func_obs)
# Example 1 N <- 100 dv <- 30 v <- seq(from = 0, to = 1, length.out = dv) set.seed(150) # For replication mat_func_obs <- matrix(rnorm(N*dv), nrow = N, ncol = dv) fd_func_obs <- mat2fd(mat_obj = mat_func_obs, range_val = range(v), argvals = v) plot(fd_func_obs)
Obtain the empirical autocorrelation function for
lags nlags
of the functional time
series. Given a functional time
series, the sample autocovariance functions
are given by:
where
denotes the sample mean function. By normalizing these
functions using the normalizing factor
, the range of the
autocovariance functions becomes
; thus
defining the autocorrelation functions of the series
obtain_autocorrelation(Y, v = seq(from = 0, to = 1, length.out = ncol(Y)), nlags)
obtain_autocorrelation(Y, v = seq(from = 0, to = 1, length.out = ncol(Y)), nlags)
Y |
Matrix containing the discretized values
of the functional time series. The dimension of the
matrix is |
v |
Discretization points of the curves, by default
|
nlags |
Number of lagged covariance operators of the functional time series that will be used to estimate the autocorrelation function. |
Return a list with the lagged autocorrelation
functions estimated from the data. Each function is given
by a matrix, where
is the
number of points observed in each curve.
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 1 lagged_autocor <- obtain_autocorrelation(Y = bbridge, nlags = nlags) image(x = v, y = v, z = lagged_autocor$Lag0) # Example 2 require(fields) N <- 500 v <- seq(from = 0, to = 1, length.out = 50) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 4 lagged_autocov <- obtain_autocovariance(Y = bbridge, nlags = nlags) lagged_autocor <- obtain_autocorrelation(Y = bbridge, v = v, nlags = nlags) opar <- par(no.readonly = TRUE) par(mfrow = c(1,2)) z_lims <- range(lagged_autocov$Lag1) colors <- heat.colors(12) image.plot(x = v, y = v, z = lagged_autocov$Lag1, legend.width = 2, zlim = z_lims, col = colors, xlab = "u", ylab = "v", main = "Autocovariance") z_lims <- range(lagged_autocor$Lag1) image.plot(x = v, y = v, z = lagged_autocor$Lag1, legend.width = 2, zlim = z_lims, col = colors, xlab = "u", ylab = "v", main = "Autocorrelation") par(opar)
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 1 lagged_autocor <- obtain_autocorrelation(Y = bbridge, nlags = nlags) image(x = v, y = v, z = lagged_autocor$Lag0) # Example 2 require(fields) N <- 500 v <- seq(from = 0, to = 1, length.out = 50) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 4 lagged_autocov <- obtain_autocovariance(Y = bbridge, nlags = nlags) lagged_autocor <- obtain_autocorrelation(Y = bbridge, v = v, nlags = nlags) opar <- par(no.readonly = TRUE) par(mfrow = c(1,2)) z_lims <- range(lagged_autocov$Lag1) colors <- heat.colors(12) image.plot(x = v, y = v, z = lagged_autocov$Lag1, legend.width = 2, zlim = z_lims, col = colors, xlab = "u", ylab = "v", main = "Autocovariance") z_lims <- range(lagged_autocor$Lag1) image.plot(x = v, y = v, z = lagged_autocor$Lag1, legend.width = 2, zlim = z_lims, col = colors, xlab = "u", ylab = "v", main = "Autocorrelation") par(opar)
Estimate the eigenvalues of the sample autocovariance
function . This functions returns the
eigenvalues which are greater than the value
epsilon
.
obtain_autocov_eigenvalues(v, Y, epsilon = 1e-04)
obtain_autocov_eigenvalues(v, Y, epsilon = 1e-04)
v |
Discretization points of the curves, by default
|
Y |
Matrix containing the discretized values
of the functional time series. The dimension of the
matrix is |
epsilon |
Value used to determine how many
eigenvalues will be returned. The eigenvalues
|
A vector containing the eigenvalues
greater than
epsilon
.
N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) lambda <- obtain_autocov_eigenvalues(v = v, Y = Y)
N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) lambda <- obtain_autocov_eigenvalues(v = v, Y = Y)
Obtain the empirical autocovariance function for
lags nlags
of the functional time
series. Given a functional time
series, the sample autocovariance functions
are given by:
where
denotes the sample mean function.
obtain_autocovariance(Y, nlags)
obtain_autocovariance(Y, nlags)
Y |
Matrix containing the discretized values
of the functional time series. The dimension of the
matrix is |
nlags |
Number of lagged covariance operators of the functional time series that will be used to estimate the autocorrelation function. |
Return a list with the lagged autocovariance
functions estimated from the data. Each function is given
by a matrix, where
is the
number of points observed in each curve.
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 1 lagged_autocov <- obtain_autocovariance(Y = bbridge, nlags = nlags) image(x = v, y = v, z = lagged_autocov$Lag0) # Example 2 N <- 500 v <- seq(from = 0, to = 1, length.out = 50) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 10 lagged_autocov <- obtain_autocovariance(Y = bbridge, nlags = nlags) image(x = v, y = v, z = lagged_autocov$Lag0) image(x = v, y = v, z = lagged_autocov$Lag10) # Example 3 require(fields) N <- 500 v <- seq(from = 0, to = 1, length.out = 50) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 4 lagged_autocov <- obtain_autocovariance(Y = bbridge, nlags = nlags) z_lims <- range(lagged_autocov$Lag0) colors <- heat.colors(12) opar <- par(no.readonly = TRUE) par(mfrow = c(1,5)) par(oma=c( 0,0,0,6)) for(k in 0:nlags){ image(x=v, y=v, z = lagged_autocov[[paste0("Lag",k)]], main = paste("Lag",k), col = colors, xlab = "u", ylab = "v") } par(oma=c( 0,0,0,2.5)) # reset margin to be much smaller. image.plot( legend.only=TRUE, legend.width = 2,zlim=z_lims, col = colors) par(opar)
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 1 lagged_autocov <- obtain_autocovariance(Y = bbridge, nlags = nlags) image(x = v, y = v, z = lagged_autocov$Lag0) # Example 2 N <- 500 v <- seq(from = 0, to = 1, length.out = 50) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 10 lagged_autocov <- obtain_autocovariance(Y = bbridge, nlags = nlags) image(x = v, y = v, z = lagged_autocov$Lag0) image(x = v, y = v, z = lagged_autocov$Lag10) # Example 3 require(fields) N <- 500 v <- seq(from = 0, to = 1, length.out = 50) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 4 lagged_autocov <- obtain_autocovariance(Y = bbridge, nlags = nlags) z_lims <- range(lagged_autocov$Lag0) colors <- heat.colors(12) opar <- par(no.readonly = TRUE) par(mfrow = c(1,5)) par(oma=c( 0,0,0,6)) for(k in 0:nlags){ image(x=v, y=v, z = lagged_autocov[[paste0("Lag",k)]], main = paste("Lag",k), col = colors, xlab = "u", ylab = "v") } par(oma=c( 0,0,0,2.5)) # reset margin to be much smaller. image.plot( legend.only=TRUE, legend.width = 2,zlim=z_lims, col = colors) par(opar)
Estimate the lagged autocorrelation function for a given functional time series and its distribution under the hypothesis of strong functional white noise. This graphic tool can be used to identify seasonal patterns in the functional data as well as auto-regressive or moving average terms. i.i.d. bounds are included to test the presence of serial correlation in the data.
obtain_FACF(Y, v, nlags, ci = 0.95, estimation = "MC", figure = TRUE, ...)
obtain_FACF(Y, v, nlags, ci = 0.95, estimation = "MC", figure = TRUE, ...)
Y |
Matrix containing the discretized values
of the functional time series. The dimension of the
matrix is |
v |
Discretization points of the curves, by default
|
nlags |
Number of lagged covariance operators of the functional time series that will be used to estimate the autocorrelation function. |
ci |
A value between 0 and 1 that indicates
the confidence interval for the i.i.d. bounds
of the autocorrelation function. By default
|
estimation |
Character specifying the method to be used when estimating the distribution under the hypothesis of functional white noise. Accepted values are:
By default, |
figure |
Logical. If |
... |
Further arguments passed to the |
Return a list with:
Blueline
: The upper prediction
bound for the i.i.d. distribution.
rho
: Autocorrelation values for
each lag of the functional time series.
Mestre G., Portela J., Rice G., Muñoz San Roque A., Alonso E. (2021). Functional time series model identification and diagnosis by means of auto- and partial autocorrelation analysis. Computational Statistics & Data Analysis, 155, 107108. https://doi.org/10.1016/j.csda.2020.107108
Mestre, G., Portela, J., Muñoz-San Roque, A., Alonso, E. (2020). Forecasting hourly supply curves in the Italian Day-Ahead electricity market with a double-seasonal SARMAHX model. International Journal of Electrical Power & Energy Systems, 121, 106083. https://doi.org/10.1016/j.ijepes.2020.106083
Kokoszka, P., Rice, G., Shang, H.L. (2017). Inference for the autocovariance of a functional time series under conditional heteroscedasticity Journal of Multivariate Analysis, 162, 32–50. https://doi.org/10.1016/j.jmva.2017.08.004
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 5) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) obtain_FACF(Y,v,20) # Example 2 data(elec_prices) v <- seq(from = 1, to = 24) nlags <- 30 obtain_FACF(Y = as.matrix(elec_prices), v = v, nlags = nlags, ci = 0.95, figure = TRUE)
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 5) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) obtain_FACF(Y,v,20) # Example 2 data(elec_prices) v <- seq(from = 1, to = 24) nlags <- 30 obtain_FACF(Y = as.matrix(elec_prices), v = v, nlags = nlags, ci = 0.95, figure = TRUE)
Estimate the partial autocorrelation function for a given functional time series and its distribution under the hypothesis of strong functional white noise.
obtain_FPACF(Y, v, nlags, n_harm, ci = 0.95, estimation = "MC", figure = TRUE, ...)
obtain_FPACF(Y, v, nlags, n_harm, ci = 0.95, estimation = "MC", figure = TRUE, ...)
Y |
Matrix containing the discretized values
of the functional time series. The dimension of the
matrix is |
v |
Discretization points of the curves. |
nlags |
Number of lagged covariance operators of the functional time series that will be used to estimate the partial autocorrelation function. |
n_harm |
Number of principal components that will be used to fit the ARH(p) models. |
ci |
A value between 0 and 1 that indicates
the confidence interval for the i.i.d. bounds
of the partial autocorrelation function. By default
|
estimation |
Character specifying the method to be used when estimating the distribution under the hypothesis of functional white noise. Accepted values are:
By default, |
figure |
Logical. If |
... |
Further arguments passed to the |
Return a list with:
Blueline
: The upper prediction
bound for the i.i.d. distribution.
rho
: Partial autocorrelation
coefficients for
each lag of the functional time series.
Mestre G., Portela J., Rice G., Muñoz San Roque A., Alonso E. (2021). Functional time series model identification and diagnosis by means of auto- and partial autocorrelation analysis. Computational Statistics & Data Analysis, 155, 107108. https://doi.org/10.1016/j.csda.2020.107108
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 5) sig <- 2 set.seed(15) Y <- simulate_iid_brownian_bridge(N, v, sig) obtain_FPACF(Y,v,10, n_harm = 2) # Example 2 data(elec_prices) v <- seq(from = 1, to = 24) nlags <- 30 obtain_FPACF(Y = as.matrix(elec_prices), v = v, nlags = nlags, n_harm = 5, ci = 0.95, figure = TRUE)
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 5) sig <- 2 set.seed(15) Y <- simulate_iid_brownian_bridge(N, v, sig) obtain_FPACF(Y,v,10, n_harm = 2) # Example 2 data(elec_prices) v <- seq(from = 1, to = 24) nlags <- 30 obtain_FPACF(Y = as.matrix(elec_prices), v = v, nlags = nlags, n_harm = 5, ci = 0.95, figure = TRUE)
Returns the L2 norm of the lagged autocovariance
functions . The L2 norm of these
functions is defined as
obtain_suface_L2_norm(v, autocovSurface)
obtain_suface_L2_norm(v, autocovSurface)
v |
Discretization points of the curves, by default
|
autocovSurface |
An |
A vector containing the L2 norm of the
lagged autocovariance functions autocovSurface
.
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 1 autocovSurface <- obtain_autocovariance(Y=Y,nlags = nlags) norms <- obtain_suface_L2_norm(v = v,autocovSurface = autocovSurface) plot_autocovariance(fun.autocovariance = autocovSurface,lag = 1) title(sub = paste0("Lag ",1," - L2 Norm: ",norms[2])) # Example 2 N <- 400 v <- seq(from = 0, to = 1, length.out = 50) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 2 autocovSurface <- obtain_autocovariance(Y=Y,nlags = nlags) norms <- obtain_suface_L2_norm(v = v,autocovSurface = autocovSurface) opar <- par(no.readonly = TRUE) par(mfrow = c(1,3)) plot_autocovariance(fun.autocovariance = autocovSurface,lag = 0) title(sub = paste0("Lag ",0," - L2 Norm: ",norms[1])) plot_autocovariance(fun.autocovariance = autocovSurface,lag = 1) title(sub = paste0("Lag ",1," - L2 Norm: ",norms[2])) plot_autocovariance(fun.autocovariance = autocovSurface,lag = 2) title(sub = paste0("Lag ",2," - L2 Norm: ",norms[3])) par(opar)
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 1 autocovSurface <- obtain_autocovariance(Y=Y,nlags = nlags) norms <- obtain_suface_L2_norm(v = v,autocovSurface = autocovSurface) plot_autocovariance(fun.autocovariance = autocovSurface,lag = 1) title(sub = paste0("Lag ",1," - L2 Norm: ",norms[2])) # Example 2 N <- 400 v <- seq(from = 0, to = 1, length.out = 50) sig <- 2 Y <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 2 autocovSurface <- obtain_autocovariance(Y=Y,nlags = nlags) norms <- obtain_suface_L2_norm(v = v,autocovSurface = autocovSurface) opar <- par(no.readonly = TRUE) par(mfrow = c(1,3)) plot_autocovariance(fun.autocovariance = autocovSurface,lag = 0) title(sub = paste0("Lag ",0," - L2 Norm: ",norms[1])) plot_autocovariance(fun.autocovariance = autocovSurface,lag = 1) title(sub = paste0("Lag ",1," - L2 Norm: ",norms[2])) plot_autocovariance(fun.autocovariance = autocovSurface,lag = 2) title(sub = paste0("Lag ",2," - L2 Norm: ",norms[3])) par(opar)
Obtain a 3D plot of the autocovariance surfaces of a given functional time series. This visualization is useful to detect any kind of dependency between the discretization points of the series.
plot_autocovariance(fun.autocovariance, lag = 0, ...)
plot_autocovariance(fun.autocovariance, lag = 0, ...)
fun.autocovariance |
A list obtained by
calling the function |
lag |
An integer between 0 and |
... |
Further arguments passed to the |
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 1 lagged_autocov <- obtain_autocovariance(Y = bbridge,nlags = nlags) plot_autocovariance(lagged_autocov,1) # Example 2 N <- 500 v <- seq(from = 0, to = 1, length.out = 50) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 4 lagged_autocov <- obtain_autocovariance(Y = bbridge,nlags = nlags) opar <- par(no.readonly = TRUE) par(mfrow = c(1,5)) for(k in 0:nlags){ plot_autocovariance(lagged_autocov,k) } par(opar)
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 1 lagged_autocov <- obtain_autocovariance(Y = bbridge,nlags = nlags) plot_autocovariance(lagged_autocov,1) # Example 2 N <- 500 v <- seq(from = 0, to = 1, length.out = 50) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 4 lagged_autocov <- obtain_autocovariance(Y = bbridge,nlags = nlags) opar <- par(no.readonly = TRUE) par(mfrow = c(1,5)) for(k in 0:nlags){ plot_autocovariance(lagged_autocov,k) } par(opar)
Plot a visual representation of the autocorrelation function of a given functional time series, including the upper i.i.d. bound.
plot_FACF(rho, Blueline, ci, ...)
plot_FACF(rho, Blueline, ci, ...)
rho |
Autocorrelation values for each lag of
the functional time series obtained by calling the
function |
Blueline |
The upper prediction bound for the
i.i.d. distribution obtained by calling the
function |
ci |
Value between 0 and 1 that was used
when calling the function |
... |
Further arguments passed to the |
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 15 upper_bound <- 0.95 fACF <- obtain_FACF(Y = bbridge,v = v,nlags = nlags,ci=upper_bound,figure = FALSE) plot_FACF(rho = fACF$rho,Blueline = fACF$Blueline,ci = upper_bound) # Example 2 N <- 200 v <- seq(from = 0, to = 1, length.out = 30) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 15 upper_bound <- 0.95 fACF <- obtain_FACF(Y = bbridge,v = v,nlags = nlags,ci=upper_bound,figure = FALSE) plot_FACF(rho = fACF$rho,Blueline = fACF$Blueline,ci = upper_bound)
# Example 1 N <- 100 v <- seq(from = 0, to = 1, length.out = 10) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 15 upper_bound <- 0.95 fACF <- obtain_FACF(Y = bbridge,v = v,nlags = nlags,ci=upper_bound,figure = FALSE) plot_FACF(rho = fACF$rho,Blueline = fACF$Blueline,ci = upper_bound) # Example 2 N <- 200 v <- seq(from = 0, to = 1, length.out = 30) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) nlags <- 15 upper_bound <- 0.95 fACF <- obtain_FACF(Y = bbridge,v = v,nlags = nlags,ci=upper_bound,figure = FALSE) plot_FACF(rho = fACF$rho,Blueline = fACF$Blueline,ci = upper_bound)
This function reconstructs the functional curves from a score vector using the basis obtained after applying functional PCA. This allows the user to draw estimations from the joint density of the FPCA scores and reconstruct the curves for those new scores.
reconstruct_fd_from_PCA(pca_struct, scores, centerfns = T)
reconstruct_fd_from_PCA(pca_struct, scores, centerfns = T)
pca_struct |
List obtained after calling
function |
scores |
Numerical vector that contains the scores of the fPCA decomposition for one functional observation. |
centerfns |
Logical value specifying
wheter the FPCA performed used |
Returns a object of type fd
that contains the reconstructed curve.
# Example 1 # Simulate fd nobs <- 200 dv <- 10 basis<-fda::create.bspline.basis(rangeval=c(0,1),nbasis=10) set.seed(5) C <- matrix(rnorm(nobs*dv), ncol = dv, nrow = nobs) fd_sim <- fda::fd(coef=t(C),basis) # Perform FPCA pca_struct <- fda::pca.fd(fd_sim,nharm = 6) # Reconstruct first curve fd_rec <- reconstruct_fd_from_PCA(pca_struct = pca_struct, scores = pca_struct$scores[1,]) plot(fd_sim[1]) plot(fd_rec, add = TRUE, col = "red") legend("topright", legend = c("Real Curve", "PCA Reconstructed"), col = c("black","red"), lty = 1) # Example 2 (Perfect reconstruction) # Simulate fd nobs <- 200 dv <- 7 basis<-fda::create.bspline.basis(rangeval=c(0,1),nbasis=dv) set.seed(5) C <- matrix(rnorm(nobs*dv), ncol = dv, nrow = nobs) fd_sim <- fda::fd(coef=t(C),basis) # Perform FPCA pca_struct <- fda::pca.fd(fd_sim,nharm = dv) # Reconstruct first curve fd_rec <- reconstruct_fd_from_PCA(pca_struct = pca_struct, scores = pca_struct$scores[1,]) plot(fd_sim[1]) plot(fd_rec, add = TRUE, col = "red") legend("topright", legend = c("Real Curve", "PCA Reconstructed"), col = c("black","red"), lty = 1)
# Example 1 # Simulate fd nobs <- 200 dv <- 10 basis<-fda::create.bspline.basis(rangeval=c(0,1),nbasis=10) set.seed(5) C <- matrix(rnorm(nobs*dv), ncol = dv, nrow = nobs) fd_sim <- fda::fd(coef=t(C),basis) # Perform FPCA pca_struct <- fda::pca.fd(fd_sim,nharm = 6) # Reconstruct first curve fd_rec <- reconstruct_fd_from_PCA(pca_struct = pca_struct, scores = pca_struct$scores[1,]) plot(fd_sim[1]) plot(fd_rec, add = TRUE, col = "red") legend("topright", legend = c("Real Curve", "PCA Reconstructed"), col = c("black","red"), lty = 1) # Example 2 (Perfect reconstruction) # Simulate fd nobs <- 200 dv <- 7 basis<-fda::create.bspline.basis(rangeval=c(0,1),nbasis=dv) set.seed(5) C <- matrix(rnorm(nobs*dv), ncol = dv, nrow = nobs) fd_sim <- fda::fd(coef=t(C),basis) # Perform FPCA pca_struct <- fda::pca.fd(fd_sim,nharm = dv) # Reconstruct first curve fd_rec <- reconstruct_fd_from_PCA(pca_struct = pca_struct, scores = pca_struct$scores[1,]) plot(fd_sim[1]) plot(fd_rec, add = TRUE, col = "red") legend("topright", legend = c("Real Curve", "PCA Reconstructed"), col = c("black","red"), lty = 1)
Generate a functional time series from a Brownian Bridge process.
If is a Wiener process, the Brownian Bridge is
defined as
.
Each functional observation is discretized in the points
indicated in
v
. The series obtained is i.i.d.
and does not exhibit any kind of serial correlation.
simulate_iid_brownian_bridge( N, v = seq(from = 0, to = 1, length.out = 100), sig = 1 )
simulate_iid_brownian_bridge( N, v = seq(from = 0, to = 1, length.out = 100), sig = 1 )
N |
The number of observations of the simulated data. |
v |
Discretization points of the curves, by default
|
sig |
Standard deviation of the Brownian Motion process,
by default |
Return the simulated functional time series as a matrix.
N <- 100 v <- seq(from = 0, to = 1, length.out = 20) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) matplot(v,t(bbridge), type = "l", xlab = "v", ylab = "Value")
N <- 100 v <- seq(from = 0, to = 1, length.out = 20) sig <- 2 bbridge <- simulate_iid_brownian_bridge(N, v, sig) matplot(v,t(bbridge), type = "l", xlab = "v", ylab = "Value")
Generate a functional time series from a Brownian Motion process.
Each functional observation is discretized in the points
indicated in v
. The series obtained is i.i.d.
and does not exhibit any kind of serial correlation
simulate_iid_brownian_motion( N, v = seq(from = 0, to = 1, length.out = 100), sig = 1 )
simulate_iid_brownian_motion( N, v = seq(from = 0, to = 1, length.out = 100), sig = 1 )
N |
The number of observations of the simulated data. |
v |
Discretization points of the curves, by default
|
sig |
Standard deviation of the Brownian Motion process,
by default |
Return the simulated functional time series as a matrix.
N <- 100 v <- seq(from = 0, to = 1, length.out = 20) sig <- 2 bmotion <- simulate_iid_brownian_motion(N, v, sig) matplot(v,t(bmotion), type = "l", xlab = "v", ylab = "Value")
N <- 100 v <- seq(from = 0, to = 1, length.out = 20) sig <- 2 bmotion <- simulate_iid_brownian_motion(N, v, sig) matplot(v,t(bmotion), type = "l", xlab = "v", ylab = "Value")