Learn R Programming

mfp2 (version 1.1.1)

fracplot: Deprecated Fractional-Polynomial Plotting Interface

Description

fracplot() is retained temporarily for compatibility with code written for earlier versions of mfp2. Use plot.mfp2() or plot() instead.

Usage

fracplot(
  model,
  terms = NULL,
  partial_only = FALSE,
  type = c("terms", "contrasts"),
  ref = NULL,
  terms_seq = c("data", "equidistant"),
  alpha = 0.05,
  show_titles = TRUE,
  show_grid = FALSE,
  color_points = "#AAAAAA",
  color_line = "red",
  color_line_spike = "red",
  color_fill = "#000000",
  shape = 16,
  size_points = 1,
  size_points_spike = 2,
  linetype = "solid",
  linewidth = 1,
  alpha_fill = 0.1
)

Value

A named list of ggplot2 objects, one for each plotted term, identical to the result returned by plot.mfp2() called with the same arguments (including the colours).

Arguments

model

A fitted object of class "mfp2".

terms

Names of the variables to plot, for example, c("age", "cavol"). By default (NULL), requests all variables kept in the final model. See Choosing terms.

partial_only

Whether to show only the fitted effect and confidence interval. Defaults to FALSE. See Component-plus-residual plots.

type

Either "terms" (default) or "contrasts". See Choosing the plot type.

ref

Named list of reference values for contrast plots, for example, list(age = 50). See Contrasts and reference values.

terms_seq

Either "data" or "equidistant". See Evaluation values for their meaning and defaults.

alpha

Significance level for confidence intervals. The default, 0.05, gives 95 percent intervals. See Confidence intervals.

show_titles

Whether to show titles describing the fitted transformation or variable representation. Defaults to TRUE.

show_grid

Whether to show the major and minor panel grid lines of ggplot2::theme_bw(). Defaults to FALSE, which draws plots without grid lines.

color_points

Colour of component-plus-residual points, for example, "grey60" or "#AAAAAA". All colour arguments accept ggplot2 colour names or hexadecimal codes. See ggplot2::aes_colour_fill_alpha.

color_line

Colour of fitted curves and fitted points for binary predictors and factors, for example, "black" or "blue". Also used for the zero endpoint of a term fitted with zero = TRUE alone.

color_line_spike

Colour of the separate zero endpoint for a catzero or spike-at-zero term with a continuous component, for example, "red".

color_fill

Fill colour of confidence bands, for example, "lightblue" or "#56B4E9".

shape

Shape of component-plus-residual points. Common ggplot2 shape codes include 1 for open circles and 16 for solid circles. The default is 16. See ggplot2::scale_shape().

size_points

Numeric size of component-plus-residual points, in millimetres, for example, 1 or 2. The default is 1. See ggplot2::geom_point().

size_points_spike

Numeric size of fitted points for binary predictors, factors, and zero endpoints. For example, use 3 for larger points. The default is 2. See ggplot2::geom_point().

linetype

Line style of fitted curves, for example, "solid", "dashed", or "dotted". The default is "solid". See ggplot2::scale_linetype().

linewidth

Numeric width of fitted curves, for example, 0.5 or 1. Larger values produce thicker lines. The default is 1. See ggplot2::geom_line().

alpha_fill

Confidence-band transparency, from 0 (transparent) to 1 (opaque).

Details

The function forwards its arguments to plot.mfp2() and returns the same plot objects, except that its own defaults for color_line and color_line_spike are "red", whereas plot.mfp2() uses "black". The sections referred to in the argument descriptions, such as Choosing terms, are on the help page of plot.mfp2().

See Also

plot.mfp2()

Examples

Run this code
data("prostate")

fit <- mfp2(
  lpsa ~ fp(age) + fp(cavol) + fp(weight) + svi,
  data = prostate,
  verbose = FALSE
)

# Plotting requires ggplot2.
if (requireNamespace("ggplot2", quietly = TRUE)) {
  # Recommended interface
  plots <- plot(fit, terms = "cavol")
  print(plots)
}

# \donttest{
if (requireNamespace("ggplot2", quietly = TRUE)) {
  # Deprecated compatibility interface
  old_plots <- fracplot(fit, terms = "cavol")
}
# }

Run the code above in your browser using DataLab