Title: | Emax Model Analysis with 'Stan' |
---|---|
Description: | Perform sigmoidal Emax model fit using 'Stan' in a formula notation, without writing 'Stan' model code. |
Authors: | Kenta Yoshida [aut, cre] , Trustees of Columbia University [cph] (src/init.cpp, tools/make_cc.R, R/stanmodels.R) |
Maintainer: | Kenta Yoshida <[email protected]> |
License: | GPL-3 | file LICENSE |
Version: | 0.1.5 |
Built: | 2024-10-26 04:43:20 UTC |
Source: | https://github.com/yoshidk6/rstanemax |
Perform sigmoidal Emax model fit using Stan without writing Stan model code.
Stan Development Team (2018). RStan: the R interface to Stan. R package version 2.18.2. http://mc-stan.org
Sample simulated data for exposure-response.
exposure.response.sample
exposure.response.sample
A data frame with columns:
Dose levels used for simulation of pharmacokinetics
Simulated exposure
Simulated pharmacodynamic response
exposure.response.sample
exposure.response.sample
Sample simulated data for exposure-response with covariates
exposure.response.sample.with.cov
exposure.response.sample.with.cov
A data frame with columns:
Dose levels used for simulation of pharmacokinetics
Simulated exposure
Simulated pharmacodynamic response
Covariate 1 for e0
Covariate 2 for emax
Covariate 3 for ec50 (data type factor)
Covariate 3 for ec50 (data type numeric)
exposure.response.sample
exposure.response.sample
Extract posterior draws of key parameters
extract_param(object)
extract_param(object)
object |
A |
A tibble containing posterior draws of key parameters. If covariate(s) are included in the model, posterior draws for different combinations of covariates are supplied in a long format - e.g. if there are posterior draws of 100 samples and 4 levels of the covariates, the returned tibble will have the length of 400
Compute outcome predictions using posterior samples. Exposure data for prediction can be either original data used for model fit or new data.
## S3 method for class 'stanemax' posterior_predict( object, newdata = NULL, returnType = c("matrix", "dataframe", "tibble"), newDataType = c("raw", "modelframe"), ... ) posterior_predict_quantile( object, newdata = NULL, ci = 0.9, pi = 0.9, newDataType = c("raw", "modelframe") )
## S3 method for class 'stanemax' posterior_predict( object, newdata = NULL, returnType = c("matrix", "dataframe", "tibble"), newDataType = c("raw", "modelframe"), ... ) posterior_predict_quantile( object, newdata = NULL, ci = 0.9, pi = 0.9, newDataType = c("raw", "modelframe") )
object |
A |
newdata |
An optional data frame that contains columns needed for model to run (exposure and covariates). If the model does not have any covariate, this can be a numeric vector corresponding to the exposure metric. |
returnType |
An optional string specifying the type of return object. |
newDataType |
An optional string specifying the type of newdata input, whether in the format of an original data frame or a processed model frame. Mostly used for internal purposes and users can usually leave at default. |
... |
Additional arguments passed to methods. |
ci |
Credible interval of the response without residual variability. |
pi |
Prediction interval of the response with residual variability. |
Run vignette("emaxmodel", package = "rstanemax")
to see
how you can use the posterior prediction for plotting estimated Emax curve.
An object that contain predicted response with posterior distribution of parameters. The default is a matrix containing predicted response. Each row of the matrix is a vector of predictions generated using a single draw of the model parameters from the posterior distribution.
If either dataframe
or tibble
is specified, the function returns a data frame or tibble object in a long format -
each row is a prediction generated using a single draw of the model parameters and a corresponding exposure.
Two types of predictions are generated with this function.
respHat
corresponds to the prediction without considering residual variability and is intended to provide credible interval of "mean" response.
response
include residual variability in its calculation, therefore the range represents prediction interval of observed response.
The return object also contains exposure and parameter values used for calculation.
With posterior_predict_quantile()
function, you can obtain quantiles
of respHat
and response
as specified by ci
and pi
.
Run sigmoidal Emax model fit with formula notation
stan_emax( formula, data, gamma.fix = 1, e0.fix = NULL, emax.fix = NULL, priors = NULL, param.cov = NULL, ... )
stan_emax( formula, data, gamma.fix = 1, e0.fix = NULL, emax.fix = NULL, priors = NULL, param.cov = NULL, ... )
formula |
a symbolic description of variables for Emax model fit. |
data |
an optional data frame containing the variables in the model. |
gamma.fix |
a (positive) numeric or NULL to specify gamma (Hill coefficient) in the sigmoidal Emax model. If NULL, gamma will be estimated from the data. If numeric, gamma is fixed at the number provided. Default = 1 (normal Emax model). |
e0.fix |
a numeric or NULL to specify E0 in the Emax model. If NULL, E0 will be estimated from the data. If numeric, E0 is fixed at the number provided. Default = NULL (estimate from the data). |
emax.fix |
a numeric or NULL to specify Emax in the Emax model. If NULL, Emax will be estimated from the data. If numeric, Emax is fixed at the number provided. Default = NULL (estimate from the data). |
priors |
a named list specifying priors of parameters (ec50, emax, e0, gamma, sigma). Each list item should be length 2 numeric vector, one corresponding to mean and another corresponding to standard deviation. Currently only supports normal distribution for priors. |
param.cov |
a named list specifying categorical covariates on parameters (ec50, emax, e0). Convert a column into factor if specific order of covariates are needed. |
... |
Arguments passed to rstan::sampling (e.g. iter, chains). |
The following structure is used for the Emax model:
An object of class stanemax
## Not run: data(exposure.response.sample) fit1 <- stan_emax(response ~ exposure, data = exposure.response.sample, # the next line is only to make the example go fast enough chains = 1, iter = 500, seed = 12345) print(fit1) # Set priors manually, also estimate gamma instead of the default of fix to 1 fit2 <- stan_emax(response ~ exposure, data = exposure.response.sample, gamma.fix = NULL, priors = list(ec50 = c(100, 30), emax = c(100, 30), e0 = c(10, 5), gamma = c(0, 3), sigma = c(0, 30)), # the next line is only to make the example go fast enough chains = 1, iter = 500, seed = 12345) print(fit2) data(exposure.response.sample.with.cov) # Specify covariates fit3 <- stan_emax(formula = resp ~ conc, data = exposure.response.sample.with.cov, param.cov = list(emax = "cov2", ec50 = "cov3", e0 = "cov1"), # the next line is only to make the example go fast enough chains = 1, iter = 500, seed = 12345) print(fit3) ## End(Not run)
## Not run: data(exposure.response.sample) fit1 <- stan_emax(response ~ exposure, data = exposure.response.sample, # the next line is only to make the example go fast enough chains = 1, iter = 500, seed = 12345) print(fit1) # Set priors manually, also estimate gamma instead of the default of fix to 1 fit2 <- stan_emax(response ~ exposure, data = exposure.response.sample, gamma.fix = NULL, priors = list(ec50 = c(100, 30), emax = c(100, 30), e0 = c(10, 5), gamma = c(0, 3), sigma = c(0, 30)), # the next line is only to make the example go fast enough chains = 1, iter = 500, seed = 12345) print(fit2) data(exposure.response.sample.with.cov) # Specify covariates fit3 <- stan_emax(formula = resp ~ conc, data = exposure.response.sample.with.cov, param.cov = list(emax = "cov2", ec50 = "cov3", e0 = "cov1"), # the next line is only to make the example go fast enough chains = 1, iter = 500, seed = 12345) print(fit3) ## End(Not run)
Methods for stanemax objects
## S3 method for class 'stanemax' print(x, digits_summary = 2, ...) extract_stanfit(x) extract_obs_mod_frame(x) ## S3 method for class 'stanemax' plot(x, show.ci = TRUE, show.pi = FALSE, ci = 0.9, pi = 0.9, ...)
## S3 method for class 'stanemax' print(x, digits_summary = 2, ...) extract_stanfit(x) extract_obs_mod_frame(x) ## S3 method for class 'stanemax' plot(x, show.ci = TRUE, show.pi = FALSE, ci = 0.9, pi = 0.9, ...)
x |
An object of class |
digits_summary |
The number of significant digits to use when printing the summary, defaulting to 2. Applies to the quantities other than the effective sample size, which is always rounded to the nearest integer. |
... |
Additional arguments passed to methods. |
show.ci |
An logical specifying if the output figure include credible interval of posterior prediction. Default TRUE. |
show.pi |
An logical specifying if the output figure include prediction interval. Default FALSE. |
ci |
Credible interval range. |
pi |
Prediction interval range. |