plot.dpGLM: Default plot for class dpGLM

plot.dpGLMR Documentation

Default plot for class dpGLM

Description

This function generates desity plots with the posterior distribution generated by the function hdpGLM

Usage

## S3 method for class 'dpGLM'
plot(
  x,
  terms = NULL,
  separate = FALSE,
  hpd = TRUE,
  true.beta = NULL,
  title = NULL,
  subtitle = NULL,
  adjust = 1,
  ncols = NULL,
  only.occupied.clusters = TRUE,
  focus.hpd = FALSE,
  legend.position = "top",
  colour = "grey",
  alpha = 0.4,
  display.terms = TRUE,
  plot.mean = TRUE,
  legend.label.true.value = "True",
  ...
)

Arguments

x

a dpGLM object with the samples from generated by hdpGLM

terms

string vector with the name of covariates to plot. If NULL (default), all covariates are plotted.

separate

boolean, if TRUE the linear coefficients beta will be displayed in their separate clusters.

hpd

boolean, if TRUE and separate=T, the 95% HPDI lines will be displayed.

true.beta

either NULL (default) or a data.frame with the true values of the linear coefficients beta if they are known. The data.frame must contain a column named k indicating the cluster of beta, and a column named Parameter with the name of the linear coefficients (beta1, beta2, ..., beta_dx, where dx is the number of covariates at the individual level, and beta1 is the coefficient of the intercept term). It must contain a column named True with the true value of the betas.

title

string, the title of the plot

subtitle

string, the subtitle of the plot

adjust

the bandwidth used is actually adjust*bw. This makes it easy to specify values like ‘half the default’ bandwidth.

ncols

integer, the number of columns in the plot

only.occupied.clusters

boolean, if TRUE it shows only the densities of the clusters that actually have data points assigned to it with high probability

focus.hpd

boolean, if TRUE and separate is also TRUE it will display only the 95% HPDI of the posterior density of the linear coefficients beta

legend.position

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

colour

= string with color to fill the density plot

alpha

number between 0 and 1 indicating the degree of transparency of the density

display.terms

boolean, if TRUE (default), the covariate name is displayed in the plot

plot.mean

boolean, if TRUE the posterior mean of every cluster is displayed

legend.label.true.value

a string with the value to display in the legend when the true.beta is used

...

ignored

Examples

# Note: this example is just for illustration. MCMC iterations are very reduced
set.seed(10)
n = 20
data = 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)) ,
                                   ) 

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

plot(samples)



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