www.gusucode.com > stats 源码程序 matlab案例代码 > stats/ComputeConfidenceIntervalsforRandomEffectsExample.m

    %% Compute Confidence Intervals for Random Effects  

%% 
% Load the sample data. 
load(fullfile(matlabroot,'examples','stats','shift.mat'))
%%
% The data shows the deviations from the target quality characteristic measured
% from the products that five operators manufacture during three shifts:
% morning, evening, and night. This is a randomized block design, where
% the operators are the blocks. The experiment is designed to study the
% impact of the time of shift on the performance. The performance measure
% is the deviation of the quality characteristics from the target value.
% This is simulated data.  

%% 
% |Shift| and |Operator| are nominal variables. 
shift.Shift = nominal(shift.Shift);
shift.Operator = nominal(shift.Operator);  

%% 
% Fit a linear mixed-effects model with a random intercept grouped by operator
% to assess if there is significant difference in the performance according
% to the time of the shift. 
lme = fitlme(shift,'QCDev ~ Shift + (1|Operator)');  

%% 
% Compute the estimate of the BLUPs for random effects. 
randomEffects(lme)  

%% 
% Compute the 95% confidence intervals for random effects. 
[~,reCI] = coefCI(lme)  

%% 
% Compute the 99% confidence intervals for random effects using the residuals
% method to determine the degrees of freedom. This is the default method. 
[~,reCI] = coefCI(lme,'Alpha',0.01)  

%% 
% Compute the 99% confidence intervals for random effects using the Satterthwaite
% approximation to determine the degrees of freedom. 
[~,reCI] = coefCI(lme,'Alpha',0.01,'DFMethod','satterthwaite') 

%%
% The Satterthwaite approximation might produce smaller |DF| values than
% the residual method. That is why these confidence intervals are larger
% than the previous ones computed using the residual method.