<?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: compute an exact confidence interval for a single proportion by hand to match output from proc f in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767163#M37498</link>
    <description>&lt;P&gt;John,&lt;/P&gt;
&lt;P&gt;Thank you for your reply. SAS is not always consistent in proc freq. If you look at my calculations in the enclosed file you will see that the Wald test and Wald confidence interval do not appear on the SAS output on page 1. I'm trying to figure out what exact test is being computed and how? Can you help?&lt;/P&gt;</description>
    <pubDate>Sat, 11 Sep 2021 01:57:50 GMT</pubDate>
    <dc:creator>MaryA_Marion</dc:creator>
    <dc:date>2021-09-11T01:57:50Z</dc:date>
    <item>
      <title>compute an exact confidence interval for a single proportion by hand to match output from proc freq</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767097#M37493</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="single proportions and exact intervals.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63499i1FC37AE22320E921/image-size/medium?v=v2&amp;amp;px=400" role="button" title="single proportions and exact intervals.png" alt="single proportions and exact intervals.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output from proc freq gives a Clopper-Pearson (exact) confidence interval but how do I compute the accompanying statistic of a test of p=po and its pvalue?&lt;/P&gt;
&lt;P&gt;Also when I am working with single binomial proportion, how is Fishers exact test computed. It is also listed on the output. Where can I find freq documentation about that. I must be using wrong search criteria for I am not seeing the answers for each of these questions. My notes have approximate and exact z statistics varying by denominator as seen in snaphot at beginning of this post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;title " Ho: p=.7 vs Ha: p ne .7";
data CellCounts; input R $ Count;
np=40*.7; nq=40*.3;
datalines;
yes 35
no 5
;
run;

proc freq data = CellCounts order=freq;
  tables R / binomial(p=0.7 exact score) alpha=.05;
  exact binomial;
  weight Count;
run; quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you. MM&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 19:58:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767097#M37493</guid>
      <dc:creator>MaryA_Marion</dc:creator>
      <dc:date>2021-09-10T19:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: compute an exact confidence interval for a single proportion by hand to match output from proc f</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767115#M37496</link>
      <description>&lt;P&gt;Hi MM,&lt;/P&gt;&lt;P&gt;Please let me be sure I understand the issue correctly.&amp;nbsp; It appears to me that (a) the binomial option of the tables statement in Proc Freq lets one calculate confidence intervals using various methods (exact, Wald, score, etc), but (b) in testing a hypothesis comparing an observed proportion to a hypothesized value (e.g., 0.07) that test is always the same, regardless of the method used for estimating confidence intervals.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, for example, if you ask for a Clopper-Pearson confidence interval, SAS will calculate that; but if you also request a hypothesis test, SAS will always use an asymptotic (probably Wald) method. Is that what you've found?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll try to look into this further.&amp;nbsp;Note, though, that if the hypothesized rate (0.07) falls outside the confidence limits for the observed data (however those are calculated), some people might take that as sufficient evidence to reject H0; not sure if that's strictly kosher, though.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Come to think of it, I don't see why one couldn't just examine the binomial distribution for pi = 0.07 and the given sample size n.&amp;nbsp; If k observed successes falls in the lower or upper .025 area of that distribution, one might reject H0:pi =0.07.&amp;nbsp; SAS has built in functions for the cumulative binomial distribution, so one could perform a hypothesis test and get a p-value that way.&lt;BR /&gt;&lt;BR /&gt;What I'm also wondering at this point is whether Clopper-Pearson is only designed to supply confidence intervals, not to perform hypothesis tests. For the latter, exact binomial distributions might be better.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;--&lt;/P&gt;&lt;P&gt;John Uebersax&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 20:17:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767115#M37496</guid>
      <dc:creator>jsuebersax</dc:creator>
      <dc:date>2021-09-10T20:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: compute an exact confidence interval for a single proportion by hand to match output from proc f</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767150#M37497</link>
      <description>&lt;P&gt;More info. You wrote:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; Also when I am working with single binomial proportion, how is Fishers exact test computed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fisher's exact test only applies to two-way tables. According to SAS documentation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;For one-way tables, PROC FREQ provides exact p-values for the &lt;FONT color="#000000"&gt;&lt;STRONG&gt;binomial proportion test&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;My guess is that the "binomial proportion test" is basically what I mentioned in my previous answer — i.e., based on the cumulative binomial probability distribution for some hypothesized population proportion and given sample size N.&lt;/P&gt;&lt;P&gt;This code&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data;
   y = 1 - cdf('BINOM', 34, .7, 40);
   put y;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;gives the probability of getting 35 or more successes out of 40 trials as 0.008618. That's the same value I get for the One-sided Exact Test using these lines:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
  do i = 1 to 35; x = 1; output; end;
  do i = 1 to 5; x = 2; output; end;
run;
proc freq data = one;
  tables x / binomial(exact score p=0.7);
  exact binomial;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;p.s. My previous reply mistakenly used p = 0.07, instead of 0.7 as in your question.&lt;/P&gt;&lt;P&gt;--&lt;/P&gt;&lt;P&gt;John Uebersax&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 22:57:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767150#M37497</guid>
      <dc:creator>jsuebersax</dc:creator>
      <dc:date>2021-09-10T22:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: compute an exact confidence interval for a single proportion by hand to match output from proc f</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767163#M37498</link>
      <description>&lt;P&gt;John,&lt;/P&gt;
&lt;P&gt;Thank you for your reply. SAS is not always consistent in proc freq. If you look at my calculations in the enclosed file you will see that the Wald test and Wald confidence interval do not appear on the SAS output on page 1. I'm trying to figure out what exact test is being computed and how? Can you help?&lt;/P&gt;</description>
      <pubDate>Sat, 11 Sep 2021 01:57:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767163#M37498</guid>
      <dc:creator>MaryA_Marion</dc:creator>
      <dc:date>2021-09-11T01:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: compute exact confidence interval for single proportion by hand to match output from proc freq</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767165#M37499</link>
      <description>&lt;P&gt;I did not see this just when I replied to your original correspondence. I like what you did. I need to study this carefully. My nonparametric class was a long time ago. Another class always seemed more relevant. I need to turn that around. It is very relevant at this time.&amp;nbsp; MM&lt;/P&gt;</description>
      <pubDate>Sat, 11 Sep 2021 02:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767165#M37499</guid>
      <dc:creator>MaryA_Marion</dc:creator>
      <dc:date>2021-09-11T02:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: compute an exact confidence interval for a single proportion by hand to match output from proc f</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767208#M37503</link>
      <description>&lt;P&gt;I closed this question too quickly. Please remain open. CLopper-Pearson and Wilson Score stats for p=.875 need to be done by hand. I am getting a different answer for wilson. Continuity correction was not added?&amp;nbsp; MM&lt;/P&gt;</description>
      <pubDate>Sat, 11 Sep 2021 15:28:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767208#M37503</guid>
      <dc:creator>MaryA_Marion</dc:creator>
      <dc:date>2021-09-11T15:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: compute an exact confidence interval for a single proportion by hand to match output from proc f</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767299#M37510</link>
      <description>&lt;P&gt;Conclusion after a lot of study.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Clopper-Pearson estimation method is based on the exact binomial distribution, and not a large sample normal approximation. Solving the enclosed equations for p setting n k and alpha will give interval bounds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know how to do this in SAS (preferably not in proc iml) ?&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 01:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767299#M37510</guid>
      <dc:creator>MaryA_Marion</dc:creator>
      <dc:date>2021-09-13T01:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: compute an exact confidence interval for a single proportion by hand to match output from proc f</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767342#M37517</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16492"&gt;@MaryA_Marion&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The formula for the Clopper-Pearson confidence interval can be found in subsection&amp;nbsp;&lt;EM&gt;Exact (Clopper-Pearson) Confidence Limits&lt;/EM&gt; under&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_freq_details37.htm" target="_blank" rel="noopener"&gt;Binomial Proportion&lt;/A&gt; in the PROC FREQ documentation → Details → Statistical Computations. In a DATA step it can be implemented as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cpci;
k=35; /* number of items in category of interest */
n=40; /* total sample size */
alpha=0.05; /* 1 - confidence level */
if k&amp;gt;0 then lcl=1/(1+(n-k+1)/(k*finv(alpha/2,2*k,2*(n-k+1)))); else lcl=0;
if k&amp;lt;n then ucl=1/(1+(n-k)/((k+1)*finv(1-alpha/2,2*(k+1),2*(n-k)))); else ucl=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Sep 2021 14:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767342#M37517</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-09-13T14:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: compute an exact confidence interval for a single proportion by hand to match output from proc f</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767410#M37519</link>
      <description>&lt;P&gt;I was expecting summation code but you approached it differently. Please see output in pdf file enclosed. Note the confidence intervals look like one sided confidence intervals for p=0 and 1. Can I say they are one-sided?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know how to do summation code outside of proc iml ie using base SAS?&amp;nbsp; Please see attached tiff.pdf file. I am trying to improve my computational skills.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 13:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767410#M37519</guid>
      <dc:creator>MaryA_Marion</dc:creator>
      <dc:date>2021-09-13T13:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: compute an exact confidence interval for a single proportion by hand to match output from proc f</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767453#M37525</link>
      <description>&lt;P&gt;You can use the summation formulas to &lt;EM&gt;verify&lt;/EM&gt; the confidence limits. In the non-degenerate case 0&amp;lt;&lt;EM&gt;x&lt;/EM&gt;&amp;lt;&lt;EM&gt;n&lt;/EM&gt;&amp;nbsp;(note that the &lt;EM&gt;x&lt;/EM&gt; in your formula corresponds to variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;k&lt;/FONT&gt; in my code) both the lower tail probability and the upper tail probability should be &lt;FONT face="symbol"&gt;a&lt;/FONT&gt;/2 (for a two-sided 100(1-&lt;FONT face="symbol"&gt;a&lt;/FONT&gt;)% confidence interval). See variables &lt;FONT face="courier new,courier"&gt;ltailp&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;utailp&lt;/FONT&gt; in the code below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data chk(drop=i);
set cpci;
do i=0 to k;
  ltailp+comb(n,i)*ucl**i*ifn(1-ucl | n-i, 1-ucl, 1)**(n-i);
end;
do i=k to n;
  utailp+comb(n,i)*ifn(lcl | i, lcl, 1)**i*(1-lcl)**(n-i);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the degenerate cases (&lt;EM&gt;x&lt;/EM&gt;=0, &lt;EM&gt;x&lt;/EM&gt;=&lt;EM&gt;n&lt;/EM&gt;) one of the tail probabilities is trivially 1 while the other is &lt;FONT face="symbol"&gt;a&lt;/FONT&gt;/2. The non-trivial of the two confidence limits is in fact a one-sided confidence limit, &lt;EM&gt;but&lt;/EM&gt; its confidence level is 1-&lt;FONT face="symbol"&gt;a&lt;/FONT&gt;/2, not 1-&lt;FONT face="symbol"&gt;a&lt;/FONT&gt;. This interpretation holds for the non-degenerate case as well: For example, the lower limit of a two-sided exact 95% CI equals the lower limit of an upper one-sided exact 97.5% CI. Similarly,&amp;nbsp;the upper limit of a two-sided exact 95% CI equals the upper limit of a lower one-sided exact 97.5% CI. If the statistical plan is to compute a &lt;EM&gt;two-sided exact 95% confidence interval&lt;/EM&gt;, then this is the correct description of the interval also in the degenerate cases.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 15:52:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/compute-an-exact-confidence-interval-for-a-single-proportion-by/m-p/767453#M37525</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-09-13T15:52:22Z</dc:date>
    </item>
  </channel>
</rss>

