plot_tau: Plot tau

plot_tauR Documentation

Plot tau

Description

Function to plot posterior distribution of tau

Usage

plot_tau(
  samples,
  X = NULL,
  W = NULL,
  title = NULL,
  true.tau = NULL,
  show.all.taus = FALSE,
  show.all.betas = FALSE,
  ncol = NULL,
  legend.position = "top",
  x.axis.size = 1.1,
  y.axis.size = 1.1,
  title.size = 1.2,
  panel.title.size = 1.4,
  legend.size = 1,
  xlab = NULL
)

Arguments

samples

an output of the function hdpGLM

X

a string vector with the name of the first-level covariates whose associated tau should be displayed

W

a string vector with the name of the context-level covariate(s) whose linear effect will be displayed. If NULL, the linear effect tau of all context-level covariates are displayed. Note: the context-level covariate must have been included in the estimation of the model.

title

string, title of the plot

true.tau

a data.frame with four columns. The first must be named w and it indicates the index of each context-level covariate, starting with 0 for the intercept term. The second column named beta must contain the indexes of the betas of individual-level covariates, starting with 0 for the intercept term. The third column named Parameter must be named tau<w><beta>, where w and beta must be the actual values displayed in the columns w and beta. Finally, it must have a column named True with the true value of the parameter.

show.all.taus

boolean, if FALSE (default) the posterior distribution of taus representing the intercept of the expectation of beta are omitted

show.all.betas

boolean, if FALSE (default) the taus affecting only the intercept terms of the outcome variable are omitted

ncol

number of columns of the grid. If NULL, one column is used

legend.position

one of four options: "bottom" (default), "top", "left", or "right". It indicates the position of the legend

x.axis.size

numeric, the relative size of the label in the x-axis

y.axis.size

numeric, the relative size of the label in the y-axis

title.size

numeric, the relative size of the title of the plot

panel.title.size

numeric, the relative size of the titles in the panel of the plot

legend.size

numeric, the relative size of the legend

xlab

string, the label of the x-axis

Examples


library(magrittr)
set.seed(66)

# Note: this example is just for illustration. MCMC iterations are very reduced
set.seed(10)
n = 20
data.context1 = tibble::tibble(x1 = rnorm(n, -3),
                                   x2 = rnorm(n,  3),
                                   z  = sample(1:3, n, replace=TRUE),
                                   y  =I(z==1) * (3 + 4*x1 - x2 + rnorm(n)) +
                                       I(z==2) * (3 + 2*x1 + x2 + rnorm(n)) +
                                       I(z==3) * (3 - 4*x1 - x2 + rnorm(n)) ,
                                   w = 20
                                   ) 
data.context2 = tibble::tibble(x1 = rnorm(n, -3),
                                   x2 = rnorm(n,  3),
                                   z  = sample(1:2, n, replace=TRUE),
                                   y  =I(z==1) * (1 + 3*x1 - 2*x2 + rnorm(n)) +
                                       I(z==2) * (1 - 2*x1 +   x2 + rnorm(n)),
                                   w = 10
                                   ) 
data = data.context1 %>%
    dplyr::bind_rows(data.context2)

## estimation
mcmc    = list(burn.in=1, n.iter=50)
samples = hdpGLM(y ~ x1 + x2, y ~ w, data=data, mcmc=mcmc, n.display=1)


plot_tau(samples)
plot_tau(samples, ncol=2)
plot_tau(samples, X='x1', W='w')
plot_tau(samples, show.all.taus=TRUE, show.all.betas=TRUE, ncol=2)


hdpGLM documentation built on Oct. 13, 2023, 1:17 a.m.