distributionPlot {pcvr}R Documentation

Function for plotting iterations of posterior distributions

Description

Function for plotting iterations of posterior distributions

Usage

distributionPlot(
  fits,
  form,
  df,
  priors = NULL,
  params = NULL,
  maxTime = NULL,
  patch = TRUE
)

Arguments

fits

A list of brmsfit objects following the same data over time. Currently checkpointing is not supported.

form

A formula describing the growth model similar to growthSS and brmPlot such as: outcome ~ predictor |individual/group

df

data used to fit models (this is used to plot each subject's trend line).

priors

a named list of samples from the prior distributions for each parameter in params. This is only used if sample_prior=FALSE in the brmsfit object. If left NULL then no prior is included.

params

a vector of parameters to include distribution plots of. Defaults to NULL which will use all parameters from the top level model.

maxTime

Optional parameter to designate a max time not observed in the models so far

patch

Logical, should a patchwork plot be returned or should lists of ggplots be returned?

Value

A ggplot or a list of ggplots (depending on patch).

Examples



  print(load(url("https://raw.githubusercontent.com/joshqsumner/pcvrTestData/main/brmsFits.rdata")))
  library(brms)
  library(ggplot2)
  library(patchwork)
  fits <- list(fit_3, fit_15)
  form <- y~time | id / group
  priors <- list(
    "phi1" = rlnorm(2000, log(130), 0.25),
    "phi2" = rlnorm(2000, log(12), 0.25),
    "phi3" = rlnorm(2000, log(3), 0.25)
  )
  params <- c("A", "B", "C")
  d <- simdf
  maxTime <- NULL
  patch <- TRUE
  from3to25 <- list(
    fit_3, fit_5, fit_7, fit_9, fit_11,
    fit_13, fit_15, fit_17, fit_19, fit_21, fit_23, fit_25
  )
  distributionPlot(
    fits = from3to25, form = y ~ time | id / group,
    params = params, d = d, priors = priors, patch = FALSE
  )
  distributionPlot(
    fits = from3to25, form = y ~ time | id / group,
    params = params, d = d, patch = FALSE
  )

## End(Not run)

[Package pcvr version 1.0.0 Index]