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]
|
Maintainer: | Kenta Yoshida <[email protected]> |
License: | GPL-3 | file LICENSE |
Version: | 0.1.9 |
Built: | 2025-02-17 09:27:41 UTC |
Source: | CRAN |
Perform sigmoidal Emax model fit using Stan without writing Stan model code.
Maintainer: Kenta Yoshida [email protected] (ORCID)
Authors:
Danielle Navarro [email protected] (ORCID)
Other contributors:
Trustees of Columbia University (src/init.cpp, tools/make_cc.R, R/stanmodels.R) [copyright holder]
Stan Development Team (2018). RStan: the R interface to Stan. R package version 2.18.2. http://mc-stan.org
Useful links:
Report bugs at https://github.com/yoshidk6/rstanemax/issues
Convert stanemax object to a posterior draws object
as_draws(x, ...) as_draws_list(x, ...) as_draws_array(x, ...) as_draws_df(x, ...) as_draws_matrix(x, ...) as_draws_rvars(x, ...) ## S3 method for class 'stanemax' as_draws(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemaxbin' as_draws(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemax' as_draws_list(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemaxbin' as_draws_list(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemax' as_draws_array(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemaxbin' as_draws_array(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemax' as_draws_df(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemaxbin' as_draws_df(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemax' as_draws_matrix(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemaxbin' as_draws_matrix(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemax' as_draws_rvars(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemaxbin' as_draws_rvars(x, inc_warmup = FALSE, ...)
as_draws(x, ...) as_draws_list(x, ...) as_draws_array(x, ...) as_draws_df(x, ...) as_draws_matrix(x, ...) as_draws_rvars(x, ...) ## S3 method for class 'stanemax' as_draws(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemaxbin' as_draws(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemax' as_draws_list(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemaxbin' as_draws_list(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemax' as_draws_array(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemaxbin' as_draws_array(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemax' as_draws_df(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemaxbin' as_draws_df(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemax' as_draws_matrix(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemaxbin' as_draws_matrix(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemax' as_draws_rvars(x, inc_warmup = FALSE, ...) ## S3 method for class 'stanemaxbin' as_draws_rvars(x, inc_warmup = FALSE, ...)
x |
An object of class stanemax. |
... |
Arguments passed to individual methods (if applicable).' |
inc_warmup |
Should warmup draws be included? Defaults to |
A draws object of the appropriate subclass
## Not run: data(exposure.response.sample) fit <- stan_emax(response ~ exposure, exposure.response.sample) posterior::as_draws_list(fit) posterior::as_draws_array(fit) posterior::as_draws_df(fit) posterior::as_draws_matrix(fit) posterior::as_draws_rvars(fit) ## End(Not run)
## Not run: data(exposure.response.sample) fit <- stan_emax(response ~ exposure, exposure.response.sample) posterior::as_draws_list(fit) posterior::as_draws_array(fit) posterior::as_draws_df(fit) posterior::as_draws_matrix(fit) posterior::as_draws_rvars(fit) ## End(Not run)
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 for binary endpoint
exposure.response.sample.binary
exposure.response.sample.binary
A data frame with columns:
Simulated exposure
Simulated logit(p)
Simulated p
Simulated event (1 or 0)
Simulated logit(p) for model with covariate
Simulated p for model with covariate
Simulated event (1 or 0) for model with covariate
1 or 0
female or male
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
See rstantools::log_lik for more details.
log_lik(object, ...) ## S3 method for class 'stanemax' log_lik(object, newdata = NULL, ...) ## S3 method for class 'stanemaxbin' log_lik(object, newdata = NULL, ...)
log_lik(object, ...) ## S3 method for class 'stanemax' log_lik(object, newdata = NULL, ...) ## S3 method for class 'stanemaxbin' log_lik(object, newdata = NULL, ...)
object |
A |
... |
Currently unused arguments |
newdata |
New data used for prediction. If NULL, original data is used. |
by
matrix of log-likelihoods, where each row
corresponds to a draw from the posterior distribution and each column corresponds to a data point.
Compute outcome predictions using posterior samples. Exposure data for prediction can be either original data used for model fit or new data.
posterior_predict(object, ...) posterior_epred(object, ...) posterior_linpred(object, transform = FALSE, ...) ## S3 method for class 'stanemax' posterior_predict( object, newdata = NULL, returnType = "matrix", newDataType = "raw", ... ) ## S3 method for class 'stanemaxbin' posterior_predict( object, newdata = NULL, returnType = "matrix", newDataType = "raw", ... ) ## S3 method for class 'stanemax' posterior_epred(object, newdata = NULL, newDataType = "raw", ...) ## S3 method for class 'stanemaxbin' posterior_epred(object, newdata = NULL, newDataType = "raw", ...) ## S3 method for class 'stanemax' posterior_linpred( object, transform = FALSE, newdata = NULL, newDataType = "raw", ... ) ## S3 method for class 'stanemaxbin' posterior_linpred( object, transform = FALSE, newdata = NULL, newDataType = "raw", ... ) posterior_predict_quantile( object, newdata = NULL, ci = 0.9, pi = 0.9, newDataType = c("raw", "modelframe") )
posterior_predict(object, ...) posterior_epred(object, ...) posterior_linpred(object, transform = FALSE, ...) ## S3 method for class 'stanemax' posterior_predict( object, newdata = NULL, returnType = "matrix", newDataType = "raw", ... ) ## S3 method for class 'stanemaxbin' posterior_predict( object, newdata = NULL, returnType = "matrix", newDataType = "raw", ... ) ## S3 method for class 'stanemax' posterior_epred(object, newdata = NULL, newDataType = "raw", ...) ## S3 method for class 'stanemaxbin' posterior_epred(object, newdata = NULL, newDataType = "raw", ...) ## S3 method for class 'stanemax' posterior_linpred( object, transform = FALSE, newdata = NULL, newDataType = "raw", ... ) ## S3 method for class 'stanemaxbin' posterior_linpred( object, transform = FALSE, newdata = NULL, newDataType = "raw", ... ) posterior_predict_quantile( object, newdata = NULL, ci = 0.9, pi = 0.9, newDataType = c("raw", "modelframe") )
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
for
stan_emax()
and .epred
for stan_emax_binary()
. 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.
Several types of predictions are generated with this function.
For continuous endpoint model (stan_emax()
),
.linpred
& .epred
: prediction without considering residual
variability and is intended to provide credible interval of "mean"
response.
.prediction
: include residual variability in its calculation,
therefore the range represents prediction interval of observed response.
For binary endpoint model (stan_emax_binary()
),
.linpred
: predicted probability on logit scale
.epred
: predicted probability on probability scale
.prediction
: predicted event (1) or non-event (0)
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)
Bayesian Emax model fit with Stan for binary endpoint
stan_emax_binary( formula, data, gamma.fix = 1, e0.fix = NULL, emax.fix = NULL, priors = NULL, param.cov = NULL, ... )
stan_emax_binary( 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). |
## Not run: data(exposure.response.sample.binary) fit1 <- stan_emax_binary( y ~ conc, data = exposure.response.sample.binary, # the next line is only to make the example go fast enough chains = 2, iter = 500, seed = 12345 ) print(fit1) # Specify covariates fit2 <- stan_emax_binary( formula = y ~ conc, data = exposure.response.sample.binary, param.cov = list(emax = "sex"), # the next line is only to make the example go fast enough chains = 2, iter = 500, seed = 12345 ) print(fit2) ## End(Not run)
## Not run: data(exposure.response.sample.binary) fit1 <- stan_emax_binary( y ~ conc, data = exposure.response.sample.binary, # the next line is only to make the example go fast enough chains = 2, iter = 500, seed = 12345 ) print(fit1) # Specify covariates fit2 <- stan_emax_binary( formula = y ~ conc, data = exposure.response.sample.binary, param.cov = list(emax = "sex"), # the next line is only to make the example go fast enough chains = 2, iter = 500, seed = 12345 ) print(fit2) ## End(Not run)
Methods for stanemax objects
## S3 method for class 'stanemax' print(x, digits_summary = 2, ...) ## S3 method for class 'stanemaxbin' 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 'stanemaxbin' plot(x, show.ci = TRUE, show.pi = FALSE, ci = 0.9, pi = 0.9, ...)
## S3 method for class 'stanemax' print(x, digits_summary = 2, ...) ## S3 method for class 'stanemaxbin' 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 'stanemaxbin' 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. |