<?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: Bayesian approach to a two sample t test in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Bayesian-approach-to-a-two-sample-t-test/m-p/851022#M42133</link>
    <description>Sorry . I am not familiar with PROC MCMC. Maybe &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13633"&gt;@StatDave&lt;/a&gt; know more things.&lt;BR /&gt;But if you want compare mean between groups, I think you need LSMEAN statement.&lt;BR /&gt;&lt;BR /&gt;lsmeans status/diff cl;</description>
    <pubDate>Sat, 24 Dec 2022 08:39:07 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-12-24T08:39:07Z</dc:date>
    <item>
      <title>Bayesian approach to a two sample t test</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Bayesian-approach-to-a-two-sample-t-test/m-p/850004#M42079</link>
      <description>&lt;P&gt;Is there a way to use a bayesian approach to compare the means of two independent samples? Can proc mcmc handle something like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, I have two independent samples from the same underlying population:&lt;BR /&gt;Sample 1: n = 500, mean = 83.8, standard deviation = 24.7&lt;/P&gt;
&lt;P&gt;Sample 2: n = 1000, mean = 86.1, standard deviation = 25.8&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way I can model the difference between the means using proc mcmc without the underlying data?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My only thought is to create a posterior distribution like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Compute the posterior distributions for the population means */
data post;
	do i = 1 to 10000;
		do x= 0 to 100 by .1;
			sample1  = pdf('Normal', x, 83.8, 24.7);
			sample2  = pdf('Normal', x, 86.1, 25.8);
		output;
		end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 04:57:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Bayesian-approach-to-a-two-sample-t-test/m-p/850004#M42079</guid>
      <dc:creator>supp</dc:creator>
      <dc:date>2022-12-16T04:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: Bayesian approach to a two sample t test</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Bayesian-approach-to-a-two-sample-t-test/m-p/850049#M42080</link>
      <description>&lt;P&gt;Yes. See this StackExchange article for references and a discussion that shows how to define the likelihood and priors: &lt;A href="https://stats.stackexchange.com/questions/130389/bayesian-equivalent-of-two-sample-t-test" target="_self"&gt;"Bayesian equivalent of two sample t-test."&lt;/A&gt; The article uses R and someone reproduced it in Python.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 11:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Bayesian-approach-to-a-two-sample-t-test/m-p/850049#M42080</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-12-16T11:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Bayesian approach to a two sample t test</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Bayesian-approach-to-a-two-sample-t-test/m-p/850055#M42086</link>
      <description>&lt;P&gt;You could try BAYES statement of PROC GENMOD .&lt;/P&gt;
&lt;P&gt;Or calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13633"&gt;@StatDave&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc genmod data=sashelp.heart;
class status;
model weight = status / dist=normal link=identity;
lsmeans status/diff cl;
bayes seed=1 coeffprior=normal;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Dec 2022 12:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Bayesian-approach-to-a-two-sample-t-test/m-p/850055#M42086</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-12-16T12:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Bayesian approach to a two sample t test</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Bayesian-approach-to-a-two-sample-t-test/m-p/850959#M42129</link>
      <description>&lt;P&gt;To figure this out here is simulated data. The outcome is score. We will try to estimate the coefficient paramater value for group using a linear regression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/**
Simulate data
**/
data _sim1;
	array test [4] _temporary_ (.03184 .08917 .19745 .68152);
	array control [4] _temporary_ (.02376 .10239 .20877 .66508);

		do i= 1 to 500;
			test_dist= rand('tabled', of test[*]);
			group = 1;
				if test_dist= 1 then score= 0;
				if test_dist= 2 then score= 33.33;
				if test_dist= 3 then score= 66.67;
				if test_dist= 4 then score= 100;
				output;
		end;

		do i= 1 to 10000;
			group = 2;
			control_dist= rand('tabled', of control[*]);
				if control_dist= 1 then score= 0;
				if control_dist= 2 then score= 33.33;
				if control_dist= 3 then score= 66.67;
				if control_dist= 4 then score= 100;
				output;
		end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using proc genmode to esitmate the paramater values. Not sure if it is better to treat group as a class variable or just numeric.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc genmod data= _sim1 ;
/* 	class group; */
	model score = group;
	bayes seed= 1 coeffprior=normal nbi= 1000 nmc= 100000 thin= 10 seed= 1
		out= posterior diagnostics=all;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think the diagnostics look good?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="supp_0-1671807122314.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78841iCC9DC8A4EFA7845C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="supp_0-1671807122314.png" alt="supp_0-1671807122314.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The final analysis seems reasonable. Using HPD the impact on score of being in the control group is likely somewhere between -3.0138 and 1.55543 with a maximum liklihood point estimate of -0.7640.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="supp_1-1671807411933.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78842iFC012CE99AC816A5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="supp_1-1671807411933.png" alt="supp_1-1671807411933.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to recreate something similar using PROC MCMC but it doesn't seem to be working as well. Can you see what I am doing wrong?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/**
MCMC approach
**/

proc mcmc data= _sim1 seed=1 nbi=1000 nmc=10000 outpost= simout thin=10;
	parms b0 0 b1 0 s2 1;
	prior b: ~ normal(0, var= 100);
	prior s2 ~ igamma(1, scale= 1);
	
	mu = b0 +( b1 * group);
	
	model score ~ normal(mu, var= s2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The effective sample size if very low and I seem to be getting almost a reversed impact of being in the test group.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="supp_2-1671807586316.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78843i3E8B3524DB76055C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="supp_2-1671807586316.png" alt="supp_2-1671807586316.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2022 15:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Bayesian-approach-to-a-two-sample-t-test/m-p/850959#M42129</guid>
      <dc:creator>supp</dc:creator>
      <dc:date>2022-12-23T15:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Bayesian approach to a two sample t test</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Bayesian-approach-to-a-two-sample-t-test/m-p/851022#M42133</link>
      <description>Sorry . I am not familiar with PROC MCMC. Maybe &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13633"&gt;@StatDave&lt;/a&gt; know more things.&lt;BR /&gt;But if you want compare mean between groups, I think you need LSMEAN statement.&lt;BR /&gt;&lt;BR /&gt;lsmeans status/diff cl;</description>
      <pubDate>Sat, 24 Dec 2022 08:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Bayesian-approach-to-a-two-sample-t-test/m-p/851022#M42133</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-12-24T08:39:07Z</dc:date>
    </item>
  </channel>
</rss>

