Load the sample data.

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 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, $$newproces{s}_{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.

Test if there is any significant difference between supplier C and supplier B.

The large $$p$$-value indicates that there is no significant difference between supplier C and supplier B at the 5% significance level. Here, `coefTest`

also returns the $$F$$-statistic, the numerator degrees of freedom, and the approximate denominator degrees of freedom.

Test if there is any significant difference between supplier A and supplier B.

If you specify the `'DummyVarCoding'`

name-value pair argument as `'effects'`

when fitting the model using `fitglme`

, then

$${\beta}_{A}+{\beta}_{B}+{\beta}_{C}=0,$$

where $${\beta}_{A}$$, $${\beta}_{B}$$, and $${\beta}_{C}$$ correspond to suppliers A, B, and C, respectively. $${\beta}_{A}$$ is the effect of A minus the average effect of A, B, and C. To determine the contrast matrix corresponding to a test between supplier A and supplier B,

$${\beta}_{B}-{\beta}_{A}={\beta}_{B}-(-{\beta}_{B}-{\beta}_{C})=2{\beta}_{B}+{\beta}_{C}.$$

From the output of `disp(glme)`

, column 5 of the contrast matrix corresponds to $${\beta}_{C}$$, and column 6 corresponds to $${\beta}_{B}$$. Therefore, the contrast matrix for this test is specified as `H = [0,0,0,0,1,2]`

.

The large $$p$$-value indicates that there is no significant difference between supplier A and supplier B at the 5% significance level.