Main Content

fitted

Class: GeneralizedLinearMixedModel

Fitted responses from generalized linear mixed-effects model

Description

mufit = fitted(glme) returns the fitted conditional response of the generalized linear mixed-effects model glme.

example

mufit = fitted(glme,Name,Value) returns the fitted response with additional options specified by one or more name-value pair arguments. For example, you can specify to compute the marginal fitted response.

Input Arguments

expand all

Generalized linear mixed-effects model, specified as a GeneralizedLinearMixedModel object. For properties and methods of this object, see GeneralizedLinearMixedModel.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Indicator for conditional response, specified as the comma-separated pair consisting of 'Conditional' and one of the following.

ValueDescription
trueContributions from both fixed effects and random effects (conditional)
falseContribution from only fixed effects (marginal)

To obtain fitted marginal response values, fitted computes the conditional mean of the response with the empirical Bayes predictor vector of random effects b set equal to 0. For more information, see Conditional and Marginal Response

Example: 'Conditional',false

Output Arguments

expand all

Fitted response values, returned as an n-by-1 vector, where n is the number of observations.

Examples

expand all

Load the sample data.

load mfr

This simulated data is from a manufacturing company that operates 50 factories across the world, with each factory running a batch process to create a finished product. The company wants to decrease the number of defects in each batch, so it developed a new manufacturing process. To test the effectiveness of the new process, the company selected 20 of its factories at random to participate in an experiment: Ten factories implemented the new process, while the other ten continued to run the old process. In each of the 20 factories, the company ran five batches (for a total of 100 batches) and recorded the following data:

  • Flag to indicate whether the batch used the new process (newprocess)

  • Processing time for each batch, in hours (time)

  • Temperature of the batch, in degrees Celsius (temp)

  • Categorical variable indicating the supplier (A, B, or C) of the chemical used in the batch (supplier)

  • Number of defects in the batch (defects)

The data also includes time_dev and temp_dev, which represent the absolute deviation of time and temperature, respectively, from the process standard of 3 hours at 20 degrees Celsius.

Fit a generalized linear mixed-effects model using newprocess, time_dev, temp_dev, and supplier as fixed-effects predictors. Include a random-effects term for intercept grouped by factory, to account for quality differences that might exist due to factory-specific variations. The response variable defects has a Poisson distribution, and the appropriate link function for this model is log. Use the Laplace fit method to estimate the coefficients. Specify the dummy variable encoding as 'effects', so the dummy variable coefficients sum to 0.

The number of defects can be modeled using a Poisson distribution

defectsijPoisson(μij)

This corresponds to the generalized linear mixed-effects model

log(μij)=β0+β1newprocessij+β2time_devij+β3temp_devij+β4supplier_Cij+β5supplier_Bij+bi,

where

  • defectsij is the number of defects observed in the batch produced by factory i during batch j.

  • μij is the mean number of defects corresponding to factory i (where i=1,2,...,20) during batch j (where j=1,2,...,5).

  • newprocessij, time_devij, and temp_devij are the measurements for each variable that correspond to factory i during batch j. For example, newprocessij indicates whether the batch produced by factory i during batch j used the new process.

  • supplier_Cij and supplier_Bij are dummy variables that use effects (sum-to-zero) coding to indicate whether company C or B, respectively, supplied the process chemicals for the batch produced by factory i during batch j.

  • biN(0,σb2) is a random-effects intercept for each factory i that accounts for factory-specific variation in quality.

glme = fitglme(mfr,'defects ~ 1 + newprocess + time_dev + temp_dev + supplier + (1|factory)', ...
    'Distribution','Poisson','Link','log','FitMethod','Laplace','DummyVarCoding','effects');

Generate the fitted conditional mean values for the model.

mufit = fitted(glme);

Create a scatterplot of the observed values versus fitted values.

figure
scatter(mfr.defects,mufit)
title('Residuals versus Fitted Values')
xlabel('Fitted Values')
ylabel('Residuals')

Figure contains an axes object. The axes object with title Residuals versus Fitted Values, xlabel Fitted Values, ylabel Residuals contains an object of type scatter.

More About

expand all