plotConditionalDensities: Plot density of the target variable, conditional on the...

View source: R/extensionScripts.R

plotConditionalDensitiesR Documentation

Plot density of the target variable, conditional on the extension variable

Description

Plots kernel density estimates of the target variable, conditional on each of a set of specified values of the extension variable. The plot makes use of the function ggridges::geom_density_ridges(), and so uses kernel density estimates rather than the exact conditional density function.

Usage

plotConditionalDensities(
  y,
  fitX,
  yCP,
  xMed,
  medianY,
  link = "identity",
  dist = "best",
  N = 1e+05,
  xLimits = NULL,
  fs = 12
)

Arguments

y

vector of values for the extension variable at which to condition on.

fitX

an object of class elicitation specifying the c-distribution: the distribution of the target variable, conditional on the extension variable taking its median value.

yCP

vector of conditioning points for the extension variable.

xMed

vector of medians of the target variable, corresponding to each value of the extension variable in yCP.

medianY

the median value of the extension variable.

link

link in the median function. One of "identity", "log" or "logit"

dist

choice of parametric distribution for the c-distribution. Options are "normal", "t", "gamma", "lognormal", "logt","beta", "hist" (for a histogram fit), and "best" (for best fitting).

N

sample size used in the kernel density estimate

xLimits

x-axis limits

fs

font size

Examples

## Not run: 

myfitX <- fitdist(vals = c(5.5, 9, 14),
 probs = c(0.25, 0.5, 0.75),
 lower = 0)

plotConditionalDensities(y = c(2, 6, 10),
 fitX = myfitX,
 yCP = c(3, 5, 7, 9.5, 13.5),
 xMed = c(2, 6.5, 9, 13, 20),
 medianY = 7,
 link = "log",
 dist = "lognormal",
 xLimits = c(0, 60))

  
# Example with the logit link

myfitXlogit <- fitdist(vals = c(0.2, 0.25, 0.3),
 probs = c(0.25, 0.5, 0.75),
 lower = 0, 
 upper = 1)
 
 plotConditionalDensities(y = c(2, 6, 10),
  fitX = myfitXlogit, 
  yCP = c(2, 4, 6, 8, 10),
  xMed = c(0.1, 0.3, 0.5, 0.7, 0.9),
  medianY = 6,
  link = "logit",
  dist = "beta")
 

## End(Not run)


SHELF documentation built on June 7, 2023, 5:11 p.m.