plot_emdr: Plot coefficients of EMD-regression

Description Usage Arguments Examples

View source: R/emdr_results.R

Description

Plot the coefficients resulting from an EMD-regression acording to the mean period of the corresponding IMFs.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
plot_emdr(
  x,
  periods = NULL,
  lower = NULL,
  upper = NULL,
  ci.args = list(),
  period.log2 = TRUE,
  trend.label = "Trend",
  show.coef = c("all", "nonzero", "significant"),
  col = NULL,
  pch = NULL,
  line.pars = list(),
  ...
)

Arguments

x

The coefficient matrix to plot. Can also contain sensitivities (see sensitivity).

periods

Matrix containting the mean period of IMFs correspondind to the coefficients in x. See period. If NULL, the period are taken as the two to the power of the IMF's order.

lower, upper

Matrices containing lower and upper confidence limits.

ci.args

A list of arguments to be passed to the function arrows for drawing confidence intervals.

period.log2

Logical. If TRUE, a log2 transformation is applied to the x axis.

trend.label

The label to be displayed for the trend component's coefficient.

show.coef

Character giving restrictions for the coefficients to draw. show.coef = "all" (the default) draws all coefficients, show.coef = "nonzero" plots only nonzero coefficients, show.coef = "significant" draws only coefficients for which the confidence interval given in lower and lower excludes the zero value.

col, pch

color and point type for drawn coefficients. If matrices one value corresponds to one coefficient and if vectors a value per variable is used.

line.pars

List of parameters for the line separating the trend coefficients from the other. See abline.

...

Other arguments to be passed to the plot. See par.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
   ## EMD-R1
   library(dlnm)
   library(glmnet)
   
   # 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) 

   ## EMD-R2
   dat <- chicagoNMMAPS[,c("death", "temp", "rhum")]

   mimfs <- memd(dat)
   cmimfs <- combine.mimf(mimfs, list(12:13, 14:17, 18:19), 
     new.names = c("C12", "C13", "r"))

   # EMD-R2 with glm
   lm.R2 <- emdr2(death ~ temp + rhum, mimf = cmimfs)
   betas.R2 <- coef(lm.R2)
   amps <- mean_amplitude(cmimfs)
   sensitivity.R2 <- sensitivity(amps[,-1], coefs = betas.R2[,-1])

   plot_emdr(sensitivity.R2, periods = period(cmimfs)[,-1],  
     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.