Description

ypred = predict(lme,tblnew) returns
a vector of conditional predicted responses ypred from
the fitted linear mixed-effects model lme at the
values in the new table or dataset array tblnew.
Use a table or dataset array for predict if you
use a table or dataset array for fitting the model lme.

If a particular grouping variable in tblnew has
levels that are not in the original data, then the random effects
for that grouping variable do not contribute to the 'Conditional' prediction
at observations where the grouping variable has new levels.

ypred = predict(lme,Xnew,Znew) returns
a vector of conditional predicted responses ypred from
the fitted linear mixed-effects model lme at the
values in the new fixed- and random-effects design matrices, Xnew and Znew,
respectively. Znew can also be a cell array of
matrices. In this case, the grouping variable G is ones(n,1),
where n is the number of observations used in the
fit.

Use the matrix format for predict if using
design matrices for fitting the model lme.

ypred = predict(lme,Xnew,Znew,Gnew) returns
a vector of conditional predicted responses ypred from
the fitted linear mixed-effects model lme at the
values in the new fixed- and random-effects design matrices, Xnew and Znew,
respectively, and the grouping variable Gnew.

Znew and Gnew can also
be cell arrays of matrices and grouping variables, respectively.

New input data, which includes the response variable, predictor
variables, and grouping
variables, specified as a table or dataset array. The predictor
variables can be continuous or grouping variables. tblnew must
have the same variables as in the original table or dataset array
used to fit the linear mixed-effects model lme.

New fixed-effects design matrix, specified as an n-by-p matrix,
where n is the number of observations and p is
the number of fixed predictor variables. Each row of X corresponds
to one observation and each column of X corresponds
to one variable.

New random-effects design, specified as an n-by-q matrix
or a cell array of R design matrices Z{r},
where r = 1, 2, ..., R. If Znew is
a cell array, then each Z{r} is an n-by-q(r)
matrix, where n is the number of observations,
and q(r) is the number of random
predictor variables.

New grouping variable or variables, specified
as a vector or a cell array, of length R, of grouping
variables with the same levels or groups as the original grouping
variables used to fit the linear mixed-effects model lme.

Data Types: single | double | logical | char | cell

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments.
Name is the argument
name and Value is the corresponding
value. Name must appear
inside single quotes (' ').
You can specify several name and value pair
arguments in any order as Name1,Value1,...,NameN,ValueN.

Output Arguments

Predicted responses, returned as a vector. ypred can
contain the conditional or marginal responses, depending on the value
choice of the 'Conditional' name-value pair argument.
Conditional predictions include contributions from both fixed and
random effects.

Point-wise confidence intervals for the predicted values, returned
as a two-column matrix. The first column of yCI contains
the lower bounds, and the second column contains the upper bound.
By default, yCI contains the 95% confidence intervals
for the predictions. You can change the confidence level using the Alpha name-value
pair argument, make them simultaneous using the Simultaneous name-value
pair argument, and also make them for a new observation rather than
for the curve using the Prediction name-value
pair argument.

Examples

The dataset array includes data from a split-plot experiment,
where soil is divided into three blocks based on the soil type: sandy,
silty, and loamy. Each block is divided into five plots, where five
different types of tomato plants (cherry, heirloom, grape, vine, and
plum) are randomly assigned to these plots. The tomato plants in the
plots are then divided into subplots, where each subplot is treated
by one of four fertilizers. This is simulated data.

Store the data in a dataset array called ds,
for practical purposes, and define Tomato, Soil,
and Fertilizer as categorical variables.

Fit a linear mixed-effects model, where Fertilizer and Tomato are
the fixed-effects variables, and the mean yield varies by the block
(soil type), and the plots within blocks (tomato types within soil
types) independently.

The dataset array includes data from a split-plot experiment,
where soil is divided into three blocks based on the soil type: sandy,
silty, and loamy. Each block is divided into five plots, where five
different types of tomato plants (cherry, heirloom, grape, vine, and
plum) are randomly assigned to these plots. The tomato plants in the
plots are then divided into subplots, where each subplot is treated
by one of four fertilizers. This is simulated data.

Store the data in a dataset array called ds,
for practical purposes, and define Tomato, Soil,
and Fertilizer as categorical variables.

Fit a linear mixed-effects model, where Fertilizer and Tomato are
the fixed-effects variables, and the mean yield varies by the block
(soil type), and the plots within blocks (tomato types within soil
types) independently.

Fit a linear mixed-effects model for miles per gallon
(MPG), with fixed effects for acceleration, horsepower, and cylinders,
and potentially correlated random effects for intercept and acceleration
grouped by model year.

Create the design matrices that contain the data at which
to predict the response values. Xnew must have
three columns as in X. The first column must be
a column of 1s. And the values in the last two columns must correspond
to Acceleration and Horsepower,
respectively. The first column of Znew must be
a column of 1s, and the second column must contain the same Acceleration values
as in Xnew. The original grouping variable in G is
the model year. So, Gnew must contain values for
the model year. Note that Gnew must contain nominal
values.

Now, repeat the same for a linear mixed-effects model
with uncorrelated random-effects terms for intercept and acceleration.
First, change the original random effects design and the random effects
grouping variables. Then, refit the model.

Fit a linear mixed-effects model for miles per gallon
(MPG), with fixed effects for acceleration, horsepower, and cylinders,
and potentially correlated random effects for intercept and acceleration
grouped by model year. First, store the variables in a table.

tbl = table(MPG,Acceleration,Horsepower,Model_Year);

Now, fit the model using fitlme with
the defined design matrices and grouping variables.

which corresponds to the 'Conditional','true' name-value
pair argument.

The predicted marginal response is

y^Mar=Xβ^,

which corresponds to the 'Conditional','false' name-value
pair argument.

When making predictions, if a particular grouping variable has
new levels (1s that were not in the original data), then the random
effects for the grouping variable do not contribute to the 'Conditional' prediction
at observations where the grouping variable has new levels.