View source: R/marginal_draws.R
marginal_draws.bgmfit | R Documentation |
The marginal_draws() function estimates and plots
growth curves (distance and velocity) by using marginaleffects
package as back-end. This function can compute growth curves (via
marginaleffects::predictions()
), average growth curves (via
marginaleffects::avg_predictions()
) or plot growth curves (via
marginaleffects::plot_predictions()
). Please see
here for details.
## S3 method for class 'bgmfit'
marginal_draws(
model,
resp = NULL,
ndraws = NULL,
draw_ids = NULL,
newdata = NULL,
datagrid = NULL,
re_formula = NA,
allow_new_levels = FALSE,
sample_new_levels = "gaussian",
parameter = NULL,
xrange = 1,
acg_velocity = 0.1,
digits = 2,
numeric_cov_at = NULL,
aux_variables = NULL,
levels_id = NULL,
avg_reffects = NULL,
idata_method = NULL,
ipts = NULL,
seed = 123,
future = FALSE,
future_session = "multisession",
cores = NULL,
fullframe = FALSE,
average = FALSE,
plot = FALSE,
showlegends = NULL,
variables = NULL,
condition = NULL,
deriv = 0,
deriv_model = TRUE,
type = NULL,
by = NULL,
conf_level = 0.95,
transform = NULL,
byfun = NULL,
wts = NULL,
hypothesis = NULL,
equivalence = NULL,
reformat = NULL,
estimate_center = NULL,
estimate_interval = NULL,
dummy_to_factor = NULL,
verbose = FALSE,
expose_function = FALSE,
usesavedfuns = NULL,
clearenvfuns = NULL,
envir = NULL,
...
)
marginal_draws(model, ...)
model |
An object of class |
resp |
A character string (default |
ndraws |
A positive integer indicating the number of posterior draws to
be used in estimation. If |
draw_ids |
An integer indicating the specific posterior draw(s)
to be used in estimation (default |
newdata |
An optional data frame to be used in estimation. If
|
datagrid |
Generate a grid of user-specified values for use in the
|
re_formula |
Option to indicate whether or not to include the
individual/group-level effects in the estimation. When |
allow_new_levels |
A flag indicating if new levels of group-level
effects are allowed (defaults to |
sample_new_levels |
Indicates how to sample new levels for grouping
factors specified in |
parameter |
A single character string, or a character vector specifying
the growth parameter(s) to be estimated. Options are |
xrange |
An integer to set the predictor range (i.e., age) when
executing the interpolation via |
acg_velocity |
A real number to set the percentage of peak growth growth
velocity as the cessation velocity when estimating the |
digits |
An integer (default |
numeric_cov_at |
An optional (named list) argument to specify the value
of continuous covariate(s). The default |
aux_variables |
An optional argument to specify the variable(s) that can
be passed to the |
levels_id |
An optional argument to specify the |
avg_reffects |
An optional argument (default |
idata_method |
A character string to indicate the interpolation method.
The number of of interpolation points is set up the |
ipts |
An integer to set the length of the predictor variable to get a
smooth velocity curve. The |
seed |
An integer (default |
future |
A logical (default |
future_session |
A character string to set the session type when
|
cores |
Number of cores to be used when running the parallel
computations (if |
fullframe |
A logical to indicate whether to return |
average |
A logical to indicate whether to internally call the
|
plot |
A logical to specify whether to plot predictions by calling the
|
showlegends |
An argument to specify whether to show legends
( |
variables |
For estimating growth parameters in the current use case,
the |
condition |
Conditional predictions
|
deriv |
An integer to indicate whether to estimate distance curve or its
derivative (i.e., velocity curve). The |
deriv_model |
A logical to specify whether to estimate velocity curve
from the derivative function, or the differentiation of the distance curve.
The argument |
type |
string indicates the type (scale) of the predictions used to
compute contrasts or slopes. This can differ based on the model
type, but will typically be a string such as: "response", "link", "probs",
or "zero". When an unsupported string is entered, the model-specific list of
acceptable values is returned in an error message. When |
by |
Aggregate unit-level estimates (aka, marginalize, average over). Valid inputs:
|
conf_level |
numeric value between 0 and 1. Confidence level to use to build a confidence interval. |
transform |
string or function. Transformation applied to unit-level estimates and confidence intervals just before the function returns results. Functions must accept a vector and return a vector of the same length. Support string shortcuts: "exp", "ln" |
byfun |
A function such as |
wts |
string or numeric: weights to use when computing average contrasts or slopes. These weights only affect the averaging in
|
hypothesis |
specify a hypothesis test or custom contrast using a numeric value, vector, or matrix, a string, or a string formula.
|
equivalence |
Numeric vector of length 2: bounds used for the two-one-sided test (TOST) of equivalence, and for the non-inferiority and non-superiority tests. See Details section below. |
reformat |
A logical (default |
estimate_center |
A character string (default |
estimate_interval |
A character string (default |
dummy_to_factor |
A named list (default |
verbose |
An optional argument (logical, default |
expose_function |
An optional logical argument to indicate whether to
expose Stan functions (default |
usesavedfuns |
A logical (default |
clearenvfuns |
A logical to indicate whether to clear the exposed
function from the environment ( |
envir |
Environment used for function evaluation. The default is
|
... |
Additional arguments passed to the |
The marginal_draws() estimates fitted values (via
brms::fitted.brmsfit()
) or the posterior draws from the posterior
distribution (via brms::predict.brmsfit()
) depending on the type
argument.
An array of predicted mean response values. See brms::fitted.brmsfit for details.
Satpal Sandhu satpal.sandhu@bristol.ac.uk
marginaleffects::predictions()
marginaleffects::avg_predictions()
marginaleffects::plot_predictions()
# Fit Bayesian SITAR model
# To avoid mode estimation which takes time, the Bayesian SITAR model fit to
# the 'berkeley_exdata' has been saved as an example fit ('berkeley_exfit').
# See 'bsitar' function for details on 'berkeley_exdata' and 'berkeley_exfit'.
# Check and confirm whether model fit object 'berkeley_exfit' exists
berkeley_exfit <- getNsObject(berkeley_exfit)
model <- berkeley_exfit
# Population average distance curve
marginal_draws(model, deriv = 0, re_formula = NA)
# Individual-specific distance curves
marginal_draws(model, deriv = 0, re_formula = NULL)
# Population average velocity curve
marginal_draws(model, deriv = 1, re_formula = NA)
# Individual-specific velocity curves
marginal_draws(model, deriv = 1, re_formula = NULL)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.