Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bread Example: nknw817.sas Y = number of cases of bread sold (sales) Factor A = height of shelf display (bottom, middle, top) Factor B = width of shelf.

Similar presentations


Presentation on theme: "Bread Example: nknw817.sas Y = number of cases of bread sold (sales) Factor A = height of shelf display (bottom, middle, top) Factor B = width of shelf."— Presentation transcript:

1 Bread Example: nknw817.sas Y = number of cases of bread sold (sales) Factor A = height of shelf display (bottom, middle, top) Factor B = width of shelf display (regular, wide) n = 2 (n T = 12)

2 Bread Example: input data bread; infile 'I:\My Documents\Stat 512\CH19TA07.DAT'; input sales height width; proc print data=bread; run; title1 h=3 'Bread Sales'; axis1 label=(h=2); axis2 label=(h=2 angle=90); Obssalesheightwidth 14711 24311 34612 44012 56221 66821 76722 87122 94131 103931 114232 124632

3 Bread Example: input scatterplot data bread; set bread; if height eq 1 and width eq 1 then hw='1_BR'; if height eq 1 and width eq 2 then hw='2_BW'; if height eq 2 and width eq 1 then hw='3_MR'; if height eq 2 and width eq 2 then hw='4_MW'; if height eq 3 and width eq 1 then hw='5_TR'; if height eq 3 and width eq 2 then hw='6_TW'; title2 h=2 'Sales vs. treatment'; symbol1 v=circle i=none c=blue; proc gplot data=bread; plot sales*hw/haxis=axis1 vaxis=axis2; run;

4 Bread Example: Scatterplot

5 Bread Example: ANOVA proc glm data=bread; class height width; model sales=height width height*width; means height width height*width; output out=diag r=resid p=pred; run; Class Level Information ClassLevelsValues height31 2 3 width21 2 Number of Observations Read12 Number of Observations Used12

6 Bread Example: ANOVA means Level of height N sales MeanStd Dev 1444.00000003.16227766 2467.00000003.74165739 3442.00000002.94392029 Level of width N sales MeanStd Dev 1650.000000012.0664825 2652.000000013.4313067 Level of height Level of width N sales MeanStd Dev 11245.00000002.82842712 12243.00000004.24264069 21265.00000004.24264069 22269.00000002.82842712 31240.00000001.41421356 32244.00000002.82842712

7 Bread Example: Means proc means data=bread; var sales; by height width; output out=avbread mean=avsales; proc print data=avbread; run; Obsheightwidth_TYPE__FREQ_avsales 1110245 2120243 3210265 4220269 5310240 6320244

8 ANOVA Table – One Way Source of Variation dfSSMS Model (Regression) r – 1 Errorn T – r Totaln T – 1

9 ANOVA Table – Two Way Source of Variation dfSSMS Factor Aa – 1 Factor Bb – 1 Interaction (AB) (a–1)(b–1) Errorab(n – 1) Totalnab – 1

10 Bread Example: Scatterplot

11 Bread Example: diagnostics proc glm data=bread; class height width; model sales=height width height*width; means height width height*width; output out=diag r=resid p=pred run; title2 h=2 'residual plots'; proc gplot data=diag; plot resid * (pred height width)/vref=0 haxis=axis1 vaxis=axis2; run; title2 'normality'; proc univariate data=diag noprint; histogram resid/normal kernel; qqplot resid/normal (mu=est sigma=est); run;

12 Bread Example: Residual Plots

13 Bread Example: Normality

14 ANOVA Table – Two Way Source of Variation dfSSMSF Modelab - 1SSMSSM/df M MSM/MSE Errorab(n – 1)SSESSE/df E Totalnab – 1SST Factor Aa – 1SSASSA/df A MSA/MSE Factor Bb – 1SSBSSB/df B MSB/MSE Interaction (AB) (a–1)(b–1)SSABSSAB/df AB MSAB/MSE

15 Strategy for Analysis

16 Bread Example: nknw817.sas Y = number of cases of bread sold (sales) Factor A = height of shelf display (bottom, middle, top) Factor B = width of shelf display (regular, wide) n = 2 (n T = 12) Questions: 1)Does the height of the display affect sales? 2)Does the width of the display affect sales? 3)Does the effect on height on sales depend on width? 4)Does the effect of the width depend on height?

17 Bread Example: Interaction Plots title2 'Interaction Plot'; symbol1 v=square i=join c=black; symbol2 v=diamond i=join c=red; symbol3 v=circle i=join c=blue; proc gplot data=avbread; plot avsales*height=width/haxis=axis1 vaxis=axis2; plot avsales*width=height/haxis=axis1 vaxis=axis2; run;

18 Bread Example: Interaction Plots (cont)

19 Bread Example: ANOVA table proc glm data=bread; class height width; model sales=height width height*width; means height width height*width; output out=diag r=resid p=pred; run; SourceDFSum of SquaresMean SquareF ValuePr > F Model51580.000000316.00000030.580.0003 Error662.00000010.333333 Corrected Total111642.000000

20 Bread Example: ANOVA table SourceDFType I SSMean SquareF ValuePr > F height21544.000000772.00000074.71<.0001 width112.000000 1.160.3226 height*width224.00000012.0000001.160.3747 SourceDFType III SSMean SquareF ValuePr > F height21544.000000772.00000074.71<.0001 width112.000000 1.160.3226 height*width224.00000012.0000001.160.3747 R-SquareCoeff VarRoot MSEsales Mean 0.9622416.3030403.21455051.00000

21 Bread Example: Interaction Plots (cont)

22 Bread Example: cell means model (MSE) proc glm data=bread; class height width; model sales=height width height*width; means height width height*width; output out=diag r=resid p=pred; run; SourceDFSum of SquaresMean SquareF ValuePr > F Model51580.000000316.00000030.580.0003 Error662.00000010.333333 Corrected Total111642.000000

23 Bread Example: cell means model proc glm data=bread; class height width; model sales=height width height*width; means height width height*width; output out=diag r=resid p=pred; run; Level of height Level of width N sales MeanStd Dev 11245.00000002.82842712 12243.00000004.24264069 21265.00000004.24264069 22269.00000002.82842712 31240.00000001.41421356 32244.00000002.82842712

24 Bread Example: factor effects model (overall mean) SourceDFType I SSMean SquareF ValuePr > F height21544.000000772.00000074.71<.0001 width112.000000 1.160.3226 height*width224.00000012.0000001.160.3747 SourceDFType III SSMean SquareF ValuePr > F height21544.000000772.00000074.71<.0001 width112.000000 1.160.3226 height*width224.00000012.0000001.160.3747 R-SquareCoeff VarRoot MSEsales Mean 0.9622416.3030403.21455051.00000

25 Bread Example: factor effects model (overall mean) (cont) proc glm data=bread; class height width; model sales=; output out=pmu p=muhat; proc print data=pmu;run; Obssalesheightwidthhwmuhat 147111_BR51 243111_BR51 346122_BW51 440122_BW51 562213_MR51 668213_MR51 767224_MW51 871224_MW51 941315_TR51 1039315_TR51 1142326_TW51 1246326_TW51

26 Bread Example: ANOVA means A (height) Level of height N sales MeanStd Dev 1444.00000003.16227766 2467.00000003.74165739 3442.00000002.94392029

27 Bread Example: means A (cont) proc glm data=bread; class height width; model sales=height; output out=pA p=Amean; proc print data = pA; run; ObssalesheightwidthhwAmean 147111_BR44 243111_BR44 346122_BW44 440122_BW44 562213_MR67 668213_MR67 7 224_MW67 871224_MW67 941315_TR42 1039315_TR42 1142326_TW42 1246326_TW42

28 Bread Example: ANOVA means B (width) Level of width N sales MeanStd Dev 1650.000000012.0664825 2652.000000013.4313067

29 Bread Example: ANOVA means Level of height N sales MeanStd Dev 1444.00000003.16227766 2467.00000003.74165739 3442.00000002.94392029 Level of width N sales MeanStd Dev 1650.000000012.0664825 2652.000000013.4313067 Level of height Level of width N sales MeanStd Dev 11245.00000002.82842712 12243.00000004.24264069 21265.00000004.24264069 22269.00000002.82842712 31240.00000001.41421356 32244.00000002.82842712

30 Bread Example: Factor Effects Model (zero-sum constraints) title2 'overall mean'; proc glm data=bread; class height width; model sales=; output out=pmu p=muhat; proc print data=pmu; run; title2 'mean for height'; proc glm data=bread; class height width; model sales=height; output out=pA p=Amean; proc print data = pA; run; title2 'mean for width'; proc glm data=bread; class height width; model sales=width; output out=pB p=Bmean; run; title2 'mean height/ width'; proc glm data=bread; class height width; model sales=height*width; output out=pAB p=ABmean; run; data parmest; merge bread pmu pA pB pAB; alpha=Amean-muhat; beta=Bmean-muhat; alphabeta=ABmean- (muhat+alpha+beta); run; proc print;run;

31 Bread Example: Factor Effects Model (zero-sum constraints) (cont) ObssalesheightwidthhwmuhatAmeanBmeanABmean  147111_BR51445045-72 243111_BR51445045-72 346122_BW51445243-71-2 440122_BW51445243-71-2 562213_MR5167506516 668213_MR5167506516 767224_MW516752691611 871224_MW516752691611 941315_TR51425040-9 1039315_TR51425040-9 1142326_TW51425244-911 1246326_TW51425244-911

32 Bread Example: nknw817b.sas Y = number of cases of bread sold (sales) Factor A = height of shelf display (bottom, middle, top) Factor B = width of shelf display (regular, wide) n = 2 (n T = 12 = 3 x 2)

33 Bread Example: SAS constraints proc glm data=bread; class height width; model sales=height width height*width/solution; means height*width; run;

34 Bread Example: SAS constraints (cont) ParameterEstimateStandard Errort ValuePr > |t| Intercept44.00000000B2.2730302819.36<.0001 height 1B3.21455025-0.310.7663 height 225.00000000B3.214550257.780.0002 height 30.00000000B... width 1-4.00000000B3.21455025-1.240.2598 width 20.00000000B... height*width 1 16.00000000B4.546060571.320.2350 height*width 1 20.00000000B... height*width 2 1-0.00000000B4.54606057-0.001.0000 height*width 2 20.00000000B... height*width 3 10.00000000B... height*width 3 20.00000000B...

35 Bread Example: Means Level of height Level of width N sales MeanStd Dev 11245.00000002.82842712 12243.00000004.24264069 21265.00000004.24264069 22269.00000002.82842712 31240.00000001.41421356 32244.00000002.82842712

36 Bread Example: nknw817b.sas Y = number of cases of bread sold (sales) Factor A = height of shelf display (bottom, middle, top) Factor B = width of shelf display (regular, wide) n = 2 (n T = 12 = 3 x 2)

37 Bread Example: Pooling *factor effects model, SAS constraints, without pooling; proc glm data=bread; class height width; model sales=height width height*width; means height/tukey lines; run; *with pooling; proc glm data=bread; class height width; model sales=height width; means height / tukey lines; run;

38 Bread Example: Pooling (cont) SourceDFSum of SquaresMean SquareF ValuePr > F Model51580.000000316.00000030.580.0003 Error662.00000010.333333 Corrected Total111642.000000 SourceDFType I SSMean SquareF ValuePr > F height21544.000000772.00000074.71<.0001 width112.000000 1.160.3226 height*width224.00000012.0000001.160.3747 SourceDFSum of SquaresMean SquareF ValuePr > F Model31556.000000518.66666748.25<.0001 Error886.00000010.750000 Corrected Total111642.000000 SourceDFType I SSMean SquareF ValuePr > F height21544.000000772.00000071.81<.0001 width112.000000 1.120.3216

39 Bread Example: Pooling (cont) Means with the same letter are not significantly different. Tukey GroupingMeanNheight A67.00042 B44.00041 B B42.00043 Means with the same letter are not significantly different. Tukey GroupingMeanNheight A67.00042 B44.00041 B B42.00043

40 Bread Example: ANOVA table/Means SourceDFSum of SquaresMean SquareF ValuePr > F Model51580.000000316.00000030.580.0003 Error662.00000010.333333 Corrected Total111642.000000 Level of height Level of width N sales MeanStd Dev 11245.00000002.82842712 12243.00000004.24264069 21265.00000004.24264069 22269.00000002.82842712 31240.00000001.41421356 32244.00000002.82842712 Level of height N sales MeanStd Dev 1444.00000003.16227766 2467.00000003.74165739 3442.00000002.94392029

41 Bread Example (nknw864.sas): contrasts and estimates proc glm data=bread; class height width; model sales=height width height*width; contrast 'middle vs others' height -.5 1 -.5 height*width -.25 -.25.5.5 -.25 -.25; estimate 'middle vs others' height -.5 1 -.5 height*width -.25 -.25.5.5 -.25 -.25; means height*width; run; ContrastDFContrast SSMean SquareF ValuePr > F middle vs others11536.000000 148.65<.0001 ParameterEstimateStandard Errort ValuePr > |t| middle vs others24.00000001.9685019712.19<.0001

42 Bread Example (nknw864.sas): contrasts and estimates (cont) Level of height Level of width N sales MeanStd Dev 11245.00000002.82842712 12243.00000004.24264069 21265.00000004.24264069 22269.00000002.82842712 31240.00000001.41421356 32244.00000002.82842712

43 ANOVA Table – Two Way, n = 1 Source of Variation dfSSMSF Factor Aa – 1SSASSA/df A MSA/MSE Factor Bb – 1SSBSSB/df B MSB/MSE Error(a – 1)(b – 1)SSESSE/df E Totalab – 1SST

44 Car Insurance Example: (nknw878.sas) Y = 3-month premium for car insurance Factor A = size of the city small, medium, large Factor B = geographic region east, west

45 Car Insurance: input data carins; infile 'I:\My Documents\Stat 512\CH20TA02.DAT'; input premium size region; if size=1 then sizea='1_small '; if size=2 then sizea='2_medium'; if size=3 then sizea='3_large '; proc print data=carins; run; Obspremiumsizeregionsizea 1140111_small 2100121_small 3210212_medium 4180222_medium 5220313_large 6200323_large

46 Car Insurance: Scatterplot symbol1 v='E' i=join c=green height=1.5; symbol2 v='W' i=join c=blue height=1.5; title1 h=3 'Scatterplot of the Car Insurance'; proc gplot data=carins; plot premium*sizea=region/haxis=axis1 vaxis=axis2; run;

47 Car Insurance: ANOVA proc glm data=carins; class sizea region; model premium=sizea region/solution; means sizea region / tukey; output out=preds p=muhat; run; proc print data=preds; run; Class Level Information ClassLevelsValues sizea31_small 2_medium 3_large region21 2 Number of Observations Read6 Number of Observations Used6

48 Car Insurance: ANOVA (cont) SourceDFSum of SquaresMean SquareF ValuePr > F Model310650.000003550.0000071.000.0139 Error2100.0000050.00000 Corrected Total510750.00000 R-SquareCoeff VarRoot MSEpremium Mean 0.9906984.0406107.071068175.0000 SourceDFType I SSMean SquareF ValuePr > F sizea29300.0000004650.00000093.000.0106 region11350.000000 27.000.0351

49 Car Insurance: ANOVA (cont) ParameterEstimateStandard Errort ValuePr > |t| Intercept195.0000000B5.7735026933.770.0009 sizea 1_small-90.0000000B7.07106781-12.730.0061 sizea 2_medium-15.0000000B7.07106781-2.120.1679 sizea 3_large0.0000000B... region 130.0000000B5.773502695.200.0351 region 20.0000000B... Obspremiumsizeregionsizeamuhat 1140111_small135 2100121_small105 3210212_medium210 4180222_medium180 5220313_large225 6200323_large195

50 Car Insurance: ANOVA (cont) Means with the same letter are not significantly different. Tukey GroupingMeanNsizea A210.00023_large A A195.00022_medium B120.00021_small Means with the same letter are not significantly different. Tukey GroupingMeanNregion A190.00031 B160.00032

51 Car Insurance: Plots symbol1 v='E' i=join c=green size=1.5; symbol2 v='W' i=join c=blue size=1.5; title1 h=3 'Plot of the model estimates'; proc gplot data=preds; plot muhat*sizea=region/haxis=axis1 vaxis=axis2; run;

52 Car Insurance: plots (cont)

53 Car Insurance Example: (nknw884.sas) Y = 3-month premium for car insurance Factor A = size of the city small, medium, large Factor B = geographic region east, west

54 Car Insurance: Overall mean proc glm data=carins; model premium=; output out=overall p=muhat; proc print data=overall; Obspremiumsizeregionmuhat 114011175 210012175 321021175 418022175 522031175 620032175

55 Car Insurance: Factor A treatment means proc glm data=carins; class size; model premium=size; output out=meanA p=muhatA; proc print data=meanA; run; ObspremiumsizeregionmuhatA 114011120 210012120 321021195 418022195 522031210 620032210

56 Car Insurance: Factor B treatment means proc glm data=carins; class region; model premium=region; output out=meanB p=muhatB; proc print data=meanB; run; ObspremiumsizeregionmuhatB 114011190 210012160 321021190 418022160 522031190 620032160

57 Car Insurance: Combine files data estimates; merge overall meanA meanB; alpha = muhatA - muhat; beta = muhatB - muhat; atimesb = alpha*beta; proc print data=estimates; var size region alpha beta atimesb; run; Obssizeregionalphabetaatimesb 111-5515-825 212-55-15825 3212015300 42220-15-300 5313515525 63235-15-525

58 Car Insurance: Tukey test for additivity proc glm data=estimates; class size region; model premium=size region atimesb/solution; run; SourceDFSum of SquaresMean SquareF ValuePr > F Model410737.096772684.27419208.030.0519 Error112.90323 Corrected Total510750.00000 R-SquareCoeff VarRoot MSEpremium Mean 0.9988002.0526323.592106175.0000 SourceDFType I SSMean SquareF ValuePr > F size29300.0000004650.000000360.370.0372 region11350.000000 104.620.0620 atimesb187.096774 6.750.2339

59 Car Insurance: Tukey test for additivity SourceDFSum of SquaresMean SquareF ValuePr > F Model410737.096772684.27419208.030.0519 Error112.90323 Corrected Total510750.00000 SourceDFType I SSMean SquareF ValuePr > F size29300.0000004650.000000360.370.0372 region11350.000000 104.620.0620 atimesb187.096774 6.750.2339 SourceDFSum of SquaresMean SquareF ValuePr > F Model310650.000003550.0000071.000.0139 Error2100.0000050.00000 Corrected Total510750.00000 SourceDFType I SSMean SquareF ValuePr > F sizea29300.0000004650.00000093.000.0106 region11350.000000 27.000.0351

60 Car Insurance: Tukey test for additivity ParameterEstimateStandard Errort ValuePr > |t| Intercept195.0000000B2.9329423066.490.0096 size 1-90.0000000B3.59210604-25.050.0254 size 2-15.0000000B3.59210604-4.180.1496 size 30.0000000B... region 130.0000000B2.9329423010.230.0620 region 20.0000000B... atimesb-0.00645160.00248323-2.600.2339 ParameterEstimateStandard Errort ValuePr > |t| Intercept195.0000000B5.7735026933.770.0009 sizea 1_small-90.0000000B7.07106781-12.730.0061 sizea 2_medium-15.0000000B7.07106781-2.120.1679 sizea 3_large0.0000000B... region 130.0000000B5.773502695.200.0351 region 20.0000000B...


Download ppt "Bread Example: nknw817.sas Y = number of cases of bread sold (sales) Factor A = height of shelf display (bottom, middle, top) Factor B = width of shelf."

Similar presentations


Ads by Google