Learn R Programming

sitar (version 1.0.9)

predict.sitar: Predict SITAR model

Description

Predict method for sitar objects, based on predict.lme.

Usage

"predict"(object, newdata = getData(object), level = 1, ..., deriv = 0, abc = ranef(object), xfun = function(x) x, yfun = function(y) y)

Arguments

object
an object inheriting from class sitar.
newdata
an optional data frame to be used for obtaining the predictions. It requires named columns for x, and for id if level = 1, matching the names in object. Any covariates in a.formula, b.formula or c.formula can also be included. By default their values are set to the mean, so when level = 0 the prediction represents the mean curve.
level
an optional integer giving the level(s) of grouping to be used in obtaining the predictions, level 0 corresponding to the population predictions. Defaults to level 1.
deriv
an optional integer specifying predictions corresponding to either the fitted curve or its derivative. deriv = 0 (default) specifies the distance curve, deriv = 1 the velocity curve and deriv = 2 the acceleration curve.
abc
an optional named vector containing values of a subset of a, b and c, default NULL. If abc is set, level is set to 0. It gives predictions for a single subject with the specified values of a, b and c, where missing values are set to 0.
xfun
an optional function to apply to x to convert it back to the original scale, e.g. if x = log(age) then xfun = exp. Only relevant if deriv > 0 - see Details.
yfun
an optional function to apply to y to convert it back to the original scale, e.g. if y = sqrt(height) then yfun = function(z) z^2.
...
other optional arguments: asList, na.action and naPattern.

Value

A vector of the predictions, or a list of vectors if asList = TRUE and level == 1, or a data frame if length(level) > 1.

Details

When deriv = 1 the returned velocity is in units of yfun(y) per xfun(x). So if x and/or y are transformed, velocity in units of y per x can be obtained by specifying xfun and/or yfun to back-transform them appropriately.

See Also

ifun for a way to generate the functions xfun and yfun automatically from the sitar model call.

Examples

Run this code

data(heights)
## fit model
m1 <- sitar(x=age, y=height, id=id, data=heights, df=5)

## predictions at level 0
predict(m1, newdata=data.frame(age=9:16), level=0)

## predictions at level 1 for subject 5
predict(m1, newdata=data.frame(age=9:16, id=5), level=1)

## velocity predictions for subjects with early and late puberty
vel1 <- predict(m1, deriv=1, abc=c(b=-1))
mplot(age, vel1, id, heights, col=id)
vel1 <- predict(m1, deriv=1, abc=c(b=1))
mplot(age, vel1, id, heights, col=id, add=TRUE)

Run the code above in your browser using DataLab