www.gusucode.com > stats 源码程序 matlab案例代码 > stats/SatterthwaiteApproximationforDegreesofFreedomExample.m
%% Satterthwaite Approximation for Degrees of Freedom %% % Load the sample data. load(fullfile(matlabroot,'examples','stats','weight.mat')) %% % |weight| contains data from a longitudinal study, where 20 subjects are % randomly assigned 4 exercise programs, and their weight loss is recorded % over six 2-week time periods. This is simulated data. %% % Store the data in a table. Define |Subject| and |Program| as categorical % variables. tbl = table(InitialWeight,Program,Subject,Week,y); tbl.Subject = nominal(tbl.Subject); tbl.Program = nominal(tbl.Program); %% % Fit the model using the |'effects'| contrasts. lme = fitlme(tbl,'y ~ InitialWeight + Program*Week + (Week|Subject)',... 'DummyVarCoding','effects') %% % The $p$-values 0.022863 and 4.1099e-08 indicate significant effects of % the initial weights of the subjects and the time factor in the amount % of weight lost. The weight loss of subjects who are in program B is significantly % different relative to the weight loss of subjects that are in program % A. The lower and upper limits of the covariance parameters for the random % effects do not include zero, thus they are significant. %% % Perform an F-test that all fixed-effects coefficients are zero. anova(lme) %% % The $p$-values for the constant term, initial weight, and week are the % same as in the coefficient table in the previous |lme| output display. % The $p$-value of 0.014286 for |Program| represents the combined significance % for all program coefficients. Similarly, the $p$-value for the interaction % between program and week (|Program:Week|) measures the combined significance % for all coefficients representing this interaction. %% % Now, use the Satterthwaite method to compute the degrees of freedom. anova(lme,'DFMethod','satterthwaite') %% % The Satterthwaite method produces smaller denominator degrees of freedom % and slightly larger $p$-values.