Main Content

randomEffects

Class: GeneralizedLinearMixedModel

Estimates of random effects and related statistics

Description

B = randomEffects(glme) returns the estimates of the empirical Bayes predictors (EBPs) of random effects in the generalized linear mixed-effects model glme conditional on the estimated covariance parameters and the observed response.

example

[B,BNames] = randomEffects(glme) also returns the names of the coefficients, BNames. Each name corresponds to a coefficient in B.

[B,BNames,stats] = randomEffects(glme) also returns related statistics, stats, for the estimated EBPs of random effects in glme.

example

[B,BNames,stats] = randomEffects(glme,Name,Value) returns any of the above output arguments using additional options specified by one or more Name,Value pair arguments. For example, you can specify the confidence interval level, or the method for computing the approximate degrees of freedom.

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.

Significance level, specified as the comma-separated pair consisting of 'Alpha' and a scalar value in the range [0,1]. For a value α, the confidence level is 100 × (1 – α)%.

For example, for 99% confidence intervals, you can specify the confidence level as follows.

Example: 'Alpha',0.01

Data Types: single | double

Method for computing approximate degrees of freedom, specified as the comma-separated pair consisting of 'DFMethod' and one of the following.

ValueDescription
'residual'The degrees of freedom value is assumed to be constant and equal to np, where n is the number of observations and p is the number of fixed effects.
'none'The degrees of freedom is set to infinity.

Example: 'DFMethod','none'

Output Arguments

expand all

Estimated empirical Bayes predictors (EBPs) for the random effects in the generalized linear mixed-effects model glme, returned as a column vector. The EBPs in B are approximated by the mode of the empirical posterior distribution of the random effects given the estimated covariance parameters and the observed response.

Suppose glme has R grouping variables g1, g2, ..., gR, with levels m1, m2, ..., mR, respectively. Also suppose q1, q2, ..., qR are the lengths of the random-effects vectors that are associated with g1, g2, ..., gR, respectively. Then, B is a column vector of length q1*m1 + q2*m2 + ... + qR*mR.

randomEffects creates B by concatenating the empirical Bayes predictors of random-effects vectors corresponding to each level of each grouping variable as [g1level1; g1level2; ...; g1levelm1; g2level1; g2level2; ...; g2levelm2; ...; gRlevel1; gRlevel2; ...; gRlevelmR]'.

Names of random-effects coefficients in B, returned as a table.

Estimated empirical Bayes predictors (EBPs) and related statistics for the random effects in the generalized linear mixed-effects model glme, returned as a table. stats has one row for each of the random effects, and one column for each of the following statistics.

Column NameDescription
GroupGrouping variable associated with the random effect
LevelLevel within the grouping variable corresponding to the random effect
NameName of the random-effect coefficient
EstimateEmpirical Bayes predictor (EBP) of random effect
SEPredSquare root of the conditional mean squared error of prediction (CMSEP) given covariance parameters and response
tStatt-statistic for a test that the random-effects coefficient is equal to 0
DFEstimated degrees of freedom for the t-statistic
pValuep-value for the t-statistic
LowerLower limit of a 95% confidence interval for the random-effects coefficient
UpperUpper limit of a 95% confidence interval for the random-effects coefficient

randomEffects computes the confidence intervals using the conditional mean squared error of prediction (CMSEP) approach conditional on the estimated covariance parameters and the observed response. An alternative interpretation of the confidence intervals is that they are approximate Bayesian credible intervals conditional on the estimated covariance parameters and the observed response.

When fitting a GLME model using fitglme and one of the pseudo likelihood fit methods ('MPL' or 'REMPL'), randomEffects computes confidence intervals and related statistics based on the fitted linear mixed-effects model from the final pseudo likelihood iteration.

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');

Compute and display the names and estimated values of the empirical Bayes predictors (EBPs) for the random effects.

[B,BNames] = randomEffects(glme)
B = 20×1

    0.2913
    0.1542
   -0.2633
   -0.4257
    0.5453
   -0.1069
    0.3040
   -0.1653
   -0.1458
   -0.0816
      ⋮

BNames=20×3 table
       Group       Level          Name      
    ___________    ______    _______________

    {'factory'}    {'1' }    {'(Intercept)'}
    {'factory'}    {'2' }    {'(Intercept)'}
    {'factory'}    {'3' }    {'(Intercept)'}
    {'factory'}    {'4' }    {'(Intercept)'}
    {'factory'}    {'5' }    {'(Intercept)'}
    {'factory'}    {'6' }    {'(Intercept)'}
    {'factory'}    {'7' }    {'(Intercept)'}
    {'factory'}    {'8' }    {'(Intercept)'}
    {'factory'}    {'9' }    {'(Intercept)'}
    {'factory'}    {'10'}    {'(Intercept)'}
    {'factory'}    {'11'}    {'(Intercept)'}
    {'factory'}    {'12'}    {'(Intercept)'}
    {'factory'}    {'13'}    {'(Intercept)'}
    {'factory'}    {'14'}    {'(Intercept)'}
    {'factory'}    {'15'}    {'(Intercept)'}
    {'factory'}    {'16'}    {'(Intercept)'}
      ⋮

Each row of B contains the estimated EPB for the random-effects coefficient named in the corresponding row of Bnames. For example, the value –0.2633 in row 3 of B is the estimated EPB for '(Intercept)' for level '3' of factory.

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');

Compute and display the 99% confidence intervals for the random-effects coefficients.

[B,BNames,stats] = randomEffects(glme,'Alpha',0.01);
stats
stats = 
    RANDOM EFFECT COEFFICIENTS: DFMETHOD = 'RESIDUAL', ALPHA = 0.01

    Group              Level         Name                   Estimate     SEPred     tStat       DF    pValue       Lower       Upper  
    {'factory'}        {'1' }        {'(Intercept)'}          0.29131    0.19163      1.5202    94      0.13182    -0.21251    0.79514
    {'factory'}        {'2' }        {'(Intercept)'}          0.15423    0.19216     0.80259    94      0.42423      -0.351    0.65946
    {'factory'}        {'3' }        {'(Intercept)'}         -0.26325    0.21249     -1.2389    94      0.21846    -0.82191    0.29541
    {'factory'}        {'4' }        {'(Intercept)'}         -0.42568    0.21667     -1.9646    94     0.052408    -0.99534    0.14398
    {'factory'}        {'5' }        {'(Intercept)'}           0.5453    0.17963      3.0356    94    0.0031051    0.073019     1.0176
    {'factory'}        {'6' }        {'(Intercept)'}         -0.10692    0.20133    -0.53105    94      0.59664    -0.63625    0.42241
    {'factory'}        {'7' }        {'(Intercept)'}          0.30404    0.18397      1.6527    94      0.10173    -0.17964    0.78771
    {'factory'}        {'8' }        {'(Intercept)'}         -0.16527    0.20505    -0.80597    94      0.42229    -0.70438    0.37385
    {'factory'}        {'9' }        {'(Intercept)'}         -0.14577      0.203    -0.71806    94       0.4745    -0.67949    0.38795
    {'factory'}        {'10'}        {'(Intercept)'}        -0.081632    0.20256      -0.403    94      0.68786    -0.61419    0.45093
    {'factory'}        {'11'}        {'(Intercept)'}         0.014529    0.21421    0.067826    94      0.94607    -0.54866    0.57772
    {'factory'}        {'12'}        {'(Intercept)'}          0.17706    0.20721     0.85446    94      0.39502    -0.36774    0.72185
    {'factory'}        {'13'}        {'(Intercept)'}          0.24872    0.20522       1.212    94      0.22857    -0.29083    0.78827
    {'factory'}        {'14'}        {'(Intercept)'}          0.21145    0.20678      1.0226    94      0.30913    -0.33221    0.75511
    {'factory'}        {'15'}        {'(Intercept)'}           0.2777    0.20345       1.365    94      0.17552    -0.25719    0.81259
    {'factory'}        {'16'}        {'(Intercept)'}         -0.25175    0.22568     -1.1156    94      0.26746    -0.84509    0.34158
    {'factory'}        {'17'}        {'(Intercept)'}         -0.13507    0.22301    -0.60568    94      0.54619     -0.7214    0.45125
    {'factory'}        {'18'}        {'(Intercept)'}          -0.1627    0.22269    -0.73061    94      0.46684    -0.74817    0.42278
    {'factory'}        {'19'}        {'(Intercept)'}         -0.32083    0.23294     -1.3773    94      0.17168    -0.93325    0.29159
    {'factory'}        {'20'}        {'(Intercept)'}         0.058418    0.21481     0.27195    94      0.78626    -0.50635    0.62319

The first three columns of stats contain the group name, level, and random-effects coefficient name. Column 4 contains the estimated EBP of the random-effects coefficient. The last two columns of stats, Lower and Upper, contain the lower and upper bounds of the 99% confidence interval, respectively. For example, for the coefficient for '(Intercept)' for level 3 of factory, the estimated EBP is -0.26325, and the 99% confidence interval is [-0.82191,0.29541].

References

[1] Booth, J.G., and J.P. Hobert. “Standard Errors of Prediction in Generalized Linear Mixed Models.” Journal of the American Statistical Association, Vol. 93, 1998, pp. 262–272.