Learn R Programming

brokenstick (version 1.1.0)

plot.brokenstick: Plot observed and fitted trajectories by group

Description

The plot method for a brokenstick object plots the observed and fitted trajectories of one or more groups.

Usage

# S3 method for brokenstick
plot(
  x,
  new_data,
  ...,
  what = "droplast",
  .x = NULL,
  group = NULL,
  xlim = NULL,
  ylim = NULL,
  show = c(TRUE, TRUE, FALSE),
  n_plot = 3L
)

Arguments

x

An object of class brokenstick.

new_data

A data frame or matrix of new predictors.

...

Extra arguments passed down to predict.brokenstick() and plot_trajectory().

what

Which knots to plot? See get_knots(). The default, what = "droplast", does not plot the right boundary knot.

.x

The x argument of the predict.brokenstick() function.

group

A vector with group identifications

xlim

Vector of length 2 with range of x-axis

ylim

Vector of length 2 with range of y-axis

show

A logical vector of length 3. Element 1 specifies whether the observed data are plotted, element 2 specifies whether the broken stick are plotted, element 3 specifies whether imputations are plotted. The default is c(TRUE, TRUE, FALSE).

n_plot

A integer indicating the number of individual plots. The default is 3, which plots the trajectories of the first three groups. The n_plot is a safety measure to prevent unintended plots of the entire data set.

Value

An object of class ggplot2::ggplot.

See Also

predict.brokenstick, plot_trajectory.

Examples

Run this code
# NOT RUN {
# fit model on raw hgt with knots at 0, 1, 2 and 3 years
fit1 <- brokenstick(hgt ~ age | id, smocc_200, knots = 0:3)
gp <- c(10001, 10005, 10022)
plot(fit1, smocc_200,
  group = gp, xlim = c(0, 2.1),
  xlab = "Age (years)", ylab = "Length (cm)"
)

# fit model on standard deviation score
fit2 <- brokenstick(hgt.z ~ age | id, smocc_200, knots = 0:3)
plot(fit2, smocc_200,
  group = gp, xlim = c(0, 2.1),
  xlab = "Age (years)", ylab = "Length (SDS)"
)

# model with 11 knots
plot(fit_200, smocc_200,
  group = gp, xlim = c(0, 2.1),
  xlab = "Age (years)", ylab = "Length (SDS)"
)
# }

Run the code above in your browser using DataLab