STA429/1007 F 2004 Handout 8
Mixed and Random Effects, nesting (Bread and Health data)
/************* bread.sas ************************ Subsampling Example from NKNW Ch. 28 (Table 28.9) **************************************************/ title 'Nested mixed model: Bread data'; options linesize=79 pagesize=35 noovp formdlim=' '; proc format; /* value labels used in data step below */ value tempfmt 1 = 'Low' 2 = 'Medium' 3 = 'High'; data school; infile 'bread.dat'; input temp batch crusty; label crusty = 'Crustiness of bread'; format temp tempfmt.; proc glm; title2 'Classical F-tests with proc glm'; class temp batch; model crusty = temp batch(temp); /* batch(temp) = batch within temp */ random batch(temp) / test; /* batch(temp) is a random effect. Test it. */ means temp batch(temp); proc varcomp method=type1; /* Just Expected Mean Squares */ title2 'Estimate variance components: Expected Mean Squares '; class temp batch; model crusty = temp batch(temp) / fixed=1; /* One fixed effect (Any fixed effects are first) */ proc varcomp method=ML; /* Maximum Likelihood */ title2 'Maximum Likelihood Estimates of variance components'; class temp batch; model crusty = temp batch(temp) / fixed=1;
Here is bread.lst
Nested mixed model: Bread data 1 Classical F-tests with proc glm 14:29 Sunday, October 24, 2004 The GLM Procedure Class Level Information Class Levels Values temp 3 High Low Medium batch 2 1 2 Number of observations 18 Nested mixed model: Bread data 2 Classical F-tests with proc glm 14:29 Sunday, October 24, 2004 The GLM Procedure Dependent Variable: crusty Crustiness of bread Sum of Source DF Squares Mean Square F Value Pr > F Model 5 284.4444444 56.8888889 21.79 <.0001 Error 12 31.3333333 2.6111111 Corrected Total 17 315.7777778 R-Square Coeff Var Root MSE crusty Mean 0.900774 13.59163 1.615893 11.88889 Source DF Type I SS Mean Square F Value Pr > F temp 2 235.4444444 117.7222222 45.09 <.0001 batch(temp) 3 49.0000000 16.3333333 6.26 0.0084 Source DF Type III SS Mean Square F Value Pr > F temp 2 235.4444444 117.7222222 45.09 <.0001 batch(temp) 3 49.0000000 16.3333333 6.26 0.0084 Nested mixed model: Bread data 3 Classical F-tests with proc glm 14:29 Sunday, October 24, 2004 The GLM Procedure Source Type III Expected Mean Square temp Var(Error) + 3 Var(batch(temp)) + Q(temp) batch(temp) Var(Error) + 3 Var(batch(temp)) Nested mixed model: Bread data 4 Classical F-tests with proc glm 14:29 Sunday, October 24, 2004 The GLM Procedure Tests of Hypotheses for Mixed Model Analysis of Variance Dependent Variable: crusty Crustiness of bread Source DF Type III SS Mean Square F Value Pr > F temp 2 235.444444 117.722222 7.21 0.0715 Error 3 49.000000 16.333333 Error: MS(batch(temp)) Source DF Type III SS Mean Square F Value Pr > F batch(temp) 3 49.000000 16.333333 6.26 0.0084 Error: MS(Error) 12 31.333333 2.611111 Nested mixed model: Bread data 5 Classical F-tests with proc glm 14:29 Sunday, October 24, 2004 Level of ------------crusty----------- temp N Mean Std Dev High 6 16.5000000 1.87082869 Low 6 7.6666667 3.01109061 Medium 6 11.5000000 1.87082869 Level of Level of ------------crusty----------- batch temp N Mean Std Dev 1 High 3 15.3333333 1.52752523 2 High 3 17.6666667 1.52752523 1 Low 3 5.3333333 1.52752523 2 Low 3 10.0000000 2.00000000 1 Medium 3 12.6666667 1.52752523 2 Medium 3 10.3333333 1.52752523 Nested mixed model: Bread data 6 Estimate variance components: Expected Mean Squares 14:29 Sunday, October 24, 2004 Variance Components Estimation Procedure Class Level Information Class Levels Values temp 3 High Low Medium batch 2 1 2 Number of observations 18 Dependent Variable: crusty Type 1 Analysis of Variance Sum of Source DF Squares Mean Square temp 2 235.444444 117.722222 Type 1 Analysis of Variance Source Expected Mean Square temp Var(Error) + 3 Var(batch(temp)) + Q(temp) Nested mixed model: Bread data 7 Estimate variance components: Expected Mean Squares 14:29 Sunday, October 24, 2004 Variance Components Estimation Procedure Type 1 Analysis of Variance Sum of Source DF Squares Mean Square batch(temp) 3 49.000000 16.333333 Error 12 31.333333 2.611111 Corrected Total 17 315.777778 . Type 1 Analysis of Variance Source Expected Mean Square batch(temp) Var(Error) + 3 Var(batch(temp)) Error Var(Error) Corrected Total . Type 1 Estimates Variance Component Estimate Var(batch(temp)) 4.57407 Var(Error) 2.61111 Nested mixed model: Bread data 8 Maximum Likelihood Estimates of variance components 14:29 Sunday, October 24, 2004 Variance Components Estimation Procedure Class Level Information Class Levels Values temp 3 High Low Medium batch 2 1 2 Number of observations 18 Dependent Variable: crusty Maximum Likelihood Iterations Var(batch Iteration Objective (temp)) Var(Error) 0 24.9947701601 3.8117283951 2.1759259259 1 24.1609121270 2.1819629992 2.4911480395 2 24.1177557504 1.8652543177 2.6055996112 3 24.1176751083 1.8517086457 2.6111703288 4 24.1176750991 1.8518518356 2.6111111178 Nested mixed model: Bread data 9 Maximum Likelihood Estimates of variance components 14:29 Sunday, October 24, 2004 Variance Components Estimation Procedure Convergence criteria met. Maximum Likelihood Estimates Variance Component Estimate Var(batch(temp)) 1.85185 Var(Error) 2.61111 Asymptotic Covariance Matrix of Estimates Var(batch(temp)) Var(Error) Var(batch(temp)) 2.59642 -0.37877 Var(Error) -0.37877 1.13632
/************* health.sas ************************ Subsampling Example from NWK prob 26.11 **************************************************/ title 'Pure random effects with subsampling: Health Awareness data'; options linesize=79 pagesize=35 noovp formdlim=' '; data final; infile 'health.dat'; input state city househld aware; proc glm; title2 'Classical F-test with proc glm'; class state city; model aware = state city(state); random state city(state) / test; proc varcomp method=type1; /* Expected Mean Squares */ title2 'Estimate variance components: Expected Mean Squares '; class state city; model aware = state city(state); proc varcomp method=ML; /* Maximum Likelihood */ title2 'Maximum Likelihood Estimates of variance components'; class state city; model aware = state city(state); proc sort; /* May be needed by proc nested */ by state city; proc nested; title2 'Estimate % of variance with proc nested'; class state city; /* Assume all IVs random and nested in order given */ var aware; /* Just name the DV(s) */
Here is health.lst.
Pure random effects with subsampling: Health Awareness data 1 Classical F-test with proc glm 14:36 Sunday, October 24, 2004 The GLM Procedure Class Level Information Class Levels Values state 3 1 2 3 city 3 1 2 3 Number of observations 45 Pure random effects with subsampling: Health Awareness data 2 Classical F-test with proc glm 14:36 Sunday, October 24, 2004 The GLM Procedure Dependent Variable: aware Sum of Source DF Squares Mean Square F Value Pr > F Model 8 7144.44444 893.05556 8.26 <.0001 Error 36 3893.20000 108.14444 Corrected Total 44 11037.64444 R-Square Coeff Var Root MSE aware Mean 0.647280 24.94490 10.39925 41.68889 Source DF Type I SS Mean Square F Value Pr > F state 2 6976.844444 3488.422222 32.26 <.0001 city(state) 6 167.600000 27.933333 0.26 0.9526 Source DF Type III SS Mean Square F Value Pr > F state 2 6976.844444 3488.422222 32.26 <.0001 city(state) 6 167.600000 27.933333 0.26 0.9526 Pure random effects with subsampling: Health Awareness data 3 Classical F-test with proc glm 14:36 Sunday, October 24, 2004 The GLM Procedure Source Type III Expected Mean Square state Var(Error) + 5 Var(city(state)) + 15 Var(state) city(state) Var(Error) + 5 Var(city(state)) Pure random effects with subsampling: Health Awareness data 4 Classical F-test with proc glm 14:36 Sunday, October 24, 2004 The GLM Procedure Tests of Hypotheses for Random Model Analysis of Variance Dependent Variable: aware Source DF Type III SS Mean Square F Value Pr > F state 2 6976.844444 3488.422222 124.88 <.0001 Error 6 167.600000 27.933333 Error: MS(city(state)) Source DF Type III SS Mean Square F Value Pr > F city(state) 6 167.600000 27.933333 0.26 0.9526 Error: MS(Error) 36 3893.200000 108.144444 Pure random effects with subsampling: Health Awareness data 5 Estimate variance components: Expected Mean Squares 14:36 Sunday, October 24, 2004 Variance Components Estimation Procedure Class Level Information Class Levels Values state 3 1 2 3 city 3 1 2 3 Number of observations 45 Dependent Variable: aware Type 1 Analysis of Variance Sum of Source DF Squares Mean Square state 2 6976.844444 3488.422222 Type 1 Analysis of Variance Source Expected Mean Square state Var(Error) + 5 Var(city(state)) + 15 Var(state) Pure random effects with subsampling: Health Awareness data 6 Estimate variance components: Expected Mean Squares 14:36 Sunday, October 24, 2004 Variance Components Estimation Procedure Type 1 Analysis of Variance Sum of Source DF Squares Mean Square city(state) 6 167.600000 27.933333 Error 36 3893.200000 108.144444 Corrected Total 44 11038 . Type 1 Analysis of Variance Source Expected Mean Square city(state) Var(Error) + 5 Var(city(state)) Error Var(Error) Corrected Total . Type 1 Estimates Variance Component Estimate Var(state) 230.69926 Var(city(state)) -16.04222 Var(Error) 108.14444 Pure random effects with subsampling: Health Awareness data 7 Maximum Likelihood Estimates of variance components 14:36 Sunday, October 24, 2004 Variance Components Estimation Procedure Class Level Information Class Levels Values state 3 1 2 3 city 3 1 2 3 Number of observations 45 Dependent Variable: aware Maximum Likelihood Iterations Var(city Iteration Objective Var(state) (state)) Var(Error) 0 215.3846762821 202.5274227843 0 94.9383872844 1 215.2568105655 149.3097905207 0 96.6541361806 2 215.2567768466 148.5955055944 0 96.6857039721 3 215.2567768466 148.5955055944 0 96.6857039721 Convergence criteria met. Pure random effects with subsampling: Health Awareness data 8 Maximum Likelihood Estimates of variance components 14:36 Sunday, October 24, 2004 Variance Components Estimation Procedure Maximum Likelihood Estimates Variance Component Estimate Var(state) 148.59551 Var(city(state)) 0 Var(Error) 96.68570 Asymptotic Covariance Matrix of Estimates Var(state) Var(city(state)) Var(Error) Var(state) 16027.2 0 -29.67765 Var(city(state)) 0 0 0 Var(Error) -29.67765 0 445.14883 Pure random effects with subsampling: Health Awareness data 9 Estimate % of variance with proc nested 21:10 Sunday, October 24, 2004 The NESTED Procedure Coefficients of Expected Mean Squares Source state city Error state 15 5 1 city 0 5 1 Error 0 0 1 Nested Random Effects Analysis of Variance for Variable aware Variance Sum of Error Source DF Squares F Value Pr > F Term Total 44 11038 state 2 6976.844444 124.88 <.0001 city city 6 167.600000 0.26 0.9526 Error Nested Random Effects Analysis of Variance for Variable aware Variance Variance Percent Source Mean Square Component of Total Total 250.855556 338.843704 100.0000 state 3488.422222 230.699259 68.0843 city 27.933333 -16.042222 0.0000 Pure random effects with subsampling: Health Awareness data 10 Estimate % of variance with proc nested 21:10 Sunday, October 24, 2004 The NESTED Procedure Nested Random Effects Analysis of Variance for Variable aware Variance Sum of Error Source DF Squares F Value Pr > F Term Error 36 3893.200000 Nested Random Effects Analysis of Variance for Variable aware Variance Variance Percent Source Mean Square Component of Total Error 108.144444 108.144444 31.9157 aware Mean 41.68888889 Standard Error of aware Mean 8.80457233