<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Comparing observed to expected values in 2x2 contingency tables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243306#M55920</link>
    <description>&lt;P&gt;I'm conducting a chi-squared goodness of fit test comparing the following observed cell counts to the expected count values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="271"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="142" colspan="2"&gt;Observed&lt;/TD&gt;
&lt;TD width="65"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;X&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;Total&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;No&lt;/TD&gt;
&lt;TD&gt;209,916&lt;/TD&gt;
&lt;TD&gt;1,191&lt;/TD&gt;
&lt;TD&gt;211,107&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Yes&lt;/TD&gt;
&lt;TD&gt;7,645&lt;/TD&gt;
&lt;TD&gt;461&lt;/TD&gt;
&lt;TD&gt;8,106&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Total&lt;/TD&gt;
&lt;TD&gt;217,561&lt;/TD&gt;
&lt;TD&gt;1,652&lt;/TD&gt;
&lt;TD&gt;219,213&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Expected&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;X&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;Total&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;No&lt;/TD&gt;
&lt;TD&gt;209,516.100&lt;/TD&gt;
&lt;TD&gt;1,590.913&lt;/TD&gt;
&lt;TD&gt;211,107&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Yes&lt;/TD&gt;
&lt;TD&gt;8,044.913&lt;/TD&gt;
&lt;TD&gt;61.087&lt;/TD&gt;
&lt;TD&gt;8,106&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Total&lt;/TD&gt;
&lt;TD&gt;217,561&lt;/TD&gt;
&lt;TD&gt;1,652&lt;/TD&gt;
&lt;TD&gt;219,213&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible to find the chi-square p-value for 2x2 or larger multinomial tables with specified expected values using proc freq?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ended up hand calculating the chi-square test statistic in the above example (= 2,739.234) and then ran the following code for chi-square dbn with 1 df:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	pvalue = 1 - PROBCHI(2739.234, 1);
	put pvalue;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The resulting p-value was so small SAS rounded down to zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jan 2016 19:48:25 GMT</pubDate>
    <dc:creator>RobF</dc:creator>
    <dc:date>2016-01-13T19:48:25Z</dc:date>
    <item>
      <title>Comparing observed to expected values in 2x2 contingency tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243306#M55920</link>
      <description>&lt;P&gt;I'm conducting a chi-squared goodness of fit test comparing the following observed cell counts to the expected count values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="271"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="142" colspan="2"&gt;Observed&lt;/TD&gt;
&lt;TD width="65"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;X&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;Total&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;No&lt;/TD&gt;
&lt;TD&gt;209,916&lt;/TD&gt;
&lt;TD&gt;1,191&lt;/TD&gt;
&lt;TD&gt;211,107&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Yes&lt;/TD&gt;
&lt;TD&gt;7,645&lt;/TD&gt;
&lt;TD&gt;461&lt;/TD&gt;
&lt;TD&gt;8,106&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Total&lt;/TD&gt;
&lt;TD&gt;217,561&lt;/TD&gt;
&lt;TD&gt;1,652&lt;/TD&gt;
&lt;TD&gt;219,213&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Expected&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;X&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;Total&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;No&lt;/TD&gt;
&lt;TD&gt;209,516.100&lt;/TD&gt;
&lt;TD&gt;1,590.913&lt;/TD&gt;
&lt;TD&gt;211,107&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Yes&lt;/TD&gt;
&lt;TD&gt;8,044.913&lt;/TD&gt;
&lt;TD&gt;61.087&lt;/TD&gt;
&lt;TD&gt;8,106&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Total&lt;/TD&gt;
&lt;TD&gt;217,561&lt;/TD&gt;
&lt;TD&gt;1,652&lt;/TD&gt;
&lt;TD&gt;219,213&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible to find the chi-square p-value for 2x2 or larger multinomial tables with specified expected values using proc freq?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ended up hand calculating the chi-square test statistic in the above example (= 2,739.234) and then ran the following code for chi-square dbn with 1 df:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	pvalue = 1 - PROBCHI(2739.234, 1);
	put pvalue;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The resulting p-value was so small SAS rounded down to zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2016 19:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243306#M55920</guid>
      <dc:creator>RobF</dc:creator>
      <dc:date>2016-01-13T19:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing observed to expected values in 2x2 contingency tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243328#M55923</link>
      <description>&lt;P&gt;PROC FREQ does all of that...though maybe not in the exact format you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
table var1*var2/chisq expected list;
weight freq;
ods table crosstabfreqs=want1;
ods table chisq=want2;
run;

proc print data=want1;
proc print data=want2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Jan 2016 20:48:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243328#M55923</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-13T20:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing observed to expected values in 2x2 contingency tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243382#M55931</link>
      <description>&lt;P&gt;Yes . Proc freq will do these all for you .&lt;/P&gt;
&lt;P&gt;But If you use IML code, that would be very easy thing too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;the p-value is also near zero , which means reject H0 .&lt;/P&gt;
&lt;P&gt;Sorry. I am confused with DF. DF=1 .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data o;
input (X Y) (: comma32.);
cards;
209,916 1,191	
7,645 461	
run;
data e;
input (X Y) (: comma32.);
cards;
209,516.100 1,590.913
8,044.913 61.087
;
run;

proc iml;
use o;
read all var _num_ into o;
close;
use e;
read all var _num_ into e;
close;
df=nrow(o)*ncol(o)-nrow(o)-ncol(o)+1;
chi= sum((o-e)##2/e);
p=1-cdf('chisq',chi,df);
print chi,df,p[f=pvalue.];
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 05:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243382#M55931</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-01-14T05:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing observed to expected values in 2x2 contingency tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243478#M55941</link>
      <description>&lt;P&gt;Thanks Reeza -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does the "expected" option allow the user to manually enter in the expected null hypothesis values, or does "expected" only calculate the 2x2 table's row and column means through cross-multiplication?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 15:17:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243478#M55941</guid>
      <dc:creator>RobF</dc:creator>
      <dc:date>2016-01-14T15:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing observed to expected values in 2x2 contingency tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243482#M55942</link>
      <description>&lt;P&gt;Although you can use the TESTF= and TESTP= options for one-way tables, these options are not supported for tw-way tables. One reason is that the test statistic has an asymptotic chi-square distribution under the null hypothesis of independence between rows and columns.&amp;nbsp;&amp;nbsp; If you plug in your own expected values, there is not reason to think that the (Obs-Expected)**2/Expected statistic is distributed like chi-square.&amp;nbsp; Therefore you can't compute p-values in the usual way.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 15:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243482#M55942</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-01-14T15:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing observed to expected values in 2x2 contingency tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243540#M55955</link>
      <description>&lt;P&gt;Ah - in that case maybe a better idea would be to conduct two binomial tests comparing the % Yes for X and Y between the Observed &amp;amp; Expected?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 18:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243540#M55955</guid>
      <dc:creator>RobF</dc:creator>
      <dc:date>2016-01-14T18:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing observed to expected values in 2x2 contingency tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243552#M55956</link>
      <description>&lt;P&gt;It seems like that is an answer to a different question than you originally asked. But, yes, you could use PROC FREQ and use two TABLES statements to conduct two hypothesis tests for the marginal distributions.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 18:59:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243552#M55956</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-01-14T18:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing observed to expected values in 2x2 contingency tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243586#M55963</link>
      <description>&lt;P&gt;I'll follow up on&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS﻿&lt;/a&gt;'s comment. &amp;nbsp;In a 2x2 table with fixed margins, the expected value is determined by the marginal values--you literally cannot specify other values. &amp;nbsp;If you loosen this restriction, then it is indeed separate binomial tests against prespecified expected values. &amp;nbsp;My question would be "Where do you get those values?" and more importantly, "How many observations go into the estimate of the proportion?" &amp;nbsp;The latter is a prime determinant of both the Type I and Type II errors for what you are going after.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Steve Denham&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 20:47:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Comparing-observed-to-expected-values-in-2x2-contingency-tables/m-p/243586#M55963</guid>
      <dc:creator>SteveDenham</dc:creator>
      <dc:date>2016-01-14T20:47:21Z</dc:date>
    </item>
  </channel>
</rss>

