# refit

**Class: **GeneralizedLinearMixedModel

Refit generalized linear mixed-effects model

## Description

## Input Arguments

`glme`

— Generalized linear mixed-effects model

`GeneralizedLinearMixedModel`

object

Generalized linear mixed-effects model, specified as a `GeneralizedLinearMixedModel`

object.
For properties and methods of this object, see `GeneralizedLinearMixedModel`

.

`ynew`

— New response vector

*n*-by-1 vector of scalar values

New response vector, specified as an *n*-by-1
vector of scalar values, where *n* is the number
of observations used to fit `glme`

.

For an observation *i* with prior weights *w _{i}^{p}* and
binomial size

*n*(when applicable), the response values

_{i}*y*contained in

_{i}`ynew`

can have the following values.Distribution | Permitted Values | Notes |
---|---|---|

`Binomial` |
$$\left\{0,\frac{1}{{w}_{i}^{p}{n}_{i}},\frac{2}{{w}_{i}^{p}{n}_{i}},.\dots ,1\right\}$$ | w and _{i}^{p}n are
integer values > 0_{i} |

`Poisson` |
$$\left\{0,\frac{1}{{w}_{i}^{p}},\frac{2}{{w}_{i}^{p}},\cdots ,1\right\}$$ | w is
an integer value > 0_{i}^{p} |

`Gamma` | (0,∞) | w ≥
0_{i}^{p} |

`InverseGaussian` | (0,∞) | w ≥
0_{i}^{p} |

`Normal` | (–∞,∞) | w ≥
0_{i}^{p} |

You can access the prior weights property *w _{i}^{p}* using
dot notation.

glme.ObservationInfo.Weights

**Data Types: **`single`

| `double`

## Output Arguments

`glmenew`

— Generalized linear mixed-effects model

`GeneralizedLinearMixedModel`

object

## Examples

### Refit Model to New Response Vector

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

$${\text{defects}}_{ij}\sim \text{Poisson}({\mu}_{ij})$$

This corresponds to the generalized linear mixed-effects model

$$\mathrm{log}({\mu}_{ij})={\beta}_{0}+{\beta}_{1}{\text{newprocess}}_{ij}+{\beta}_{2}{\text{time}\text{\_}\text{dev}}_{ij}+{\beta}_{3}{\text{temp}\text{\_}\text{dev}}_{ij}+{\beta}_{4}{\text{supplier}\text{\_}\text{C}}_{ij}+{\beta}_{5}{\text{supplier}\text{\_}\text{B}}_{ij}+{b}_{i},$$

where

$${\text{defects}}_{ij}$$ is the number of defects observed in the batch produced by factory $$i$$ during batch $$j$$.

$${\mu}_{ij}$$ is the mean number of defects corresponding to factory $$i$$ (where $$i=1,2,...,20$$) during batch $$j$$ (where $$j=1,2,...,5$$).

$${\text{newprocess}}_{ij}$$, $${\text{time}\text{\_}\text{dev}}_{ij}$$, and $${\text{temp}\text{\_}\text{dev}}_{ij}$$ are the measurements for each variable that correspond to factory $$i$$ during batch $$j$$. For example, $${\text{newprocess}}_{ij}$$ indicates whether the batch produced by factory $$i$$ during batch $$j$$ used the new process.

$${\text{supplier}\text{\_}\text{C}}_{ij}$$ and $${\text{supplier}\text{\_}\text{B}}_{ij}$$ 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$$.$${b}_{i}\sim N(0,{\sigma}_{b}^{2})$$ 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');

Use `random`

to simulate a new response vector from the fitted model.

rng(0,'twister'); % For reproducibility ynew = random(glme);

Refit the model using the new response vector.

glme = refit(glme,ynew)

glme = Generalized linear mixed-effects model fit by ML Model information: Number of observations 100 Fixed effects coefficients 6 Random effects coefficients 20 Covariance parameters 1 Distribution Poisson Link Log FitMethod Laplace Formula: defects ~ 1 + newprocess + time_dev + temp_dev + supplier + (1 | factory) Model fit statistics: AIC BIC LogLikelihood Deviance 469.24 487.48 -227.62 455.24 Fixed effects coefficients (95% CIs): Name Estimate SE tStat DF pValue {'(Intercept)'} 1.5738 0.18674 8.4276 94 4.0158e-13 {'newprocess' } -0.21089 0.2306 -0.91455 94 0.36277 {'time_dev' } -0.13769 0.77477 -0.17772 94 0.85933 {'temp_dev' } 0.24339 0.84657 0.2875 94 0.77436 {'supplier_C' } -0.12102 0.07323 -1.6526 94 0.10175 {'supplier_B' } 0.098254 0.066943 1.4677 94 0.14551 Lower Upper 1.203 1.9445 -0.66875 0.24696 -1.676 1.4006 -1.4375 1.9243 -0.26642 0.024381 -0.034662 0.23117 Random effects covariance parameters: Group: factory (20 Levels) Name1 Name2 Type Estimate {'(Intercept)'} {'(Intercept)'} {'std'} 0.46587 Group: Error Name Estimate {'sqrt(Dispersion)'} 1

## Tips

You can use

`refit`

and`random`

to conduct a simulated likelihood ratio test or parametric bootstrap.

## See Also

`GeneralizedLinearMixedModel`

| `fitted`

| `residuals`

| `designMatrix`

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

# Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)