<?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 Quantiles for Observations from  a Triangular Distribution in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/845577#M41868</link>
    <description>&lt;P&gt;The QUANTILE function lists several distributions but the TRIANGULAR distribution is not one of them.&amp;nbsp; The RAND function can compute random variables from a triangular distribution.&amp;nbsp; Suppose I have observations from a triangular distribution, how do I compute their quantiles?&amp;nbsp; It's easy for distributions that the QUANTILE allows, but the triangle distribution isn't one of them.&amp;nbsp; Any code is appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 21 Nov 2022 22:56:27 GMT</pubDate>
    <dc:creator>PaulN</dc:creator>
    <dc:date>2022-11-21T22:56:27Z</dc:date>
    <item>
      <title>Quantiles for Observations from  a Triangular Distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/845577#M41868</link>
      <description>&lt;P&gt;The QUANTILE function lists several distributions but the TRIANGULAR distribution is not one of them.&amp;nbsp; The RAND function can compute random variables from a triangular distribution.&amp;nbsp; Suppose I have observations from a triangular distribution, how do I compute their quantiles?&amp;nbsp; It's easy for distributions that the QUANTILE allows, but the triangle distribution isn't one of them.&amp;nbsp; Any code is appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2022 22:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/845577#M41868</guid>
      <dc:creator>PaulN</dc:creator>
      <dc:date>2022-11-21T22:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Quantiles for Observations from  a Triangular Distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/845597#M41869</link>
      <description>&lt;P&gt;Simulation and PROC UNIVARIATE?&lt;/P&gt;
&lt;P&gt;or Calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 03:11:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/845597#M41869</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-11-22T03:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: Quantiles for Observations from  a Triangular Distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/845606#M41870</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/376594"&gt;@PaulN&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The QUANTILE function lists several distributions but the TRIANGULAR distribution is not one of them.&amp;nbsp; The RAND function can compute random variables from a triangular distribution.&amp;nbsp; Suppose I have observations from a triangular distribution, how do I compute their quantiles?&amp;nbsp; It's easy for distributions that the QUANTILE allows, but the triangle distribution isn't one of them.&amp;nbsp; Any code is appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you know the parameters of the trangular distribution?&amp;nbsp; I.e. the minimum (a), maximum (b) and mode (c)?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, then according to&amp;nbsp;&lt;A href="https://github.com/distributions-io/triangular-quantile" target="_self"&gt;https://github.com/distributions-io/triangular-quantile&lt;/A&gt;&amp;nbsp;the formula for quantiles (q) of a triangular distribution is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if p &amp;lt; (c-a)/(b-a) then q= a + sqrt((b-a)*(c-a)*p) ;
  else q= b - sqrt((b-a)*(b-c)*(1-p)) ; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;p is the cumulative distribution level for which you want a quantile&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; and&lt;/LI&gt;
&lt;LI&gt;(c-a)/(b-a) is the cumulative distribution at the mode value c&amp;nbsp; (i.e.&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;F(c)&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp; )&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 22 Nov 2022 04:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/845606#M41870</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-11-22T04:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Quantiles for Observations from  a Triangular Distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/845701#M41877</link>
      <description>&lt;P&gt;I do know the minimum (a), maximum (b), and mode (c).&lt;/P&gt;&lt;P&gt;minimum = 0&amp;nbsp;&lt;/P&gt;&lt;P&gt;maximum = 1&lt;/P&gt;&lt;P&gt;mode = 0.2&lt;/P&gt;&lt;P&gt;Height of triangle = 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll use your code and see what I get.&amp;nbsp; I'll compare it to my hand computations.&amp;nbsp; Thank you for the help.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 16:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/845701#M41877</guid>
      <dc:creator>PaulN</dc:creator>
      <dc:date>2022-11-22T16:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: Quantiles for Observations from  a Triangular Distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/847363#M41952</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the triangle distribution that I'm attempting to get SAS to compute quantiles.&amp;nbsp; When I do it by hand I get the following but when I run the code it doesn't match.&amp;nbsp; Any suggestions?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaulN_2-1669931690974.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77929i078DB6F35ADBDFF2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PaulN_2-1669931690974.png" alt="PaulN_2-1669931690974.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;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaulN_1-1669931659034.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77928i11762ACBD33DA39E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PaulN_1-1669931659034.png" alt="PaulN_1-1669931659034.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;data triangle;&lt;BR /&gt;input x;&lt;BR /&gt;datalines;&lt;BR /&gt;0.1&lt;BR /&gt;0.2&lt;BR /&gt;0.3&lt;BR /&gt;0.4&lt;BR /&gt;0.5&lt;BR /&gt;0.6&lt;BR /&gt;0.7&lt;BR /&gt;0.8&lt;BR /&gt;0.9&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data triangle_percentile;&lt;BR /&gt;set triangle;&lt;/P&gt;&lt;P&gt;/*a=minimum, b=maximum, c=mode*/&lt;BR /&gt;a=0;&lt;BR /&gt;b=1;&lt;BR /&gt;c=0.2;&lt;/P&gt;&lt;P&gt;if x &amp;lt;= (c-a)/(b-a) then&lt;BR /&gt;q=a + sqrt((b-a)*(c-a)*x);&lt;BR /&gt;else&lt;BR /&gt;q=b - sqrt((b-a)*(b-c)*(1-x));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 21:57:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/847363#M41952</guid>
      <dc:creator>PaulN</dc:creator>
      <dc:date>2022-12-01T21:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: Quantiles for Observations from  a Triangular Distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/847374#M41954</link>
      <description>&lt;P&gt;Here's what I came up with. It seems to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data triangle_percentile;&lt;BR /&gt;set triangle;&lt;/P&gt;&lt;P&gt;/*a=minimum, b=maximum, c=mode h =height*/&lt;/P&gt;&lt;P&gt;/*using the 1/2*base*height for a triangle&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/P&gt;&lt;P&gt;/*and slope = (y2-y1)/(x2-x1), which is either&amp;nbsp; &amp;nbsp;*/&lt;/P&gt;&lt;P&gt;/* h/(c-a) for x&amp;lt;=c or h/(b-c) for x &amp;gt; c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; */&lt;/P&gt;&lt;P&gt;/*the negative sign for the slope for the latter&amp;nbsp; &amp;nbsp;*/&lt;/P&gt;&lt;P&gt;/is the minus sign after the 1.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;BR /&gt;a=0;&lt;BR /&gt;b=1;&lt;BR /&gt;c=0.2;&lt;/P&gt;&lt;P&gt;h=2;&lt;/P&gt;&lt;P&gt;if x &amp;lt;= c then&lt;BR /&gt;q= 0.5*(x-a)*(h/(c-a))*x;&lt;BR /&gt;else&lt;BR /&gt;q=1 - 0.5*(b-x)*(h/(b-c))*(1-x);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 23:00:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/847374#M41954</guid>
      <dc:creator>PaulN</dc:creator>
      <dc:date>2022-12-01T23:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: Quantiles for Observations from  a Triangular Distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/847443#M41959</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/376594"&gt;@PaulN&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Here's what I came up with. It seems to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data triangle_percentile;&lt;BR /&gt;set triangle;&lt;/P&gt;
&lt;P&gt;/*a=minimum, b=maximum, c=mode h =height*/&lt;/P&gt;
&lt;P&gt;/*using the 1/2*base*height for a triangle&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/P&gt;
&lt;P&gt;/*and slope = (y2-y1)/(x2-x1), which is either&amp;nbsp; &amp;nbsp;*/&lt;/P&gt;
&lt;P&gt;/* h/(c-a) for x&amp;lt;=c or h/(b-c) for x &amp;gt; c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; */&lt;/P&gt;
&lt;P&gt;/*the negative sign for the slope for the latter&amp;nbsp; &amp;nbsp;*/&lt;/P&gt;
&lt;P&gt;/is the minus sign after the 1.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;BR /&gt;a=0;&lt;BR /&gt;b=1;&lt;BR /&gt;c=0.2;&lt;/P&gt;
&lt;P&gt;h=2;&lt;/P&gt;
&lt;P&gt;if x &amp;lt;= c then&lt;BR /&gt;q= 0.5*(x-a)*(h/(c-a))*x;&lt;BR /&gt;else&lt;BR /&gt;q=1 - 0.5*(b-x)*(h/(b-c))*(1-x);&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/376594"&gt;@PaulN&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your algorithm correctly computes the values &lt;EM&gt;of the cumulative distribution function (CDF) from given quantiles&lt;/EM&gt;. (For general values of &lt;FONT face="courier new,courier"&gt;a&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;b&lt;/FONT&gt; the formulas should read&lt;/P&gt;
&lt;PRE&gt;q = 0.5*(x-a)*(h/(c-a))*&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;(&lt;/FONT&gt;&lt;/STRONG&gt;x&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;-a)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;PRE&gt;q = 1 - 0.5*(b-x)*(h/(b-c))*(&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;b&lt;/STRONG&gt;&lt;/FONT&gt;-x)&lt;/PRE&gt;
&lt;P&gt;respectively, but since a=0 and b=1 in your example, you get the correct results.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you set out to compute &lt;EM&gt;quantiles (from cumulative probabilities)&lt;/EM&gt;&amp;nbsp;like SAS's &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0uhywbqfucg6qn18woziy41flqp.htm" target="_blank" rel="noopener"&gt;QUANTILE function&lt;/A&gt;&amp;nbsp;-- the &lt;EM&gt;inverse&lt;/EM&gt; function of the CDF. For that purpose&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;'s algorithm is correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, to answer the typical question "What is the 95% quantile of that triangular distribution?", his formula yields the 0.8 in the &lt;EM&gt;left&lt;/EM&gt; column of your table from the 0.95 (=95%) in the &lt;EM&gt;right&lt;/EM&gt; column:&lt;/P&gt;
&lt;PRE&gt;1 - sqrt((1-0)*(1-0.2)*(1-&lt;STRONG&gt;0.95&lt;/STRONG&gt;)) = &lt;STRONG&gt;0.8&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;(mathematically; in SAS under Windows the result deviates from 0.8 by a tiny rounding error due to numeric representation issues).&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 13:04:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/847443#M41959</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-12-02T13:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Quantiles for Observations from  a Triangular Distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/847446#M41961</link>
      <description>&lt;P&gt;Thanks for the clarification.&amp;nbsp; I should have stated my problem differently.&amp;nbsp; Your help is appreciated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 14:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/847446#M41961</guid>
      <dc:creator>PaulN</dc:creator>
      <dc:date>2022-12-02T14:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Quantiles for Observations from  a Triangular Distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/847449#M41962</link>
      <description>&lt;P&gt;You're welcome. So, you really wanted to extend the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0n7cce4a3gfqkn1vr0p1x0of99s.htm" target="_blank" rel="noopener"&gt;&lt;EM&gt;CDF&lt;/EM&gt; function&lt;/A&gt; to the triangular distribution, not the &lt;EM&gt;QUANTILE&lt;/EM&gt; function mentioned in your initial post. (Otherwise&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461" target="_blank" rel="noopener"&gt;mkeintz&lt;/A&gt;'s reply, not my clarification, should be marked as the accepted solution.) Indeed, rereading your question "&lt;SPAN&gt;Suppose I have observations from a triangular distribution, how do I compute their quantiles?" it sounds like you start with observations&amp;nbsp;&lt;FONT face="courier new,courier"&gt;x&lt;/FONT&gt;&amp;nbsp;between &lt;FONT face="courier new,courier"&gt;a&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;b&lt;/FONT&gt;&amp;nbsp;and want to compute cumulative probabilities &lt;FONT face="courier new,courier"&gt;p&lt;/FONT&gt; (which you denote with &lt;FONT face="courier new,courier"&gt;q&lt;/FONT&gt;), not vice versa.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 14:31:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Quantiles-for-Observations-from-a-Triangular-Distribution/m-p/847449#M41962</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-12-02T14:31:18Z</dc:date>
    </item>
  </channel>
</rss>

