pimf: EMD-R1 preparation

Description Usage Arguments Value References Examples

View source: R/emdr1.R

Description

Prepare a data.frame to be used in a regression function for EMD-R1, including the predictors MIMF and the response.

Usage

1
2
3
4
5
6
7
8
9
pimf(
  x,
  y,
  covariates = NULL,
  tt = attr(x, "tt"),
  lag = NA,
  lag.max = 0.5,
  fill.na = FALSE
)

Arguments

x

mimf object to be prepared for regression.

y

Vector containing the response variable of the regression.

covariates

List containing eventual covariates to be added to the output data.frame.

tt

Vector of custom time indices. Useful to lag irregular time series.

lag

Vector of lagging values for the IMFs in x. If NA (the default) lags are automatically chosen by the function choose_lag.

lag.max

The maximum lag to consider in the automatic lag choice. See choose_lag.

fill.na

Logical indicating if irregularly sampled IMFs should be filled with NAs.

This function take a mimf object, a response vector and prepare them to be easily used in any regression function. It essentially transform the MIMF array into a matrix containing all IMFs and lags these IMFs if necessary.

Also allows the inclusion of non-IMF predictors in covariates that are included in the output data.frame.

Value

A data.frame containing all necessary variables for a regression function. The first column contains the response vector y. The following columns contain the IMFs to be used and the last columns contain the eventual covariates.

References

Masselot, P., Chebana, F., Belanger, D., St-Hilaire, A., Abdous, B., Gosselin, P., Ouarda, T.B.M.J., 2018. EMD-regression for modelling multi-scale relationships, and application to weather-related cardiovascular mortality. Science of The Total Environment 612, 1018-1029.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   library(dlnm)
   
   # Predictor decomposition
   X <- chicagoNMMAPS[,c("temp", "rhum")]
   set.seed(123)
   mimfs <- memd(X, l = 2) # Takes a couple of minutes
   cmimfs <- combine.mimf(mimfs, list(10:11, 12:13), 
     new.names = c("C10", "C11"))

   # Response variable
   Y <- chicagoNMMAPS$resp[attr(cmimfs, "tt")]

   # Data preparation: includes the day-of-week variable as potential
   # confounder
   dataR1 <- pimf(cmimfs, Y, covariates = list(dow = 
     chicagoNMMAPS$dow[attr(cmimfs, "tt")]))
   
   # Apply the Lasso
   library(glmnet)
   lasso.res <- cv.glmnet(data.matrix(dataR1[,-1]), dataR1[,1], 
     family = "poisson")

   # Compute sensitivity and plot results
   amps <- mean_amplitude(dataR1[,2:25])
   betas <- coef(lasso.res)
   s <- sensitivity(amps, coefs = betas[2:25]) 
   plot_emdr(matrix(s, ncol = 2, byrow = FALSE), periods = period(cmimfs), 
   show.coef = "nonzero", col = c("red", "blue"), pch = 16:17)
   abline(h = 0, lty = 2)
 

PierreMasselot/Library--emdr documentation built on June 19, 2021, 8:58 a.m.