plot.gformula_binary_eof: Plot method for objects of class "gformula_binary_eof"

View source: R/s3methods.R

plot.gformula_binary_eofR Documentation

Plot method for objects of class "gformula_binary_eof"

Description

This function generates graphs of the mean simulated vs. observed values at each time point of the time-varying covariates under the natural course. For categorical covariates, the observed and simulated probability of each level are plotted at each time point.

Usage

## S3 method for class 'gformula_binary_eof'
plot(
  x,
  covnames = NULL,
  ncol = NULL,
  nrow = NULL,
  common.legend = TRUE,
  legend = "bottom",
  xlab = NULL,
  ylab_cov = NULL,
  ...
)

Arguments

x

Object of class "gformula_binary_eof".

covnames

Vector of character strings specifying the names of the time-varying covariates to be plotted. The ordering of covariates given here is used in the plot grid. Time-varying covariates of type "categorical time" cannot be included. By default, this argument is set equal to the covnames argument used in gformula_binary_eof, where covariates of type "categorical time" are removed.

ncol

Number of columns in the plot grid. By default, two columns are used when there is at least two plots.

nrow

Number of rows in the plot grid. By default, a maximum of six rows is used and additional plots are included in subsequent pages.

common.legend

Logical scalar indicating whether to include a legend. The default is TRUE.

legend

Character string specifying the legend position. Valid values are "top", "bottom", "left", "right", and "none". The default is "bottom".

xlab

Character string for the x axes of all plots. By default, this argument is set to the time_name argument specified in gformula_binary_eof.

ylab_cov

Vector of character strings for the y axes of the plots for the covariates. This argument must be the same length as covnames. The i-th element of this argument corresponds to the plot for the i-th element of covnames.

...

Other arguments, which are passed to ggarrange.

Value

An object of class "ggarrange". See documentation of ggarrange.

See Also

gformula_binary_eof

Examples

## Estimating the effect of threshold interventions on the mean of a binary
## end of follow-up outcome

outcome_type <- 'binary_eof'
id <- 'id_num'
time_name <- 'time'
covnames <- c('cov1', 'cov2', 'treat')
outcome_name <- 'outcome'
histories <- c(lagged, cumavg)
histvars <- list(c('treat', 'cov1', 'cov2'), c('cov1', 'cov2'))
covtypes <- c('binary', 'zero-inflated normal', 'normal')
covparams <- list(covmodels = c(cov1 ~ lag1_treat + lag1_cov1 + lag1_cov2 +
                                  cov3 + time,
                                cov2 ~ lag1_treat + cov1 + lag1_cov1 +
                                  lag1_cov2 + cov3 + time,
                                treat ~ lag1_treat + cumavg_cov1 +
                                  cumavg_cov2 + cov3 + time))
ymodel <- outcome ~  treat + cov1 + cov2 + lag1_cov1 + lag1_cov2 + cov3
intervention1.treat <- list(static, rep(0, 7))
intervention2.treat <- list(threshold, 1, Inf)
int_descript <- c('Never treat', 'Threshold - lower bound 1')
nsimul <- 10000
ncores <- 2

gform_bin_eof <- gformula(obs_data = binary_eofdata,
                          outcome_type = outcome_type, id = id,
                          time_name = time_name, covnames = covnames,
                          outcome_name = outcome_name, covtypes = covtypes,
                          covparams = covparams, ymodel = ymodel,
                          intervention1.treat = intervention1.treat,
                          intervention2.treat = intervention2.treat,
                          int_descript = int_descript, histories = histories,
                          histvars = histvars, basecovs = c("cov3"),
                          seed = 1234, parallel = TRUE, nsamples = 5,
                          nsimul = nsimul, ncores = ncores)
plot(gform_bin_eof)



CausalInference/gfoRmula documentation built on Oct. 1, 2024, 8:36 p.m.