Skip to contents

Deprecated. Use ctGenerate(fromPriors = TRUE), which is the same computation reached through the function that generates data from a ctsem model generally. ctStanGenerate is a backward-compatible alias and is deprecated with it.

Usage

ctGenerateFromPriors(
  cts,
  datastruct = NA,
  is = FALSE,
  fullposterior = TRUE,
  nsamples = 200,
  parsonly = FALSE,
  cores = getOption("mc.cores", 2L),
  backend = c("auto", "julia", "stan"),
  n.subjects = 20,
  Tpoints = NULL,
  dtmean = 1
)

Arguments

cts

A model – ctModel or ctModelConvertOMX – or a fit from either backend, which is simply a model that arrives with a design attached. Nothing here needs a fit: generating from the prior needs the model and a set of subjects and times to generate over, and a fit is one way to supply both.

datastruct

Long format data structure as used by ctsem, giving the subjects, times and missingness to generate for. Ignored when cts is a fit, which carries its own. Left at NA for a model, a balanced design of n.subjects subjects observed at Tpoints occasions dtmean apart is built instead.

is

Deprecated and ignored, with a warning if set. Importance sampling reweights draws taken from a gaussian approximation onto a target that cannot be sampled directly. Fitted to an empty dataset there is no such target: the likelihood contributes nothing and what remains is the prior, which ctsem holds as independent univariate densities in the raw space these draws are taken in. There is no approximation to correct.

fullposterior

Generate from the full prior, or from its mode (the raw origin)?

nsamples

How many samples to generate?

parsonly

If TRUE, only return samples of raw parameters, don't generate data.

cores

Number of cpu cores to use.

backend

Which engine turns a parameter draw into data: 'auto' (the default – 'julia' when a julia session is available, 'stan' otherwise), 'julia' or 'stan'. The draws themselves do not depend on this: they come from the model's prior, which is the same object either way. parsonly=TRUE returns those draws and generates nothing, so it does not use this argument.

n.subjects, Tpoints, dtmean

The design to build when cts is a model and no datastruct is given, and unused otherwise. Tpoints falls back to the model's own when it carries one. n.subjects is deliberately smaller than ctGenerate's: this returns nsamples datasets rather than one.

Value

List containing Y, an array of nsamples by data rows by manifest variables, and llrow, an array of nsamples by data rows log likelihoods. With parsonly=TRUE, the prepared model carrying the prior draws under $stanfit$rawposterior and $stanfit$transformedpars.

Examples

# \donttest{
#generate and plot samples from prior predictive
priorpred <- ctGenerateFromPriors(cts = ctstantestfit,cores=2,nsamples = 50)
# backend = 'auto' generates with julia where it is available. Julia keeps
# running between calls, holding what it has compiled; this ends it.
if (isTRUE(ctJuliaStatus()$available)) ctJuliaKill("session")
# }