wp.twin: Superposes two worm plots

View source: R/wp.twin.r

wp.twinR Documentation

Superposes two worm plots

Description

Superposes two worm plots from GAMLSS fitted objects. This is a diagnostic tool for comparing two solutions.

Usage

wp.twin(
  obj1,
  obj2 = NULL,
  xvar = NULL,
  xvar.column = 2,
  n.inter = 16,
  show.given = FALSE,
  ylim.worm = 0.5,
  line = FALSE,
  cex = 1,
  col1 = "black",
  col2 = "orange",
  warnings = FALSE,
  ...
)

Arguments

obj1

a GAMLSS fitted object

obj2

an optional second GAMLSS fitted object

xvar

the explanatory variable against which the worm plots will be plotted

xvar.column

the number referring to the column of obj1$mu.x and obj2$mu.x. If xvar=NULL then the explanatory variable is set to xvar=obj1$mu.x[,xvar.column] respectively xvar=obj2$mu.x[,xvar.column]. The default is xvar.column=2, which selects the variable following the intercept (which is typically age in most applications).

n.inter

the number of intervals in which the explanatory variable xvar will be cut. The default is 16.

show.given

whether to show the x-variable intervals in the top of the graph, default is show.given=FALSE

ylim.worm

for multiple plots, this values is the y-variable limit, default value is ylim.worm=0.5

line

whether to plot the polynomial line in the worm plot, default value is line=FALSE

cex

the cex plotting parameter with default cex=1

col1

the color for the points of obj1. The default col="black"

col2

the color for the points of obj2. The default col="orange"

warnings

a logical indicating whether warnings should be produced. The default warnings=FALSE

...

for extra arguments, overlap, xlim.worm or pch

Details

This function is a customized version of the wp() function found in the gamlss package. Function wp.twin() allows overplotting of two worm plots, each in its own color. The points of obj1 are plotted first, the points of obj2 are superposed. This twin worm plot provide a visual assessment of the differences between the solutions. Extra arguments can be specified (e.g. xvar) that are passed down to the wp() function of gamlss if specified. The worm plot is a detrended normal QQ-plot that highlight departures from normality.

Argument xvar takes priority over xvar.column. The xvar variable is cut into n.iter intervals with an equal number observations and detrended normal QQ (i.e. worm) plots for each interval are plotted. This is a way of highlighting failures of the model within different ranges of the explanatory variable.

If line=TRUE and n.inter>1, the fitted coefficients from fitting cubic polynomials to the residuals (within each x-variable interval) can be obtain by e.g. coeffs<-wp.twin(model1,xvar=x,n.iner=9). van Buuren et al. (2001) used these residuals to identify regions (intervals) of the explanatory variable within which the model does not fit adequately the data (called "model violation")

Value

For multiple plots the xvar intervals and the coefficients of the fitted cubic polynomials to the residuals (within each xvar interval) are returned.

Author(s)

Stef van Buuren, using R code of Mikis Stasinopoulos and Bob Rigby

References

Stasinopoulos D. M. Rigby R.A. (2007) Generalized additive models for location scale and shape (GAMLSS) in R. Journal of Statistical Software, Vol. 23, Issue 7, Dec 2007, https://www.jstatsoft.org/v23/i07.

van Buuren and Fredriks M. (2001) Worm plot: simple diagnostic device for modelling growth reference curves. Statistics in Medicine, 20, 1259–1277.

van Buuren and Fredriks M. (2007) Worm plot to diagnose fit in quantile regression. Statistical Modelling, 7, 4, 363–376.

Examples


## Not run: 
library(gamlss)
data(abdom)
a <- gamlss(y~cs(x,df=1),sigma.fo=~cs(x,0),family=LO,data=abdom)
b <- gamlss(y~cs(x,df=3),sigma.fo=~cs(x,1),family=LO,data=abdom)
coeff1 <- wp.twin(a,b,line=TRUE)

## End(Not run)

AGD documentation built on May 29, 2024, 3:19 a.m.

Related to wp.twin in AGD...