<?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: Calculating a p-value in a script in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Calculating-a-p-value-in-a-script/m-p/583189#M78935</link>
    <description>&lt;P&gt;Thanks again Ross, much appreciated&lt;/P&gt;</description>
    <pubDate>Mon, 19 Dec 2022 05:02:55 GMT</pubDate>
    <dc:creator>Mickyboy</dc:creator>
    <dc:date>2022-12-19T05:02:55Z</dc:date>
    <item>
      <title>Calculating a p-value in a script</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-a-p-value-in-a-script/m-p/580060#M78725</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;l know l am doing something wrong here, but l can't see it at the moment, l am wanting the two-tailed p-value for a difference in two means and am using the following script&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt5 &amp;lt;&amp;lt; New Column(" t-Value", Numeric, Continuous, Format( "Fixed Dec", 15, 3), Formula( t Quantile (0.95,:"N(Data) VPP"n + :"N(Data) Commercial"n -2)));

dt5 &amp;lt;&amp;lt; New Column( "p-Value", Numeric, Continuous, Format( "Fixed Dec", 15, 3), Formula( t Distribution (:"T-Value"n,:"N(Data) VPP"n + :"N(Data) Commercial"n - 1 )));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;can anyone please offer some advice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Mick.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:04:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-a-p-value-in-a-script/m-p/580060#M78725</guid>
      <dc:creator>Mickyboy</dc:creator>
      <dc:date>2023-06-09T16:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating a p-value in a script</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-a-p-value-in-a-script/m-p/580439#M78752</link>
      <description>&lt;P&gt;There a couple things here:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The script is calculating the p-value based on the &lt;EM&gt;critical&lt;/EM&gt; t-value (calculated on the first line) instead of the &lt;EM&gt;observed&lt;/EM&gt; t-value. The latter is the difference in means divided by the standard error of the difference.&lt;/LI&gt;
&lt;LI&gt;The t Distribution() call is calculating the proportion of the distribution less than the t-value, which isn't quite the p-value you're looking for. Calculating the two-tailed p-value requires some simple arithmetic from here (see example).&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If we can assume the data table has at minimum the by-group sample sizes, means, and standard deviations in their own columns, then here's some JSL that'll do what you want. Try it out on the attached example table. Note that I've included an intermediate step of calculating a pooled standard deviation column to improve readability of the formula for the t-value column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 );

dt = Data Table( "Example.jmp" );

dt &amp;lt;&amp;lt; New Column( "Pooled stdev",
	Numeric,
	Continuous,
	Format( "Fixed Dec", 15, 3 ),
	Formula(
		Sqrt( ((:Group A n - 1) * :Group A stdev ^ 2 + (:Group B n - 1) * :Group B stdev ^ 2) / (:Group A n + :Group B n - 2) )
	)
);

dt &amp;lt;&amp;lt; New Column( " t-Value", 
	Numeric, 
	Continuous, 
	Format( "Fixed Dec", 15, 3), 
	Formula( 
		(:Group A mean - :Group B mean) / (:Pooled stdev * Sqrt( 1 / :Group A n + 1 / :Group B n) )	
	) 
);

dt &amp;lt;&amp;lt; New Column( "p-Value", 
	Numeric, 
	Continuous, 
	Format( "Fixed Dec", 15, 3 ), 
	Formula( 
		( 1 - t Distribution( Abs( :"t-Value"n ), :Group A n + :Group B n - 2 ) ) * 2
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2022 19:23:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-a-p-value-in-a-script/m-p/580439#M78752</guid>
      <dc:creator>Ross_Metusalem</dc:creator>
      <dc:date>2022-12-12T19:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating a p-value in a script</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-a-p-value-in-a-script/m-p/582314#M78884</link>
      <description>&lt;P&gt;Hi Ross,&lt;/P&gt;&lt;P&gt;Thanks for your reply, how does this look&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt5 &amp;lt;&amp;lt; New Column( "Difference in Mean", Numeric, Continuous, Format( "Fixed Dec", 15, 3 ), Formula( :"Mean(Data) VPP"n - :"Mean(Data) Commercial"n ) );	

dt5 &amp;lt;&amp;lt; New Column( "Pooled Std Dev", Numeric, Continuous, Format( "Fixed Dec", 15, 3 ), Formula( sqrt(((:"N(Data) VPP"n - 1)* :"Std Dev(Data) VPP"n ^ 2  + (:"N(Data) Commercial"n - 1) * :"Std Dev(Data) Commercial"n ^ 2 )  / (:"N(Data) VPP"n + :"N(Data) Commercial"n - 2)))) ;	

dt5 &amp;lt;&amp;lt; New Column( "Lower 90% Confidence Interval", Numeric, Continuous, Format( "Fixed Dec", 15, 3 ), Formula( (:"Mean(Data) VPP"n - :"Mean(Data) Commercial"n  ) - t Quantile (0.95,:"N(Data) VPP"n + :"N(Data) Commercial"n -2) * (:Pooled Std Dev * sqrt(( 1/:"N(Data) VPP"n) + (1/:"N(Data) Commercial"n )) )));

dt5 &amp;lt;&amp;lt; New Column( "Upper 90% Confidence Interval", Numeric, Continuous, Format( "Fixed Dec", 15, 3), Formula( (:"Mean(Data) VPP"n - :"Mean(Data) Commercial"n  ) + t Quantile (0.95,:"N(Data) VPP"n + :"N(Data) Commercial"n -2) * (:Pooled Std Dev * sqrt(( 1/:"N(Data) VPP"n) + (1/:"N(Data) Commercial"n )) )));

dt5 &amp;lt;&amp;lt; New Column( "Pooled Variance", Numeric, Continuous, Format( "Fixed Dec", 15, 3), Formula(:Pooled Std Dev ^ 2));

dt5 &amp;lt;&amp;lt; New Column(" Std Error for t-Value", Numeric, Continuous, Format( "Fixed Dec", 15, 3), Formula(sqrt (:Pooled Variance * ( 1/:"N(Data) VPP"n + 1/ :"N(Data) Commercial"n ) )));

dt5 &amp;lt;&amp;lt; New Column(" t-stat", Numeric, Continuous, Format( "Fixed Dec", 15, 3), Formula((Abs (:"Mean(Data) VPP"n - :"Mean(Data) Commercial"n - 0)) / :"Std Error for t-Value"n));

dt5 &amp;lt;&amp;lt; New Column( "one tail p-Value", Numeric, Continuous, Format( "Fixed Dec", 15, 4), Formula(1 - t Distribution (:"t-stat"n,:"N(Data) VPP"n + :"N(Data) Commercial"n - 2 )));

dt5 &amp;lt;&amp;lt; New Column( "two tail p-value", Numeric,	Continuous, Format( "Fixed Dec", 12, 4 ),Formula( :"one tail p-Value"n * 2 ));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 22:45:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-a-p-value-in-a-script/m-p/582314#M78884</guid>
      <dc:creator>Mickyboy</dc:creator>
      <dc:date>2022-12-15T22:45:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating a p-value in a script</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-a-p-value-in-a-script/m-p/582590#M78896</link>
      <description>&lt;P&gt;I haven't gone through each equation in full detail so definitely double-check everything yourself too. But with that said, I only caught one thing you'll probably want to change: The formula for the t-statistic takes the absolute value of the difference in means, which means that your t-statistic will always come out positive when it should be negative any time the VPP mean is lower than the Commercial mean. I used the Abs() function in my example only to ensure that the p-value would be calculated correctly regardless of the sign of the t-statistic. You'll probably want to do the same.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 14:04:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-a-p-value-in-a-script/m-p/582590#M78896</guid>
      <dc:creator>Ross_Metusalem</dc:creator>
      <dc:date>2022-12-16T14:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating a p-value in a script</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-a-p-value-in-a-script/m-p/583189#M78935</link>
      <description>&lt;P&gt;Thanks again Ross, much appreciated&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2022 05:02:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-a-p-value-in-a-script/m-p/583189#M78935</guid>
      <dc:creator>Mickyboy</dc:creator>
      <dc:date>2022-12-19T05:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating a p-value in a script</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-a-p-value-in-a-script/m-p/589153#M79410</link>
      <description>&lt;P&gt;Thanks for the solution.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 05:42:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-a-p-value-in-a-script/m-p/589153#M79410</guid>
      <dc:creator>TraciThompson</dc:creator>
      <dc:date>2023-01-12T05:42:55Z</dc:date>
    </item>
  </channel>
</rss>

