plot_curves.bgmfit {bsitar} | R Documentation |
Plot growth curves
Description
The plot_curves() provides visualization of six
different types of growth curves that are plotted by using the ggplot2
package. The plot_curves() also allows users to make their own
detailed plots from the data returned as a data.frame
.
Usage
## S3 method for class 'bgmfit'
plot_curves(
model,
opt = "dv",
apv = FALSE,
bands = NULL,
conf = 0.95,
resp = NULL,
ndraws = NULL,
draw_ids = NULL,
newdata = NULL,
summary = TRUE,
digits = 2,
re_formula = NULL,
numeric_cov_at = NULL,
aux_variables = NULL,
levels_id = NULL,
avg_reffects = NULL,
ipts = 10,
deriv_model = TRUE,
xrange = NULL,
xrange_search = NULL,
takeoff = FALSE,
trough = FALSE,
acgv = FALSE,
acgv_velocity = 0.1,
seed = 123,
estimation_method = "fitted",
allow_new_levels = FALSE,
sample_new_levels = "uncertainty",
incl_autocor = TRUE,
robust = FALSE,
future = FALSE,
future_session = "multisession",
cores = NULL,
trim = 0,
layout = "single",
linecolor = NULL,
linecolor1 = NULL,
linecolor2 = NULL,
label.x = NULL,
label.y = NULL,
legendpos = NULL,
linetype.apv = NULL,
linewidth.main = NULL,
linewidth.apv = NULL,
linetype.groupby = NA,
color.groupby = NA,
band.alpha = NULL,
show_age_takeoff = TRUE,
show_age_peak = TRUE,
show_age_cessation = TRUE,
show_vel_takeoff = FALSE,
show_vel_peak = FALSE,
show_vel_cessation = FALSE,
returndata = FALSE,
returndata_add_parms = FALSE,
parms_eval = FALSE,
idata_method = NULL,
parms_method = "getPeak",
verbose = FALSE,
fullframe = NULL,
dummy_to_factor = NULL,
expose_function = FALSE,
usesavedfuns = NULL,
clearenvfuns = NULL,
envir = NULL,
...
)
plot_curves(model, ...)
Arguments
model |
An object of class |
opt |
A character string containing letter(s) corresponding to the following plotting options: 'd' for population average distance curve, 'v' for population average velocity curve, 'D' for individual-specific distance curves, 'V' for individual-specific velocity curves, 'u' for unadjusted individual-specific distance curves, and 'a' for adjusted individual-specific distance curves (adjusted for the random effects). Options 'd' and 'D' can not be specified simultaneously. Likewise, Options 'v' and 'V' can not be specified simultaneously. All other combinations are allowed. For example, dvau', Dvau', dVau', DVau', or dvau'. |
apv |
An optional logical (default |
bands |
A character string containing letter(s), or |
conf |
A numeric value (default |
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
|
summary |
A logical indicating whether only the estimate should be
computed ( |
digits |
An integer (default |
re_formula |
Option to indicate whether or not to include the
individual/group-level effects in the estimation. When |
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 variables to be
passed to the |
levels_id |
An optional argument to specify the |
avg_reffects |
An optional argument (default |
ipts |
An integer to set the length of the predictor variable to get a
smooth 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 |
xrange |
An integer to set the predictor range (i.e., age) when
executing the interpolation via |
xrange_search |
A vector of length two, or a character string
|
takeoff |
A logical (default |
trough |
A logical (default |
acgv |
A logical (default |
acgv_velocity |
Specify the percentage of the peak growth velocity to be
used when estimating |
seed |
An integer (default |
estimation_method |
A character string to specify the estimation method
when calculating the velocity from the posterior draws. The |
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 |
incl_autocor |
A flag indicating if correlation structures originally
specified via |
robust |
A logical to specify the summarize options. If |
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 |
trim |
A number (default 0) of long line segments to be excluded from plot with option 'u' or 'a'. See sitar::plot.sitar for details. |
layout |
A character string defining the layout structure of the plot. A
|
linecolor |
The color of line used when layout is |
linecolor1 |
The color of first line when layout is |
linecolor2 |
The color of second line when layout is |
label.x |
An optional character string to label the x axis. When
|
label.y |
An optional character string to label the y axis. When
|
legendpos |
An optional character string to specify the position of
legends. When |
linetype.apv |
An optional character string to specify the type of the
vertical line drawn to mark the APGV. Default |
linewidth.main |
An optional character string to specify the width of the
the line for the distance and velocity curves. The default |
linewidth.apv |
An optional character string to specify the width of the
the vertical line drawn to mark the APGV. The default |
linetype.groupby |
An optional argument to specify the line type for the
distance and velocity curves when drawing plots for a model that includes
factor covariate(s) or when visualising individual specific
distance/velocity curves (default |
color.groupby |
An optional argument to specify the line color for
distance and velocity curves when drawing plots for a model that includes
factor covariate(s), or when visualising individual specific
distance/velocity curves (default |
band.alpha |
An optional numeric value to specify the transparency of the
CI band(s) around the distance curve, velocity curve and the line indicating
the APGV. The default |
show_age_takeoff |
A logical (default |
show_age_peak |
A logical (default |
show_age_cessation |
A logical (default |
show_vel_takeoff |
A logical (default |
show_vel_peak |
A logical (default |
show_vel_cessation |
A logical (default |
returndata |
A logical (default |
returndata_add_parms |
A logical (default |
parms_eval |
A logical to specify whether or not to get growth parameters on the fly. This is for internal use only and mainly needed for compatibility across internal functions. |
idata_method |
A character string to indicate the interpolation method.
The number of of interpolation points is set up the |
parms_method |
A character to specify the method used to when evaluating
|
verbose |
An optional argument (logical, default |
fullframe |
A logical to indicate whether to return |
dummy_to_factor |
A named list (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
|
... |
Further arguments passed to |
Details
The plot_curves() is a generic function that allows
visualization of following six curves: population average distance curve,
population average velocity curve, individual-specific distance curves,
individual-specific velocity curves, unadjusted individual growth curves
(i.e, observed growth curves), and the adjusted individual growth curves
(adjusted for the model estimated random effects). The
plot_curves() internally calls the growthparameters()
function to
estimate and summaries the distance and velocity curves and to estimate
growth parameters such as the age at peak growth velocity (APGV). The
plot_curves() in turn calls the fitted_draws()
or the
predict_draws()
functions to make inference from the posterior draws.
Thus, plot_curves() allows plotting fitted or predicted curves. See
fitted_draws()
and predict_draws()
for details on these functions and
the difference between fitted and predicted values.
Value
A plot object (default), or a data.frame
when
returndata = TRUE
.
Author(s)
Satpal Sandhu satpal.sandhu@bristol.ac.uk
See Also
growthparameters()
fitted_draws predict_draws()
Examples
# 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 and velocity curves with default options
plot_curves(model, opt = 'dv')
# Individual-specific distance and velocity curves with default options
# Note that legendpos = 'none' will suppress the legend positions. This
# suppression is useful when plotting individual-specific curves
plot_curves(model, opt = 'DV')
# Population average distance and velocity curves with APGV
plot_curves(model, opt = 'dv', apv = TRUE)
# Individual-specific distance and velocity curves with APGV
plot_curves(model, opt = 'DV', apv = TRUE)
# Population average distance curve, velocity curve, and APGV with CI bands
# To construct CI bands, growth parameters are first calculated for each
# posterior draw and then summarized across draws. Therefore,summary
# option must be set to FALSE
plot_curves(model, opt = 'dv', apv = TRUE, bands = 'dvp', summary = FALSE)
# Adjusted and unadjusted individual curves
# Note ipts = NULL (i.e., no interpolation of predictor (i.e., age) to plot a
# smooth curve). This is because it does not a make sense to interploate data
# when estimating adjusted curves. Also, layout = 'facet' (and not default
# layout = 'single') is used for the ease of visualizing the plotted
# adjusted and unadjusted individual curves. However, these lines can be
# superimposed on each other by setting the set layout = 'single'.
# For other plots shown above, layout can be set as 'single' or 'facet'
# Separate plots for adjusted and unadjusted curves (layout = 'facet')
plot_curves(model, opt = 'au', ipts = NULL, layout = 'facet')
# Superimposed adjusted and unadjusted curves (layout = 'single')
plot_curves(model, opt = 'au', ipts = NULL, layout = 'single')