knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

In this vignette, we will show how to estimate the mean and covariance functions of a functional dataset. For this example, we will use simulated data using the package simulater.

# Load the packages
library(funestim)
library(simulater)

First, we will generate some data.

mu <- learn_mean(powerconsumption)
cov <- learn_covariance(powerconsumption)
noise <- learn_noise(powerconsumption)

grid <- seq(0, 1, length.out = 101)
X <- generate_data(n = 100, m = 100, 
                   model_mean = mu, covariance = cov, 
                   model_noise = noise, 
                   lambda = exp(-5.5), 
                   ti = NULL, grid = grid,
                   p = 0.2, k = 1)

We perform an estimation of the mean curve.

obs_points <- seq(0, 1, length.out = 101)  # Estimation grid mean
band_points <- c(0.25, 0.5, 0.75) # Estimation grid regularity
delta_f <- function(m) exp(-log(m)**0.5)
mean_curve <- mean_ll(X, grid = obs_points,
                      grid_param = band_points, delta_f = delta_f)
plot(NULL, xlim = c(0, 1), ylim = c(230, 250), xlab = '', ylab = '')
for (i in 1:35) {
  lines(X[[i]]$t, X[[i]]$x, col = i)
}
lines(obs_points, mean_curve$mu, col = 'red', lwd = 4)

We perform an estimation of the covariance surface.

obs_points <- seq(0, 1, length.out = 101)  # Estimation grid mean
band_points <- c(0.25, 0.5, 0.75) # Estimation grid regularity
delta_f <- function(m) exp(-log(m)**0.5)
cov_our <- covariance_ll(X, grid = obs_points, 
                         grid_param = band_points,
                         grid_bandwidth = NULL,
                         center = TRUE,
                         delta_f = delta_f,
                         n_obs_min = 2,
                         kernel_name = 'epanechnikov')
filled.contour(cov_our$cov, nlevels = 5)


StevenGolovkine/funestim documentation built on June 15, 2022, 3:42 a.m.