<?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 Re: Chi Square for inclusive values in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/738674#M28899</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203839"&gt;@merdemk&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for the late response, but here's another suggestion: Wouldn't it be appropriate to divide this multiple-choice survey question into two Yes/No questions (i.e., "... because of money?" and "... because of ideals?")? Then, assuming that the respondents were randomly selected from a large population, you could model it as two &lt;EM&gt;dependent&lt;/EM&gt; binary variables (each having a Bernoulli distribution) and use&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.3/statug/statug_freq_details76.htm#statug.freq.freqmcnemar" target="_blank" rel="noopener"&gt;McNemar's test&lt;/A&gt; to test the null hypothesis of equal marginal probabilities for "Yes."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
Motivation_V18_H6=_n_-1;
input n @@;
cards;
35 22 54 8
;

data want;
set have;
money  = (Motivation_V18_H6 in (0 2));
ideals = (Motivation_V18_H6 in (1 2));
run;

proc freq data=want;
weight n;
tables money*ideals / agree;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Table of money by ideals

money     ideals

Frequency|
Percent  |
Row Pct  |
Col Pct  |       0|       1|  Total
---------+--------+--------+
       0 |      8 |     22 |     30
         |   6.72 |  18.49 |  25.21
         |  26.67 |  73.33 |
         |  18.60 |  28.95 |
---------+--------+--------+
       1 |     35 |     54 |     89
         |  29.41 |  45.38 |  74.79
         |  39.33 |  60.67 |
         |  81.40 |  71.05 |
---------+--------+--------+
Total          43       76      119
            36.13    63.87   100.00


Statistics for Table of money by ideals


&lt;STRONG&gt;          McNemar's Test

Chi-Square        DF    Pr &amp;gt; ChiSq

    2.9649         1        0.0851&lt;/STRONG&gt;


           Simple Kappa Coefficient

            Standard
Estimate       Error    95% Confidence Limits

 -0.1107      0.0841     -0.2755       0.0541

Sample Size = 119&lt;/PRE&gt;
&lt;P&gt;I've run simulations to estimate the power and&amp;nbsp;type I error probability of the test in situations similar to your numeric example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Format for p-values (using a 5% significance level) */

proc format;
value signif
low-0.05   = 'significant'
0.05&amp;lt;-high = 'not significant';
run;

/* Simulation of two dependent Bernoulli distributed random variables¹,                   */
/* estimation of the power and type I error probability of McNemar's test                 */
/*                                                                                        */
/* ¹ based on sample code from Rick Wicklin's blog article                                */
/*   https://blogs.sas.com/content/iml/2016/03/16/simulate-multinomial-sas-data-step.html */

%let SampleSize = 1000000;
%let N = 119;

%macro sim(outds,  /* Name of output dataset */
              p1,  /* Parameter of the Bernoulli distribution of the row variable (X) */
              p2,  /* Parameter of the Bernoulli distribution of the column variable (Y) */
              p11  /* p11=P(X=Y=1); note: max(0, p1+p2-1) &amp;lt;= p11 &amp;lt;= min(p1, p2) */
          );
data &amp;amp;outds(keep=i pv);
call streaminit(27182818);
array probs[4] _temporary_ (%sysevalf(1-&amp;amp;p1-&amp;amp;p2+&amp;amp;p11) /* p00 */
                            %sysevalf(&amp;amp;p2-&amp;amp;p11)       /* p01 */
                            %sysevalf(&amp;amp;p1-&amp;amp;p11)       /* p10 */
                            %sysevalf(&amp;amp;p11));         /* p11 */
array x[4] x00 x01 x10 x11;
do i = 1 to &amp;amp;SampleSize; 
  ItemsLeft = &amp;amp;N;
  cumProb = 0;
  do j = 1 to dim(probs)-1;
    p = probs[j] / (1 - cumProb);
    x[j] = rand('binom', p, ItemsLeft);
    ItemsLeft = ItemsLeft - x[j];
    cumProb = cumProb + probs[j];
  end;
  x[dim(probs)] = ItemsLeft;

  if x01 ne x10 then pv=sdf('chisq',(x01-x10)**2/(x01+x10),1); /* p-value of McNemar's test */
  else pv=1;
  output;
end;
run;

proc freq data=&amp;amp;outds;
format pv signif.;
tables pv / binomial;
run;

%mend sim;

%sim(sim0, 165/238, 165/238, 54/119) /* one particular case of the null hypothesis (p1=p2) */
/* Estimated probability of type I error: 0.0492 */

%sim(sim1, 89/119, 76/119, 54/119) /* Corr(X,Y)=(&amp;amp;p11-&amp;amp;p1*&amp;amp;p2)/sqrt(&amp;amp;p1*&amp;amp;p2*(1-&amp;amp;p1)*(1-&amp;amp;p2))=-0.1144 */
/* Estimated power: 0.4052 */

%sim(sim2, 89/119, 76/119, 72/119) /* larger p11, Corr(X,Y)=0.6107 */
/* Estimated power: 0.8530 */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Two variants of McNemar's test (not shown here) -- the exact version available with the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.3/statug/statug_freq_syntax03.htm#statug.freq.freqexmcnem" target="_blank" rel="noopener"&gt;EXACT MCNEM&lt;/A&gt; statement in PROC FREQ and the asymptotic version using Edwards' correction (see &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.3/statug/statug_freq_references.htm#statug_freqflei_j2003" target="_self"&gt;Fleiss, Levin, and Paik, 2003&lt;/A&gt;,&amp;nbsp;&lt;SPAN&gt;p. 375) -- turned out to be rather conservative, hence less powerful than the default "uncorrected" asymptotic version of the test.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 03 May 2021 18:47:36 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-05-03T18:47:36Z</dc:date>
    <item>
      <title>Chi Square for inclusive values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/737156#M28785</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My apologies if this was asked before. I have a variable indicating why people select a particular academic field. It is something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obs&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Reason&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; money (coded as 0)&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ideals (1)&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; money and ideals (2)&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; none (3)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to test the hypothesis "people are more likely to select a field because of money than ideals" .&amp;nbsp; The existence of "money and ideals" confuses me. If I create a binary variable I have to exclude money and ideals.&amp;nbsp; I don't think I can exclude "money and ideals" and test only money vs ideals as almost half of the observations are "money and ideals".&amp;nbsp; Any help is much appreciated. Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 04:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/737156#M28785</guid>
      <dc:creator>merdemk</dc:creator>
      <dc:date>2021-04-27T04:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: Chi Square for inclusive values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/737161#M28786</link>
      <description>&lt;P&gt;You have a fairly classic example of not matching questions in a survey to the analysis plan, or more common, no analysis plan before writing the survey.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on what you actually collected there may not be much you can do except use all 4 levels. How many "fields" are represented in the data, or are you not looking at the fields in this analysis? And how many respondents? You may not have much sample to work with including "field".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Was that an actual question or are these the results of coding from other actual questions, or a multi-response question that allowed selecting both categories and possibly more categories? Or the result of coding open text responses into a category?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 04:56:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/737161#M28786</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-27T04:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: Chi Square for inclusive values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/737172#M28788</link>
      <description>&lt;P&gt;Thanks for the answer. Unfortunately I didn't design the survey. Here is the frequency data:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 213px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58718i1DE7065A01A26109/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I believe that was the actual question and subjects were able to select multiple choices at once. Do you think omitting option 2 causes bias? If I omit 2 then 0/1 ratio is 35/22 but if I include 2 then it becomes 89/76. They are quite different plus I would be artificially increasing the sample size in the latter.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 05:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/737172#M28788</guid>
      <dc:creator>merdemk</dc:creator>
      <dc:date>2021-04-27T05:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: Chi Square for inclusive values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/737291#M28798</link>
      <description>&lt;P&gt;Including option 2 in any way confounds the data because it is clearly neither one of the other two choices.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Subset the data and do the test you were going to do.&lt;/P&gt;
&lt;P&gt;No reason to create an additional variable for a quick test just use a: Where &amp;lt;your variable name&amp;gt; in (0 1); and see what you get.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The write up should include that half the data was thrown away because the data collection did not match the requirements for the analysis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or go back to whoever requests this analysis and discuss what the analysis plan indicated how this question was intended to be used.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 15:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/737291#M28798</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-27T15:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: Chi Square for inclusive values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/737303#M28802</link>
      <description>If this is homework/class work you do it anyways. If someone was asking for the analysis you explain the survey wasn't designed to answer this question as it's a multiselect question where a user isn't picking between two specific choices. You can make an assumption, either put everyone who said money/ideals in Money and everyone else in Ideals, excluding None of course or exclude the group that selects both and see what the results are - I would probably do it both ways to see what happens out of curiousity.</description>
      <pubDate>Tue, 27 Apr 2021 16:02:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/737303#M28802</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-27T16:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Chi Square for inclusive values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/738674#M28899</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203839"&gt;@merdemk&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for the late response, but here's another suggestion: Wouldn't it be appropriate to divide this multiple-choice survey question into two Yes/No questions (i.e., "... because of money?" and "... because of ideals?")? Then, assuming that the respondents were randomly selected from a large population, you could model it as two &lt;EM&gt;dependent&lt;/EM&gt; binary variables (each having a Bernoulli distribution) and use&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.3/statug/statug_freq_details76.htm#statug.freq.freqmcnemar" target="_blank" rel="noopener"&gt;McNemar's test&lt;/A&gt; to test the null hypothesis of equal marginal probabilities for "Yes."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
Motivation_V18_H6=_n_-1;
input n @@;
cards;
35 22 54 8
;

data want;
set have;
money  = (Motivation_V18_H6 in (0 2));
ideals = (Motivation_V18_H6 in (1 2));
run;

proc freq data=want;
weight n;
tables money*ideals / agree;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Table of money by ideals

money     ideals

Frequency|
Percent  |
Row Pct  |
Col Pct  |       0|       1|  Total
---------+--------+--------+
       0 |      8 |     22 |     30
         |   6.72 |  18.49 |  25.21
         |  26.67 |  73.33 |
         |  18.60 |  28.95 |
---------+--------+--------+
       1 |     35 |     54 |     89
         |  29.41 |  45.38 |  74.79
         |  39.33 |  60.67 |
         |  81.40 |  71.05 |
---------+--------+--------+
Total          43       76      119
            36.13    63.87   100.00


Statistics for Table of money by ideals


&lt;STRONG&gt;          McNemar's Test

Chi-Square        DF    Pr &amp;gt; ChiSq

    2.9649         1        0.0851&lt;/STRONG&gt;


           Simple Kappa Coefficient

            Standard
Estimate       Error    95% Confidence Limits

 -0.1107      0.0841     -0.2755       0.0541

Sample Size = 119&lt;/PRE&gt;
&lt;P&gt;I've run simulations to estimate the power and&amp;nbsp;type I error probability of the test in situations similar to your numeric example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Format for p-values (using a 5% significance level) */

proc format;
value signif
low-0.05   = 'significant'
0.05&amp;lt;-high = 'not significant';
run;

/* Simulation of two dependent Bernoulli distributed random variables¹,                   */
/* estimation of the power and type I error probability of McNemar's test                 */
/*                                                                                        */
/* ¹ based on sample code from Rick Wicklin's blog article                                */
/*   https://blogs.sas.com/content/iml/2016/03/16/simulate-multinomial-sas-data-step.html */

%let SampleSize = 1000000;
%let N = 119;

%macro sim(outds,  /* Name of output dataset */
              p1,  /* Parameter of the Bernoulli distribution of the row variable (X) */
              p2,  /* Parameter of the Bernoulli distribution of the column variable (Y) */
              p11  /* p11=P(X=Y=1); note: max(0, p1+p2-1) &amp;lt;= p11 &amp;lt;= min(p1, p2) */
          );
data &amp;amp;outds(keep=i pv);
call streaminit(27182818);
array probs[4] _temporary_ (%sysevalf(1-&amp;amp;p1-&amp;amp;p2+&amp;amp;p11) /* p00 */
                            %sysevalf(&amp;amp;p2-&amp;amp;p11)       /* p01 */
                            %sysevalf(&amp;amp;p1-&amp;amp;p11)       /* p10 */
                            %sysevalf(&amp;amp;p11));         /* p11 */
array x[4] x00 x01 x10 x11;
do i = 1 to &amp;amp;SampleSize; 
  ItemsLeft = &amp;amp;N;
  cumProb = 0;
  do j = 1 to dim(probs)-1;
    p = probs[j] / (1 - cumProb);
    x[j] = rand('binom', p, ItemsLeft);
    ItemsLeft = ItemsLeft - x[j];
    cumProb = cumProb + probs[j];
  end;
  x[dim(probs)] = ItemsLeft;

  if x01 ne x10 then pv=sdf('chisq',(x01-x10)**2/(x01+x10),1); /* p-value of McNemar's test */
  else pv=1;
  output;
end;
run;

proc freq data=&amp;amp;outds;
format pv signif.;
tables pv / binomial;
run;

%mend sim;

%sim(sim0, 165/238, 165/238, 54/119) /* one particular case of the null hypothesis (p1=p2) */
/* Estimated probability of type I error: 0.0492 */

%sim(sim1, 89/119, 76/119, 54/119) /* Corr(X,Y)=(&amp;amp;p11-&amp;amp;p1*&amp;amp;p2)/sqrt(&amp;amp;p1*&amp;amp;p2*(1-&amp;amp;p1)*(1-&amp;amp;p2))=-0.1144 */
/* Estimated power: 0.4052 */

%sim(sim2, 89/119, 76/119, 72/119) /* larger p11, Corr(X,Y)=0.6107 */
/* Estimated power: 0.8530 */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Two variants of McNemar's test (not shown here) -- the exact version available with the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.3/statug/statug_freq_syntax03.htm#statug.freq.freqexmcnem" target="_blank" rel="noopener"&gt;EXACT MCNEM&lt;/A&gt; statement in PROC FREQ and the asymptotic version using Edwards' correction (see &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.3/statug/statug_freq_references.htm#statug_freqflei_j2003" target="_self"&gt;Fleiss, Levin, and Paik, 2003&lt;/A&gt;,&amp;nbsp;&lt;SPAN&gt;p. 375) -- turned out to be rather conservative, hence less powerful than the default "uncorrected" asymptotic version of the test.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 18:47:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/738674#M28899</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-05-03T18:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Chi Square for inclusive values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/738689#M28900</link>
      <description>Hi @FreelanceReinhard,&lt;BR /&gt;&lt;BR /&gt;Thank you so much! This is an excellent idea!</description>
      <pubDate>Mon, 03 May 2021 19:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Chi-Square-for-inclusive-values/m-p/738689#M28900</guid>
      <dc:creator>merdemk</dc:creator>
      <dc:date>2021-05-03T19:57:01Z</dc:date>
    </item>
  </channel>
</rss>

