Navigate to a folder containing sample data.

Load the sample data.

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.

Generate random response values at the original design
points. Display the first five values.

ans =
114.8785
134.2018
154.2818
169.7554
84.6089

Load the sample data.

Fit a linear mixed-effects model, with a fixed-effects
for `Weight`

, and a random intercept grouped by `Model_Year`

.
First, store the data in a table.

Randomly generate responses using the original data.

Plot the original and the randomly generated responses
to see how they differ. Group them by model year.

Note that the simulated random response values for year 82 are
lower than the original data for that year. This might be due to a
lower simulated random effect for year 82 than the estimated random
effect in the original data.

Navigate to a folder containing sample data.

Load the sample data.

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.

Create a new dataset array with design values. The new
dataset array must have the same variables as the original dataset
array you use for fitting the model `lme`

.

Generate random responses at the new points.

ysim =
99.6006
101.9911
161.4026

Load the sample data.

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

First, prepare the design matrices for fitting the linear mixed-effects
model.

Now, fit the model using `fitlmematrix`

with
the defined design matrices and grouping variables.

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.

Generate random responses for the data in the new design
matrices.

ysim =
15.7416
10.6085
6.8796

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, fit the model.

Now, recreate the new random effects design, `Znew`

,
and the grouping variable design, `Gnew`

, using which
to predict the response values.

Generate random responses using the new design matrices.

ysim =
16.8280
10.4375
4.1027