View source: R/predict.sitar.R
predict.sitar | R Documentation |
Predict method for sitar
objects, based on predict.lme
.
## S3 method for class 'sitar'
predict(
object,
newdata = getData(object),
level = 1L,
...,
deriv = 0L,
abc = NULL
)
object |
an object inheriting from class |
newdata |
an optional data frame to be used for obtaining the
predictions, defaulting to the data used to fit |
level |
an optional integer vector giving the level(s) of grouping to be used
in obtaining the predictions, level 0 corresponding to the population
predictions. Defaults to level 1, and |
... |
other optional arguments: |
deriv |
an optional integer specifying predictions corresponding to
the fitted curve and/or its derivative. |
abc |
an optional named vector containing values of a subset of
|
If x
and/or y
include transformations, e.g. x = log(age)
,
predictions are returned in the original units by back-transforming x
and/or y
appropriately using the function ifun
.
A vector of the predictions, or a list of vectors if asList =
TRUE
and level == 1
, or a data frame if length(level) * length(deriv) > 1
.
The data frame column names are (a subset of): (id, predict.fixed,
predict.id, vel.predict.fixed, vel.predict.id)
.
Tim Cole tim.cole@ucl.ac.uk
data(heights)
require(dplyr)
require(tidyr)
require(ggplot2)
## fit model
m1 <- sitar(x = age, y = height, id = id, data = heights, df = 5)
df <- data.frame(age = 9:16, id = 5)
## height predictions at level 0
predict(m1, newdata = df, level = 0)
## height predictions at level 1 for subject 5
predict(m1, newdata = df, level = 1)
## velocity predictions for subjects with early, average and late puberty
m2 <- sitar(x = log(age), y = height, id = id, data = heights, df = 5)
tibble(age = 80:160/10) %>%
mutate(early = predict(m2, ., deriv = 1, abc = c(b = -0.07)),
average = predict(m2, ., deriv = 1, level = 0),
late = predict(m2, ., deriv = 1, abc = c(b = 0.07))) %>%
pivot_longer(early:late, names_to = 'group', values_to = 'height_velocity') %>%
ggplot(aes(age, height_velocity, group = group, colour = group)) +
geom_path(show.legend = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.