Learn R Programming

sitar (version 1.0.10)

plot.sitar: Plot SITAR model

Description

plot and lines methods for objects of class sitar, providing various flavours of plot of the fitted growth curves.

Usage

# S3 method for sitar
plot(x, opt = "dv", labels, apv = FALSE, xfun = NULL,
  yfun = NULL, subset = NULL, ns = 101, abc = NULL, add = FALSE,
  nlme = FALSE, ...)

# S3 method for sitar lines(x, ...)

Arguments

x

object of class sitar.

opt

character string containing a subset of letters corresponding to the options: 'd' for fitted Distance curve, 'v' for fitted Velocity curve, 'e' for fitted fixed Effects distance curve, 'D' for individual fitted Distance curves, 'V' for individual fitted Velocity curves, 'u' for Unadjusted individual growth curves, and 'a' for Adjusted individual growth curves. Options 'dveDV' give spline curves, while 'ua' give data curves made up as line segments. If both distance and velocity curves are specified, the axis for the velocity curve appears on the right side of the plot (y2), and a legend identifying the distance and velocity curves is provided.

labels

optional character vector containing plot labels for x, y and y velocity from the original SITAR model. The first two elements can alternatively be provided via par parameters xlab and ylab, and the third element via y2par (see Details). The latter take precedence. Default labels are the names of x and y, and "y velocity", suitably adjusted to reflect any back-transformation via xfun and yfun.

apv

optional logical specifying whether or not to calculate the age at peak velocity from the velocity curve. If TRUE, age at peak velocity is calculated as the age when the second derivative of the fitted curve changes sign (after applying xfun and/or yfun). Age at peak velocity is marked in the plot with a vertical dotted line, and its value, along with peak velocity, is printed and returned.

xfun

optional function to be applied to the x variable prior to plotting. Defaults to NULL, which translates to ifun(x$call.sitar$x) and inverts any transformation applied to x in the original SITAR model call. To plot on the transformed scale set xfun to I.

yfun

optional function to be applied to the y variable prior to plotting. Defaults to NULL, which translates to ifun(x$call.sitar$y) and inverts any transformation applied to y in the original SITAR model call. To plot on the transformed scale set yfun to I.

subset

optional logical vector of length x defining a subset of data rows to be plotted.

ns

scalar defining the number of points for spline curves (default 101).

abc

vector of named values of random effects a, b and c used to define an individual growth curve, e.g. abc=c(a=1, c=-0.1). Alternatively a single character string defining an id level whose random effect values are used. If abc is set, level is ignored. If abc is NULL (default), or if a, b or c values are missing, values of zero are assumed.

add

optional logical defining if the plot is pre-existing (TRUE) or new (FALSE). TRUE is equivalent to using lines.

nlme

optional logical which set TRUE plots the model as an nlme object, using plot.nlme arguments.

Further graphical parameters (see par) may also be supplied as arguments, e.g. axis labels xlab and ylab, line type lty, line width lwd, and color col. For the velocity (y2) plot y2par can be used (see Details).

Value

Returns invisibly a list of three objects:

ss

smooth.spline object corresponding to the fitted distance curve.

usr

value of par('usr') for the main plot.

usr2

the value of par('usr') for the velocity (y2) plot.

apv

if argument apv is TRUE a named list giving the age at peak velocity (apv) and peak velocity (pv) from the fitted velocity curve.

Details

For option 'dv' (the default) the velocity curve plot (with right axis) can be annotated with par parameters given as a named list called y2par. To suppress the legend that comes with it set xlegend = NULL.

See Also

mplot, plotclean, y2plot, ifun

Examples

Run this code
# NOT RUN {
## fit sitar model
m1 <- sitar(x=age, y=height, id=id, data=heights, df=7)

## draw fitted distance and velocity curves
## with velocity curve in blue
## adding age at peak velocity
plot(m1, y2par=list(col='blue'), apv=TRUE)

## draw individually coloured growth curves adjusted for random effects
## using same x-axis limits as for previous plot
plot(m1, opt='a', col=id, xlim=xaxsd())

## add mean curve in red
lines(m1, opt='d', col='red', lwd=2)

## add mean curve for a, b, c = -1 SD
lines(m1, opt='d', lwd=2, abc=-sqrt(diag(getVarCov(m1))))

# }

Run the code above in your browser using DataLab