Skip to contents

This function plots probability density for given predictor value

Usage

sliceMixglm(
  mod,
  form = NULL,
  value = 0,
  byChains = TRUE,
  xlab = names(mod$data),
  doPlot = TRUE,
  setCol = c("#1b9e77", "#d95f02", "#7570b3", "#e7298a", "#66a61e", "#e6ab02", "#a6761d",
    "#666666"),
  plotEst = TRUE,
  xaxis = TRUE,
  addEcos = FALSE,
  ecosTol = 0.1,
  samples = 1000,
  randomSample = NULL,
  getParsD = FALSE,
  respIn = NULL
)

Arguments

mod

an object of class "mixglm"

form

formula with one predictor specifying which variables to plot

value

numeric vector of values of the preditor specified by "form" where the slice is done or data.frame with values of predictors in named columns

byChains

logical value indicating if slice should be done for each chain separately

xlab

string used as label for x-axis

doPlot

logical value indicating if plotting should be done

setCol

vector of colours to be used for visualization of estimated states

plotEst

logical value indicating if estimated mixture components should be visualized

xaxis

logical value indicating if values should be marked on x-axis

addEcos

logical value indicating if observations within "ecosTol" from "value" should be visualized on the stability curve

ecosTol

scalar specifying range of predictor from the "value" to select observations to be visualized

samples

scalar specifying number of samples to be taken along predictor

randomSample

integer specifying how many random samples from posterior distribution to take instead of summary. Use "NULL" for summary.

getParsD

logical value indicating if the output should be parameters of distributions instead of the slice. Requires doPlot to be FALSE

respIn

mainly for internal use. Numeric vector specifying values along response variable for which to compute probability density.

Value

Returns invisibly a list containing the following components:

chainX

One or more items of a matrix of probability density values along the response with a column for each value. One item is returned if byChains is not TRUE, otherwise one item for each chain. If getParsD is TRUE, parameters for probability density distributions are returned instead.

densFun

If getParsD is TRUE, function for calculation of probability density is returned.

resp

A vector of response values for which stability curves are evaluated

Author

Adam Klimes

Examples

if (FALSE) { # \dontrun{
set.seed(10)
n <- 200
x <- rnorm(n)
group <- rbinom(n, 1, 0.5)
y <- rnorm(n, 1 + 0.5 * x * c(-1, 1)[group + 1], 0.1)
plot(y ~ x)
dat <- data.frame(x, y)

mod <- mixglm(
  stateValModels = y ~ x,
  stateProbModels = ~ x,
  statePrecModels = ~ x,
  inputData = dat,
  numStates = 2)
sliceMixglm(mod, value = 1)

# plot including observations around x == 1
sliceMixglm(mod, value = 1, addEcos = TRUE)

# plot 5 random samples from posterior distribution
sliceMixglm(mod, value = 1, randomSample = 5, byChain = FALSE)} # }