Description Usage Arguments Details Value Examples
The predictions from a broken stick model coincide with the
groupconditional means of the random effects. This function takes
an object of class brokenstick
and returns predictions
in one of several formats. The user can calculate predictions
for new persons, i.e., for persons who are not part of
the fitted model, through the x
and y
arguments.
1 2 3 4 5 6 7 8 9 10 11 12 
object 
A 
new_data 
A data frame or matrix of new predictors. 
type 
A single character. The type of predictions to generate. Valid options are:

... 
Not used, but required for extensibility. 
x 
Optional. A numeric vector with values of the predictor. It could
also be the special keyword 
y 
Optional. A numeric vector with measurements. 
group 
A vector with group identifications 
strip_data 
A logical indicating whether the row with the
observed data from 
shape 
A string: 
By default, predict()
calculates predictions for every row in
new_data
. It is possible to tailor the behavior through the
x
, y
and group
arguments. What exactly happens depends on
which of these arguments is specified:
If the user specifies x
, but no y
and group
, the function
returns  for every group in new_data
 predictions at x
values. This method will use the data from new_data
.
If the user specifies x
and y
but no group
, the function
forms a hypothetical new group with the x
and y
values. This
method uses no information from new_data
.
If the user specifies group
, but no x
or y
, the function
searches for the relevant data in new_data
and limits its
predictions to the specified groups. This is useful if prediction
for only one or a few groups is needed.
If the user specifies x
and group
, but no y
, the function
will create new values for x
in each group, search for the relevant
data in new_data
and limit prediction to locations x
in those
groups.
If the user specifies x
, y
and group
, the functions
assumes that these vectors form a data frame. The lengths of x
,
y
and group
must be the same. This procedure uses only
information from new_data
for groups with group
values that match
those on newdata
.
As case 5, but now without a new_data
argument. All data are
specified through x
, y
and group
. No matching to new_data
attempted.
A tibble of predictions. If x
, y
and group
are not specified,
the number of rows in the tibble is guaranteed to be the same as
the number of rows in new_data
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  train < smocc_200[1:1198, ]
test < smocc_200[1199:1940, ]
# Fit
fit < brokenstick(hgt.z ~ age  id, data = train, knots = 0:3)
# Predict, with preprocessing
tail(predict(fit, test), 3)
# case 1: x as knots
z < predict(fit, test, x = "knots")
# case 2: x and y, one new group
predict(fit, test, x = "knots", y = c(1, 1, 0.5, 0))
# case 2: x and y, one new group, we need not specify new_data
predict(fit, x = "knots", y = c(1, 1, 0.5, 0))
# case 3: only group
predict(fit, test, group = c(11045, 11120, 999))
# case 4: predict at x in selected groups
predict(fit, test, x = c(0.5, 1, 1.25), group = c(11045, 11120, 999))
# case 5: vectorized
predict(fit, test, x = c(0.5, 1, 1.25), y = c(0, 0.5, 1), group = c(11045, 11120, 999))
# case 6: vectorized, without new_data, results are different for 11045 and 11120
predict(fit, x = c(0.5, 1, 1.25), y = c(0, 0.5, 1), group = c(11045, 11120, 999))

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.