Skip to contents

Useful function for creating a good-quality line graph of changes in the predicted mortality rate.

If you want more control over the style of the graph, use the pred_mortality_rate() function to retrieve data.

Useful function for creating a good-quality line graph of changes in the empirical mortality rate.

You don't need to fit with lifelihood() to use this function, only to retrieve a lifelihood data object with lifelihoodData()

If you want more control over the style of the graph, use the compute_mortality_rate() function to retrieve data.

Convenient function used in plot_observed_mortality_rate() and plot_fitted_mortality_rate().

Usage

plot_fitted_mortality_rate(
  lifelihoodResults,
  interval_width,
  newdata = NULL,
  max_time = NULL,
  groupby = NULL,
  use_facet = FALSE,
  log_x = FALSE,
  log_y = FALSE,
  title = "Mortality rate over time",
  xlab = "Time",
  ylab = "Mortality Rate"
)

plot_observed_mortality_rate(
  lifelihoodData,
  interval_width,
  max_time = NULL,
  min_sample_size = 1,
  groupby = NULL,
  use_facet = FALSE,
  log_x = FALSE,
  log_y = FALSE,
  title = "Mortality rate over time",
  xlab = "Time",
  ylab = "Mortality Rate"
)

plot_mortality_rate(
  rate_df,
  max_time,
  groupby,
  use_facet,
  log_x,
  log_y,
  title,
  xlab = "Time",
  ylab = "Mortality rate"
)

Arguments

lifelihoodResults

output of lifelihood()

interval_width

The interval width used to calculate the mortality rate. For instance, if the time unit for deaths in the original dataset is days and interval_width is set to 10, the mortality rate will be calculated every 10 days for each group.

newdata

Data for prediction. If absent, predictions are for the subjects used in the original fit.

max_time

The maximum time for calculating the mortality rate. If set to NULL, the time of the last observed death is used.

groupby

covariate(s) over which mortality rate should be computed (default is NULL).

  • If NULL, calculates a single overall mortality rate.

  • If "all", calculates mortality rate over each combination of covariates listed in thelifelihoodData object provided.

  • Otherwise must be a character ("covariate1") or a character vector (c("covariate1", "covariate2")).

use_facet

Use facet_wrap to plot one panel per group (default=FALSE)

log_x

Determine whether the x-axis should be displayed on a logarithmic scale

log_y

Determine whether the y-axis should be displayed on a logarithmic scale

lifelihoodData

lifelihoodData object created with lifelihoodData().

min_sample_size

The minimum number of individuals alive at the beggining of a time interval for computing the observed mortality rate

rate_df

Dataframe with mortality rate, obtained via mortality_rate_data()

Value

a ggplot2 plot

a ggplot2 plot

a ggplot2 plot

Details

This function requires ggplot2 to be installed.

This function requires ggplot2 to be installed.