PMXStanFit | R Documentation |
PMXStanFit
objectReads in data, runs a compiled Stan executable, generates posterior samples for model parameters, check convergence, and perform model diagnosis.
PMXStanFit(model, dat, ...)
model |
a |
dat |
a named list that provides the input data for the Stan model and other information such as individual
|
... |
any other arguments that are passed to the function |
Intuitively, a PMXStanFit
object can be uniquely realized by a PMXStanModel
object that has
been compiled successfully, an input list of data that has been prepared compatible to the model object, and a
group of arguments passed to Stan
to run sampling
.
In addition to serving as an interface to generate samples with Stan
, PMXStanFit
also provides an
interface for users to perform a variety of post-processing procedures by inquiring these samples, making
predictions, and comparing with observations. Basic functions are available to investigate sampling behavior
and check convergence, return diagnostic statistics for a fitted Bayesian model, and generate goodness-of-fit
plots commonly used for PK/PD models, both for the overall population and for subgroups by covariates.
Since all samples from all chains are conveniently accessible, users can also easily boost the capability of
a PMXStanFit
object by writing their own diagnostic/goodness-of-fit/visual predictive checks functions.
A PMXStanFit
object, with the following list of methods:
get.fit |
returns the output derived from fitting a Stan model, including the samples; the same output as
defined by |
print.fit |
prints out statistics of posterior samples, with the following arguments:
This function has a generic form as well (see Examples). |
get.path |
returns path of the folder that stores all post-processing results, such as printed statistics for samples and goodness-of-fit plots. |
get.waic |
returns diagnostic statistics for a fitted Bayesian model: Watanabe-Akaike information criterion
( |
plot.trace |
plots traces and posterior distributions corresponding to one or more Markov chains, therefore to
investigate sampling behavior and to assess mixing across chains and convergence. The argument
|
plot.gof.pred.obs |
plots medians of predictions vs. observations for goodness-of-fit assessment, with the following arguments:
Noted that a good fit usually results in a group of points clustered around the line of
|
plot.gof.pred.rsd |
plots residuals, calculated as the difference between medians of predictions and observations,
vs. predictions as one way of goodness-of-fit assessment, with the same arguments as
|
plot.gof.idv |
plots time profiles of the prediction medians and 95 profile of observations. This function has a generic form as well (see Examples). |
Yuan Xiong and Wenping Wang
The Stan Development Team. Stan Modeling Language User's Guide and Reference Manual. https://mc-stan.org.
Aki Vehtari and Andrew Gelman. WAIC and cross-validation in Stan.
Sumio Watanabe. Asymptotic Equivalence of Bayes Cross Validation and Widely Applicable Information Criterion in Singular Learning Theory. https://www.jmlr.org/papers/volume11/watanabe10a/watanabe10a.pdf.
PMXStanModel
for initialization and compilation of a PMXStanModel
object;
prepareInputData
for transformation of a NONMEM-readable dataset to a list compatiable to auto-generated
model-specific Stan code;
sampling
for usage of arguments to draw samples from a compiled Stan model.
## Not run: ### A population PK model m1 <- PMXStanModel(path = tempfile("pk_m1"), pk.struct = "1-cmpt", compile=TRUE) print(m1) data("examples_data") dat <- prepareInputData(data.source = d1_nm_poppk, model = m1, covar = c("AGE","GENDER") ) fit <- PMXStanFit(m1, dat, iter=100, chains=1) print(fit, on.screen=F) save(m1, dat, fit, file = file.path(tempfile("pk_m1"),"ModelFit.RData")) traces(fit) waic(fit) gofplot(fit) obs.vs.pred(fit, by.cov = "AGE", type = "continuous", cutoff = c(50, 60), filename = "obs_pred_by_age.pdf" ) obs.vs.pred(fit, by.cov = "GENDER", type = "categorical", filename = "obs_pred_by_gender.pdf" ) rsd.vs.pred(fit, by.cov = "AGE", type = "continuous", cutoff = c(50, 60), filename = "rsd_pred_by_age.pdf" ) rsd.vs.pred(fit, by.cov = "GENDER", type = "categorical", filename = "rsd_pred_by_gender.pdf" ) ### A population PKPD model ode <- " C2 = centr/V; d/dt(depot) =-ka*depot; d/dt(centr) = ka*depot - ke*centr; d/dt(eff) = (1+Emax*C2/(C2+EC50))*Kin - Kout*eff; " instant.stan.extension(ode) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.