* ---------------------------------------------------------- ; * Exercise 2.8 ; * ---------------------------------------------------------- ; data traffic ; length signal $ 14 ; input signal $ r ; do i = 1 to r ; input delay @@ ; output ; end ; drop i r ; cards ; pretimed 5 36.6 39.2 30.4 37.1 34.1 semiactuated 5 17.5 20.6 18.7 25.7 22.0 fullyactuated 5 15.0 10.4 18.9 10.5 15.2 ; proc print data = traffic ; run ; proc glm data = traffic ; class signal ; model delay = signal ; lsmeans signal / stderr cl ; output out = rtraffic p = pred r = res ; run ; proc plot data = rtraffic vpercent = 80 hpercent = 80 ; plot res*pred ; proc capability noprint data = rtraffic lineprinter ; var res ; qqplot res /normal(mu = est sigma = est symbol='.') square ; run ; * MSE = 11.49 ; * For mu values of 20, 18, 16, the grand mean is 18 and the taui are 2, 0, -2, thus the sum of taui**2 = 8 ; * Thus the ratio of the sum of the taui**2/sigma**2 will be 8/11.49 = ; %macro powcr(ngrp,rat,alpha,power) ; %local n ndf ddf nonc fcr pv ; data calc1 ; do r = 2 to 10000 ; ndf = &ngrp -1 ; ddf = &ngrp*(r -1) ; nonc = &rat*r ; fcr = finv(1-&alpha,ndf,ddf) ; power = 1 -probf(fcr,ndf,ddf,nonc) ; output ; if power ge &power then leave ; end ; run ; proc print noobs ; title 'Macro POWCR results' ; run ; proc plot vpercent=90 hpercent=90 ; plot power*r ; title 'Macro POWCR results' ; run ; %mend ; %powcr(3,.6963,.01,.9) ; * ---------------------------------------------------------- ; * Exercise 5.2 ; * ---------------------------------------------------------- ; data ch3ex5 ; input patient chol @@ ; cards ; 1 167.3 1 166.7 2 186.7 2 184.2 3 100.0 3 107.9 4 214.5 4 215.3 5 148.5 5 149.5 6 171.5 6 167.3 7 161.5 7 159.4 8 243.6 8 245.5 ; proc print data = ch3ex5 ; run ; proc glm data = ch3ex5 ; class patient ; model chol = patient ; run ; proc mixed data = ch3ex5 cl alpha = .1 ; ods output CovParms = covpar ; class patient ; model chol = / outp = rch3ex5 ; random patient ; run ; proc plot data = rch3ex5 vpercent = 80 hpercent = 80 ; plot resid*pred ; proc capability noprint data = rch3ex5 lineprinter ; var resid ; qqplot resid /normal(mu = est sigma = est symbol='.') square ; run ; * this code calculates the intraclass correlation ; data icc_calc ; set covpar ; retain siga ; if covparm = 'patient' then siga = estimate ; if covparm = 'Residual' then sige = estimate ; icc = siga/(siga +sige) ; keep covparm estimate icc ; run ; proc print data = icc_calc ; run ; * ---------------------------------------------------------- ; * Exercise 5.4 ; * ---------------------------------------------------------- ; data ex5_4 ; length lot $ 10 ; input lot $ r ; do i = 1 to r ; input conc @@ ; output ; end ; cards ; 3469-72 4 39 57 63 66 3849-52 4 56 13 25 31 3721-24 4 64 83 88 71 3477-80 4 29 55 21 51 3669-72 4 38 66 53 81 3873-76 4 11 49 34 10 3777-80 4 23 0 5 20 3461-64 4 10 11 23 37 ; proc print data = ex5_4 ; run ; proc glm data = ex5_4 ; class lot ; model conc = lot ; random lot / test ; run ; proc mixed data = ex5_4 ; class lot ; model conc = / outp = rex5_4 ; random lot ; run ; proc plot data = rex5_4 vpercent = 80 hpercent = 80 ; plot resid*pred ; proc capability noprint data = rex5_4 lineprinter ; var resid ; qqplot resid /normal(mu = est sigma = est symbol='.') square ; run ; * ---------------------------------------------------------- ; * Exercise 6.3 ; * ---------------------------------------------------------- ; data ex6_3 ; input fabric temp shrink @@ ; cards ; 1 210 1.8 1 210 2.1 1 215 2.0 1 215 2.1 1 220 4.6 1 220 5.0 1 225 7.5 1 225 7.9 2 210 2.2 2 210 2.4 2 215 4.2 2 215 4.0 2 220 5.4 2 220 5.6 2 225 9.8 2 225 9.2 3 210 2.8 3 210 3.2 3 215 4.4 3 215 4.8 3 220 8.7 3 220 8.4 3 225 13.2 3 225 13.0 4 210 3.2 4 210 3.6 4 215 3.3 4 215 3.5 4 220 5.7 4 220 5.8 4 225 10.9 4 225 11.1 ; proc print data = ex6_3 ; run ; proc glm data = ex6_3 ; class fabric temp ; model shrink = fabric temp fabric*temp ; contrast 'fabric main effect' fabric 1 -1 0 0, fabric 1 0 -1 0, fabric 1 0 0 -1 ; * the above code calculates the fabric main effect as a set of 3 pairwise contrasts ; contrast 'linear temp' temp -3 -1 1 3 ; contrast 'quadratic temp' temp 1 -1 -1 1 ; contrast 'cubic temp' temp -1 3 -3 1 ; contrast 'linear temp x fabric int. ' fabric*temp -3 -1 1 3 3 1 -1 -3 0 0 0 0 0 0 0 0 , fabric*temp -3 -1 1 3 0 0 0 0 3 1 -1 -3 0 0 0 0 , fabric*temp -3 -1 1 3 0 0 0 0 0 0 0 0 3 1 -1 -3 / e ; contrast 'quad. temp x fabric int. ' fabric*temp 1 -1 -1 1 -1 1 1 -1 0 0 0 0 0 0 0 0 , fabric*temp 1 -1 -1 1 0 0 0 0 -1 1 1 -1 0 0 0 0 , fabric*temp 1 -1 -1 1 0 0 0 0 0 0 0 0 -1 1 1 -1 ; contrast 'cubic temp x fabric int. ' fabric*temp -1 3 -3 1 1 -3 3 -1 0 0 0 0 0 0 0 0 , fabric*temp -1 3 -3 1 0 0 0 0 1 -3 3 -1 0 0 0 0 , fabric*temp -1 3 -3 1 0 0 0 0 0 0 0 0 1 -3 3 -1 ; output out = rex6_3 p = pred r = res ; run ; proc plot data = rex6_3 ; plot pred*fabric=temp pred*temp=fabric res*pred ; run ; proc capability noprint data = rex6_3 lineprinter ; var res ; qqplot res /normal(mu = est sigma = est symbol='.') square ; run ; * ---------------------------------------------------------- ; * Exercise 6.11 ; * ---------------------------------------------------------- ; data ex6_11 ; input base alcohol prod @@ ; cards ; 1 1 90.7 1 1 91.4 1 2 89.3 1 2 88.1 1 2 90.4 1 3 89.5 1 3 87.6 1 3 88.3 1 3 90.3 2 1 87.3 2 1 88.3 2 1 91.5 2 2 94.7 2 3 93.1 2 3 90.7 2 3 91.5 ; proc print data = ex6_11 ; run ; proc glm data = ex6_11 ; class base alcohol ; model prod = base alcohol base*alcohol ; estimate 'base1 vs base2 @ alc1' base 1 -1 base*alcohol 1 0 0 -1 0 0 / e ; estimate 'base1 vs base2 @ alc2' base 1 -1 base*alcohol 0 1 0 0 -1 0 ; estimate 'base1 vs base2 @ alc3' base 1 -1 base*alcohol 0 0 1 0 0 -1 ; lsmeans base*alcohol / slice = alcohol ; lsmeans base alcohol base*alcohol / stderr ; means base alcohol base*alcohol ; output out = rex6_11 p = pred r = res ; run ; proc plot data = rex6_11 ; plot res*pred ; run ; proc capability noprint data = rex6_11 lineprinter ; var res ; qqplot res /normal(mu = est sigma = est symbol='.') square ; run ;