Page 447 Table 17.1
data depress; set "c:\cama4\depress"; inccat = 0; if income ge 20 then inccat = 1; run; proc freq data = depress; tables sex*inccat / norow nocol nopercent; run;
The FREQ Procedure Table of SEX by inccat SEX inccat Frequency| 0| 1| Total ---------+--------+--------+ 1 | 54 | 57 | 111 ---------+--------+--------+ 2 | 125 | 58 | 183 ---------+--------+--------+ Total 179 115 294
Page 448 Table 17.2
NOTE: You can also use proc tabulate to create this table.
data depress; set depress; cesdcat = 0; if cesd ge 11 then cesdcat = 1; run; proc freq data = depress; tables sex *inccat* treat / norow nocol nopercent; run;
The FREQ Procedure Table 1 of inccat by TREAT Controlling for SEX=1 inccat TREAT Frequency| 1| 2| Total ---------+--------+--------+ 0 | 20 | 34 | 54 ---------+--------+--------+ 1 | 21 | 36 | 57 ---------+--------+--------+ Total 41 70 111 Table 2 of inccat by TREAT Controlling for SEX=2 inccat TREAT Frequency| 1| 2| Total ---------+--------+--------+ 0 | 73 | 52 | 125 ---------+--------+--------+ 1 | 34 | 24 | 58 ---------+--------+--------+ Total 107 76 183
Page 449 Table 17.3
proc freq data = depress; tables sex *inccat* cesdcat* treat / norow nocol nopercent; run;
The FREQ Procedure Table 1 of cesdcat by TREAT Controlling for SEX=1 inccat=0 cesdcat TREAT Frequency| 1| 2| Total ---------+--------+--------+ 0 | 16 | 23 | 39 ---------+--------+--------+ 1 | 4 | 11 | 15 ---------+--------+--------+ Total 20 34 54 Table 2 of cesdcat by TREAT Controlling for SEX=1 inccat=1 cesdcat TREAT Frequency| 1| 2| Total ---------+--------+--------+ 0 | 16 | 30 | 46 ---------+--------+--------+ 1 | 5 | 6 | 11 ---------+--------+--------+ Total 21 36 57 Table 3 of cesdcat by TREAT Controlling for SEX=2 inccat=0 cesdcat TREAT Frequency| 1| 2| Total ---------+--------+--------+ 0 | 48 | 33 | 81 ---------+--------+--------+ 1 | 25 | 19 | 44 ---------+--------+--------+ Total 73 52 125 Table 4 of cesdcat by TREAT Controlling for SEX=2 inccat=1 cesdcat TREAT Frequency| 1| 2| Total ---------+--------+--------+ 0 | 20 | 20 | 40 ---------+--------+--------+ 1 | 14 | 4 | 18 ---------+--------+--------+ Total 34 24 58
Page 451 middle of the page
proc freq data = depress; tables sex*inccat / norow nocol nopercent expected; run;
The FREQ Procedure Table of SEX by inccat SEX inccat Frequency| Expected | 0| 1| Total ---------+--------+--------+ 1 | 54 | 57 | 111 | 67.582 | 43.418 | ---------+--------+--------+ 2 | 125 | 58 | 183 | 111.42 | 71.582 | ---------+--------+--------+ Total 179 115 294
Page 454 top of the page
proc freq data = depress; tables sex*inccat / norow nocol nopercent chisq; run;
The FREQ Procedure Table of SEX by inccat SEX inccat Frequency| 0| 1| Total ---------+--------+--------+ 1 | 54 | 57 | 111 ---------+--------+--------+ 2 | 125 | 58 | 183 ---------+--------+--------+ Total 179 115 294 Statistics for Table of SEX by inccat Statistic DF Value Prob ------------------------------------------------------ Chi-Square 1 11.2104 0.0008 Likelihood Ratio Chi-Square 1 11.1467 0.0008 Continuity Adj. Chi-Square 1 10.4002 0.0013 Mantel-Haenszel Chi-Square 1 11.1723 0.0008 Phi Coefficient -0.1953 Contingency Coefficient 0.1917 Cramer's V -0.1953 Fisher's Exact Test ---------------------------------- Cell (1,1) Frequency (F) 54 Left-sided Pr <= F 6.489E-04 Right-sided Pr >= F 0.9997 Table Probability (P) 3.813E-04 Two-sided Pr <= P 9.068E-04 Sample Size = 294
Page 455 Table 17.7
proc freq data = depress; tables sex*inccat /out=page420 norow nocol nopercent; run; data page420a; set page420; if sex = 1 then sex1 = -1; if sex = 2 then sex1 = 1; if inccat = 0 then inccat1 = -1; if inccat = 1 then inccat1 = 1; run; proc genmod data = page420a; model count= sex1 inccat1 sex1*inccat1 /d=poisson; run; quit;
The GENMOD Procedure Model Information Data Set WORK.PAGE420A Distribution Poisson Link Function Log Dependent Variable COUNT Observations Used 4 Criteria For Assessing Goodness Of Fit Criterion DF Value Value/DF Deviance 0 0.0000 . Scaled Deviance 0 0.0000 . Pearson Chi-Square 0 0.0000 . Scaled Pearson X2 0 0.0000 . Log Likelihood 990.9040 Algorithm converged. Analysis Of Parameter Estimates Standard Wald 95% Confidence Chi- Parameter DF Estimate Error Limits Square Pr > ChiSq Intercept 1 4.2302 0.0619 4.1089 4.3515 4670.40 <.0001 sex1 1 0.2142 0.0619 0.0929 0.3355 11.97 0.0005 inccat1 1 -0.1785 0.0619 -0.2998 -0.0571 8.31 0.0039 sex1*inccat1 1 -0.2055 0.0619 -0.3268 -0.0842 11.02 0.0009 Scale 0 1.0000 0.0000 1.0000 1.0000 NOTE: The scale parameter was held fixed.
Page 460 in the middle
ods listing close; proc genmod data = tab427; class sex inccat treat; model count = sex|inccat|treat/ d = poisson ; ods output modelfit = temp1; run; proc genmod data = tab427; class sex inccat treat; model count = sex|inccat|treat@1/ d = poisson ; ods output modelfit = temp2; run; proc genmod data = tab427; class sex inccat treat; model count = sex|inccat|treat@2/ d = poisson ; ods output modelfit = temp3; run; proc genmod data = tab427; class sex inccat treat; model count = sex|inccat|treat@1 sex*inccat/ d = poisson ; ods output modelfit = temp4; run; proc genmod data = tab427; class sex inccat treat; model count = sex|inccat|treat@1 sex*inccat sex*treat/ d = poisson ; ods output modelfit = temp5; run; ods listing; data modelfit; set temp1 temp2 temp3 temp4 temp5; mydf = lag(df); if Criterion="Log Likelihood"; keep mydf value ; run; data modelfit; set modelfit; retain full_ll; retain full_df; if _n_ = 1 then do; full_ll= value; full_df = mydf; end; diff_ll = 2*(full_ll - value); diff_df = mydf - full_df; pvalue = 1 - probchi(diff_ll, diff_df); keep value diff_ll diff_df pvalue; run; proc print data = modelfit; run;
Obs Value diff_ll diff_df pvalue 1 589.8050 0.0000 0 . 2 577.7669 24.0763 4 0.00008 3 589.8045 0.0012 1 0.97262 4 583.3402 12.9296 3 0.00479 5 589.8044 0.0012 2 0.99938
Page 461 table in the middle of the page
ods listing close; proc freq data = depress; tables sex*inccat*treat /list out=tab427; run; proc genmod data = tab427; class sex inccat treat; model count = / d = poisson ; ods output modelfit = temp1; run; * all main effect terms; proc genmod data= tab427; class sex inccat treat; model count = sex inccat treat / d=poisson; ods output modelfit = temp2; run; /*row number 2 is comparing the model below with the model above*/ * all two-way interactions; proc genmod data= tab427; class sex inccat treat; model count = sex|inccat|treat@2 / d=poisson; ods output modelfit = temp3; run; /*row number 3 is comparing the model below with the model above*/ * all terms included; proc genmod data= tab427; class sex inccat treat; model count = sex|inccat|treat@3 / d=poisson; ods output modelfit = temp4; run; data modelcom; set temp1 temp2 temp3 temp4; mydf = lag(df); if Criterion="Log Likelihood" or criterion = "Pearson Chi-Square"; keep criterion mydf value myvalue; run; proc sort data = modelcom; by criterion; run; data modelcom1; set modelcom; if criterion = "Log Likelihood" then do; lagvalue=lag(value); lagdf = lag(mydf); chisq = 2*(value-lagvalue); df = lagdf - mydf ; pvalue = 1-probchi(chisq, df); end; else do ; lagvalue=lag(value); lagdf = lag(mydf); chisq = lagvalue - value; df = lagdf - mydf ; pvalue = 1-probchi(chisq, df); end; keep df chisq pvalue; if chisq ~=.; run; ods listing; proc print data = modelcom1; run;
Obs chisq df pvalue 1 31.8710 3 0.00000 2 24.0752 3 0.00002 3 0.0012 1 0.97262 4 36.6679 3 0.00000 5 24.6507 3 0.00002 6 0.0012 1 0.97262
Page 462
Partial association
ods listing close; proc genmod data= tab427; class sex inccat treat; model count = sex|inccat|treat@2 / d=poisson; ods output modelfit = temp1; run; /*this model gives loglikelihood of 584.4699 with df of 10*/ proc genmod data= tab427; class sex inccat treat; model count = inccat|treat sex|treat / d=poisson; ods output modelfit = temp2; run; /*this model gives loglikelihood of 589.8044 with df of 10*/ proc genmod data= tab427; class sex inccat treat; model count = sex|inccat sex|treat / d=poisson; ods output modelfit = temp3; run; /*this model gives loglikelihood of 583.5791 with df of 10*/ proc genmod data= tab427; class sex inccat treat; model count = sex|inccat inccat|treat / d=poisson; ods output modelfit = temp4; run; proc print data = temp1; run; ods listing; data pg428; set temp1 temp2 temp3 temp4; mydf = lag(df); if criterion = "Log Likelihood"; keep value mydf; run; data page428; set pg428; retain whole wholedf; if _n_ = 1 then do; whole = value; wholedf = mydf; end; else do; chisq = 2*(whole - value); df = mydf - wholedf; pvalue = 1 -probchi(chisq , df); end; keep df chisq pvalue; if chisq ~=.; run; proc print data = page428; run;
Obs chisq df pvalue 1 10.6691 1 0.00109 2 0.0001 1 0.99336 3 12.4508 1 0.00042
Marginal association
NOTE: Look at the Likelihood ratio chi-squares
proc freq data = tab427; weight count; tables sex*inccat /chisq; tables sex*treat /chisq; tables inccat*treat /chisq; run;
The FREQ Procedure Table of SEX by inccat SEX inccat Frequency| Percent | Row Pct | Col Pct | 0| 1| Total ---------+--------+--------+ 1 | 54 | 57 | 111 | 18.37 | 19.39 | 37.76 | 48.65 | 51.35 | | 30.17 | 49.57 | ---------+--------+--------+ 2 | 125 | 58 | 183 | 42.52 | 19.73 | 62.24 | 68.31 | 31.69 | | 69.83 | 50.43 | ---------+--------+--------+ Total 179 115 294 60.88 39.12 100.00 Statistics for Table of SEX by inccat Statistic DF Value Prob ------------------------------------------------------ Chi-Square 1 11.2104 0.0008 Likelihood Ratio Chi-Square 1 11.1467 0.0008 Continuity Adj. Chi-Square 1 10.4002 0.0013 Mantel-Haenszel Chi-Square 1 11.1723 0.0008 Phi Coefficient -0.1953 Contingency Coefficient 0.1917 Cramer's V -0.1953 Fisher's Exact Test ---------------------------------- Cell (1,1) Frequency (F) 54 Left-sided Pr <= F 6.489E-04 Right-sided Pr >= F 0.9997 Table Probability (P) 3.813E-04 Two-sided Pr <= P 9.068E-04 Sample Size = 294 The FREQ Procedure Table of SEX by TREAT SEX TREAT Frequency| Percent | Row Pct | Col Pct | 1| 2| Total ---------+--------+--------+ 1 | 41 | 70 | 111 | 13.95 | 23.81 | 37.76 | 36.94 | 63.06 | | 27.70 | 47.95 | ---------+--------+--------+ 2 | 107 | 76 | 183 | 36.39 | 25.85 | 62.24 | 58.47 | 41.53 | | 72.30 | 52.05 | ---------+--------+--------+ Total 148 146 294 50.34 49.66 100.00 Statistics for Table of SEX by TREAT Statistic DF Value Prob ------------------------------------------------------ Chi-Square 1 12.8149 0.0003 Likelihood Ratio Chi-Square 1 12.9284 0.0003 Continuity Adj. Chi-Square 1 11.9680 0.0005 Mantel-Haenszel Chi-Square 1 12.7713 0.0004 Phi Coefficient -0.2088 Contingency Coefficient 0.2044 Cramer's V -0.2088 Fisher's Exact Test ---------------------------------- Cell (1,1) Frequency (F) 41 Left-sided Pr <= F 2.578E-04 Right-sided Pr >= F 0.9999 Table Probability (P) 1.568E-04 Two-sided Pr <= P 4.627E-04 Sample Size = 294 The FREQ Procedure Table of inccat by TREAT inccat TREAT Frequency| Percent | Row Pct | Col Pct | 1| 2| Total ---------+--------+--------+ 0 | 93 | 86 | 179 | 31.63 | 29.25 | 60.88 | 51.96 | 48.04 | | 62.84 | 58.90 | ---------+--------+--------+ 1 | 55 | 60 | 115 | 18.71 | 20.41 | 39.12 | 47.83 | 52.17 | | 37.16 | 41.10 | ---------+--------+--------+ Total 148 146 294 50.34 49.66 100.00 Statistics for Table of inccat by TREAT Statistic DF Value Prob ------------------------------------------------------ Chi-Square 1 0.4776 0.4895 Likelihood Ratio Chi-Square 1 0.4777 0.4895 Continuity Adj. Chi-Square 1 0.3267 0.5676 Mantel-Haenszel Chi-Square 1 0.4759 0.4903 Phi Coefficient 0.0403 Contingency Coefficient 0.0403 Cramer's V 0.0403 Fisher's Exact Test ---------------------------------- Cell (1,1) Frequency (F) 93 Left-sided Pr <= F 0.7912 Right-sided Pr >= F 0.2838 Table Probability (P) 0.0750 Two-sided Pr <= P 0.5504 Sample Size = 294
Page 463 We were unable to reproduce the stepwise analysis using proc genmod.
Page 464
NOTE: The type1 option on the model statement gives us the first order terms and this is the model to compare against the three-way terms.
/*first order terms*/ proc genmod data = tab427; class sex inccat treat cesdcat; model count = sex inccat treat cesdcat sex|inccat|treat|cesdcat@3 / d = poisson link=log type1 ; ods output modelfit = three; run; ods listing close; /*term stc*/ proc genmod data = tab427; class sex inccat treat cesdcat; model count = sex|inccat|treat|cesdcat@2 sex*inccat*treat sex*inccat*cesdcat inccat*treat*cesdcat / d = poisson link=log ; ods output modelfit = stc; run; /*term itc*/ proc genmod data = tab427; class sex inccat treat cesdcat; model count = sex|inccat|treat|cesdcat@2 sex*inccat*treat sex*inccat*cesdcat sex*treat*cesdcat / d = poisson link=log ; ods output modelfit = itc; run; /*term isc*/ proc genmod data = tab427; class sex inccat treat cesdcat; model count = sex|inccat|treat|cesdcat@2 sex*inccat*treat inccat*treat*cesdcat sex*treat*cesdcat / d = poisson link=log ; ods output modelfit = isc; run; /*term ist*/ proc genmod data = tab427; class sex inccat treat cesdcat; model count = sex|inccat|treat|cesdcat@2 inccat*sex*cesdcat inccat*treat*cesdcat sex*treat*cesdcat / d = poisson link=log; ods output modelfit = ist; run; ods listing; data threecom; set three ist isc itc stc; if Criterion="Deviance" ; keep criterion df value ; run; data table430_part3; set threecom; retain a; if _n_ =1 then a = Value; else do; lrchisq = value - a; pvalue = 1-probchi(lrchisq, 1); end; keep lrchisq pvalue; if _n_ >1; run; /*comparison model*/ ods listing close; proc genmod data = tab427; class sex inccat treat cesdcat; model count = sex|inccat|treat|cesdcat@2 / d = poisson link=log ; ods output modelfit = two; run; /*term si*/ proc genmod data = tab427; class sex inccat treat cesdcat; model count = sex inccat treat cesdcat inccat*treat inccat*cesdcat sex*treat sex*cesdcat treat*cesdcat / d = poisson link=log ; ods output modelfit = si; run; /*term it*/ proc genmod data = tab427; class sex inccat treat cesdcat; model count = sex inccat treat cesdcat sex*inccat inccat*cesdcat sex*treat sex*cesdcat treat*cesdcat / d = poisson link=log ; ods output modelfit = it; run; /*term ic*/ proc genmod data = tab427; class sex inccat treat cesdcat; model count = sex inccat treat cesdcat sex*inccat inccat*treat sex*treat sex*cesdcat treat*cesdcat / d = poisson link=log ; ods output modelfit = ic; run; /*term st*/ proc genmod data = tab427; class sex inccat treat cesdcat; model count = sex inccat treat cesdcat inccat*sex inccat*treat inccat*cesdcat sex*cesdcat treat*cesdcat / d = poisson link=log ; ods output modelfit = st; run; /*term sc*/ proc genmod data = tab427; class sex inccat treat cesdcat; model count = sex inccat treat cesdcat inccat*sex inccat*treat inccat*cesdcat sex*treat treat*cesdcat / d = poisson link=log ; ods output modelfit = sc; run; /*term tc*/ proc genmod data = tab427; class sex inccat treat cesdcat; model count = sex inccat treat cesdcat inccat*sex inccat*treat inccat*cesdcat sex*treat sex*cesdcat / d = poisson link=log ; ods output modelfit = tc; run; ods listing; data twocom; set two si it ic st sc tc; if Criterion="Deviance" ; keep criterion df value ; run; data table430_part2; set twocom; retain a; if _n_ =1 then a = Value; else do; lrchisq = value - a; pvalue = 1-probchi(lrchisq, 1); end; keep lrchisq pvalue; if _n_ >1; run; proc print data = table430_part2; run;
NOTE: This output gives the first four rows of the table.
<some output omitted> LR Statistics For Type 1 Analysis Chi- Source Deviance DF Square Pr > ChiSq Intercept 115.4069 SEX 97.5936 1 17.81 <.0001 inccat 83.5495 1 14.04 0.0002 TREAT 83.5358 1 0.01 0.9071 cesdcat 34.8139 1 48.72 <.0001 SEX*inccat 23.6672 1 11.15 0.0008 SEX*TREAT 10.7389 1 12.93 0.0003 inccat*TREAT 10.7388 1 0.00 0.9934 SEX*inccat*TREAT 10.7376 1 0.00 0.9726 SEX*cesdcat 7.0589 1 3.68 0.0551 inccat*cesdcat 5.8929 1 1.17 0.2802 SEX*inccat*cesdcat 5.6357 1 0.26 0.6120 TREAT*cesdcat 5.3193 1 0.32 0.5738 SEX*TREAT*cesdcat 4.7877 1 0.53 0.4659 inccat*TREAT*cesdcat 0.0452 1 4.74 0.0294
NOTE: The output below gives the rest of the table. It is the output from the two proc prints above. The ods listing close statements tell SAS not to print the output of the proc genmods.
Obs lrchisq pvalue 1 0.00830 0.92743 2 0.00995 0.92053 3 4.74251 0.02943 4 1.22709 0.26797 Obs lrchisq pvalue 1 9.9063 0.00165 2 0.0019 0.96527 3 1.1678 0.27986 4 11.9764 0.00054 5 2.3418 0.12595 6 0.3171 0.57333
Page 468 at the bottom
proc freq data= depress; tables sex*treat*inccat/list out=page435; run; data page435a; set page435; if sex = 1 then sex1= 1; if sex = 2 then sex1 = -1; if treat =1 then treat1 = 1; if treat = 2 then treat1 = -1; if inccat = 0 then inccat1 = -1; if inccat = 1 then inccat1 = 1; run; proc genmod data= page435a; model count = sex1 treat1 inccat1 sex1*treat1 sex1*inccat1 treat1*inccat1 /d = poisson; run;
The GENMOD Procedure Model Information Data Set WORK.PAGE435A Distribution Poisson Link Function Log Dependent Variable COUNT Observations Used 8 Criteria For Assessing Goodness Of Fit Criterion DF Value Value/DF Deviance 1 0.0012 0.0012 Scaled Deviance 1 0.0012 0.0012 Pearson Chi-Square 1 0.0012 0.0012 Scaled Pearson X2 1 0.0012 0.0012 Log Likelihood 793.5897 Algorithm converged. Analysis Of Parameter Estimates Standard Wald 95% Confidence Chi- Parameter DF Estimate Error Limits Square Pr > ChiSq Intercept 1 3.5121 0.0636 3.3875 3.6367 3051.83 <.0001 sex1 1 -0.2246 0.0636 -0.3491 -0.1000 12.48 0.0004 treat1 1 -0.0481 0.0627 -0.1711 0.0748 0.59 0.4431 inccat1 1 -0.1784 0.0620 -0.2999 -0.0570 8.29 0.0040 sex1*treat1 1 -0.2194 0.0630 -0.3429 -0.0958 12.11 0.0005 sex1*inccat1 1 0.2056 0.0633 0.0815 0.3297 10.54 0.0012 treat1*inccat1 1 0.0005 0.0623 -0.1217 0.1227 0.00 0.9934 Scale 0 1.0000 0.0000 1.0000 1.0000 NOTE: The scale parameter was held fixed.
Page 470 top of the page
data depress437; set depress; treat1 = treat -1; sex1 = sex - 1; run; proc logistic data = depress437 desc; model treat1 = inccat sex1; run;
The LOGISTIC Procedure Analysis of Maximum Likelihood Estimates Standard Wald Parameter DF Estimate Error Chi-Square Pr > ChiSq Intercept 1 0.5360 0.2347 5.2149 0.0224 inccat 1 -0.00208 0.2494 0.0001 0.9934 sex1 1 -0.8774 0.2522 12.1067 0.0005 Odds Ratio Estimates Point 95% Wald Effect Estimate Confidence Limits inccat 0.998 0.612 1.627 sex1 0.416 0.254 0.682 Association of Predicted Probabilities and Observed Responses Percent Concordant 34.7 Somers' D 0.202 Percent Discordant 14.4 Gamma 0.412 Percent Tied 50.9 Tau-a 0.102 Pairs 21608 c 0.601