<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Stats raving mad</title>
	<atom:link href="http://statsravingmad.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://statsravingmad.wordpress.com</link>
	<description>Do stats drive you mad?</description>
	<lastBuildDate>Wed, 07 Apr 2010 17:00:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='statsravingmad.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Stats raving mad</title>
		<link>http://statsravingmad.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://statsravingmad.wordpress.com/osd.xml" title="Stats raving mad" />
	<atom:link rel='hub' href='http://statsravingmad.wordpress.com/?pushpress=hub'/>
		<item>
		<title>It&#8217;s time,huh?</title>
		<link>http://statsravingmad.wordpress.com/2010/04/07/its-timehuh/</link>
		<comments>http://statsravingmad.wordpress.com/2010/04/07/its-timehuh/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 16:59:53 +0000</pubDate>
		<dc:creator>Manos Parzakonis</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://statsravingmad.wordpress.com/?p=1201</guid>
		<description><![CDATA[Well, i managed to take my personal webspace somewhere out there and of course the first thing to set up was my blog . WordPress, was great but there was limitations you know. At this point I&#8217;d like to present you my new blog address, statsravingmad.com/blog. I hope y&#8217;all follow me there. Please update you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1201&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Well, i managed to take my personal webspace somewhere out there and of course the first thing to set up was my blog <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . WordPress, was great but there was limitations you know. At this point I&#8217;d like to present you my new blog address, <a href="http://statsravingmad.com/blog">statsravingmad.com/blog</a>. I hope y&#8217;all follow me there. Please update you bookmarks&#8230;</p>
<p>CU!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/statsravingmad.wordpress.com/1201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/statsravingmad.wordpress.com/1201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/statsravingmad.wordpress.com/1201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/statsravingmad.wordpress.com/1201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/statsravingmad.wordpress.com/1201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/statsravingmad.wordpress.com/1201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/statsravingmad.wordpress.com/1201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/statsravingmad.wordpress.com/1201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/statsravingmad.wordpress.com/1201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/statsravingmad.wordpress.com/1201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/statsravingmad.wordpress.com/1201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/statsravingmad.wordpress.com/1201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/statsravingmad.wordpress.com/1201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/statsravingmad.wordpress.com/1201/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1201&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://statsravingmad.wordpress.com/2010/04/07/its-timehuh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a327e204e4d170e1949ef27309a13cf5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">soundsofmine</media:title>
		</media:content>
	</item>
		<item>
		<title>In church&#8230;</title>
		<link>http://statsravingmad.wordpress.com/2010/04/02/in-church/</link>
		<comments>http://statsravingmad.wordpress.com/2010/04/02/in-church/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 11:54:51 +0000</pubDate>
		<dc:creator>Manos Parzakonis</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[church]]></category>
		<category><![CDATA[cyann ben version]]></category>
		<category><![CDATA[m83]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://statsravingmad.wordpress.com/?p=1198</guid>
		<description><![CDATA[<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1198&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:center;"><span style="text-align:center; display: block;"><a href="http://statsravingmad.wordpress.com/2010/04/02/in-church/"><img src="http://img.youtube.com/vi/y35DO_WfWvA/2.jpg" alt="" /></a></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/statsravingmad.wordpress.com/1198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/statsravingmad.wordpress.com/1198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/statsravingmad.wordpress.com/1198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/statsravingmad.wordpress.com/1198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/statsravingmad.wordpress.com/1198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/statsravingmad.wordpress.com/1198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/statsravingmad.wordpress.com/1198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/statsravingmad.wordpress.com/1198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/statsravingmad.wordpress.com/1198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/statsravingmad.wordpress.com/1198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/statsravingmad.wordpress.com/1198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/statsravingmad.wordpress.com/1198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/statsravingmad.wordpress.com/1198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/statsravingmad.wordpress.com/1198/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1198&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://statsravingmad.wordpress.com/2010/04/02/in-church/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a327e204e4d170e1949ef27309a13cf5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">soundsofmine</media:title>
		</media:content>
	</item>
		<item>
		<title>Probability manipulations with Mathematica&#8230;</title>
		<link>http://statsravingmad.wordpress.com/2010/04/01/probability-manipulations-with-mathematica/</link>
		<comments>http://statsravingmad.wordpress.com/2010/04/01/probability-manipulations-with-mathematica/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 22:13:53 +0000</pubDate>
		<dc:creator>Manos Parzakonis</dc:creator>
				<category><![CDATA[probability]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[characteristic function]]></category>
		<category><![CDATA[estimation]]></category>
		<category><![CDATA[Mathematica]]></category>
		<category><![CDATA[moment generating function]]></category>

		<guid isPermaLink="false">http://statsravingmad.wordpress.com/?p=1148</guid>
		<description><![CDATA[There comes a time that a statistician needs to do some ananytic calculations. There more than a bunch of tools to use but I usually prefer Mathematica or Maple. Today, I&#8217;m gonna use Mathematica to do a simple exhibition. Let&#8217;s set this example upon the    distribution. pfun = PDF[UniformDistribution[{2*Subscript[θ, 1] - Subscript[θ, 2], 2*Subscript[θ, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1148&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There comes a time that a statistician needs to do some ananytic calculations. There more than a bunch of tools to use but I usually prefer Mathematica or Maple. Today, I&#8217;m gonna use Mathematica to do a simple exhibition.</p>
<p>Let&#8217;s set this example upon the  <img src='http://s0.wp.com/latex.php?latex=U%282+%5Ctheta+_1-%5Ctheta+_2%5Cleq+x%5Cleq+2+%5Ctheta+_1%2B%5Ctheta+_2%29+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='U(2 &#92;theta _1-&#92;theta _2&#92;leq x&#92;leq 2 &#92;theta _1+&#92;theta _2) ' title='U(2 &#92;theta _1-&#92;theta _2&#92;leq x&#92;leq 2 &#92;theta _1+&#92;theta _2) ' class='latex' />  distribution.</p>
<pre>pfun = PDF[UniformDistribution[{2*Subscript[θ, 1] - Subscript[θ, 2],
2*Subscript[θ, 1] + Subscript[θ, 2]}], x]</pre>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cbegin%7Bcases%7D++%5Cfrac%7B1%7D%7B2+%5Ctheta+_2%7D+%26+2+%5Ctheta+_1-%5Ctheta+_2%5Cleq+x%5Cleq+2+%5Ctheta+_1%2B%5Ctheta+_2+%5C%5C++0+%26+%5Ctext%7BTrue%7D++%5Cend%7Bcases%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;begin{cases}  &#92;frac{1}{2 &#92;theta _2} &amp; 2 &#92;theta _1-&#92;theta _2&#92;leq x&#92;leq 2 &#92;theta _1+&#92;theta _2 &#92;&#92;  0 &amp; &#92;text{True}  &#92;end{cases} ' title='&#92;begin{cases}  &#92;frac{1}{2 &#92;theta _2} &amp; 2 &#92;theta _1-&#92;theta _2&#92;leq x&#92;leq 2 &#92;theta _1+&#92;theta _2 &#92;&#92;  0 &amp; &#92;text{True}  &#92;end{cases} ' class='latex' /></p>
<p style="text-align:left;">One of the most intensive calculations is the characteristic function (eq. the moment generating function). This is straightforward to derive.</p>
<pre>cfun=CharacteristicFunction[UniformDistribution[
{2*Subscript[θ, 1]-Subscript[θ, 2],2*Subscript[θ, 1]+Subscript[θ, 2]}],x]</pre>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=-%5Cfrac%7Bi+%5Cleft%28-e%5E%7Bi+x+%5Cleft%282+%5Ctheta+_1-%5Ctheta+_2%5Cright%29%7D%2Be%5E%7Bi+x+%5Cleft%282+%5Ctheta+_1%2B%5Ctheta+_2%5Cright%29%7D%5Cright%29%7D%7B2+x+%5Ctheta+_2%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='-&#92;frac{i &#92;left(-e^{i x &#92;left(2 &#92;theta _1-&#92;theta _2&#92;right)}+e^{i x &#92;left(2 &#92;theta _1+&#92;theta _2&#92;right)}&#92;right)}{2 x &#92;theta _2} ' title='-&#92;frac{i &#92;left(-e^{i x &#92;left(2 &#92;theta _1-&#92;theta _2&#92;right)}+e^{i x &#92;left(2 &#92;theta _1+&#92;theta _2&#92;right)}&#92;right)}{2 x &#92;theta _2} ' class='latex' />.</p>
<p>The Table[] command calculates for us the raw moments for our distribution.</p>
<pre>Table[Limit[D[cfun, {x, n}], x -&gt; 0]/I^n, {n, 4}]</pre>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cleft%5C%7B2+%5Ctheta+_1%2C%5Cfrac%7B1%7D%7B3%7D+%5Cleft%2812+%5Ctheta+_1%5E2%2B%5Ctheta+_2%5E2%5Cright%29%2C2+%5Ctheta+_1+%5Cleft%284+%5Ctheta+_1%5E2%2B%5Ctheta+_2%5E2%5Cright%29%2C16+%5Ctheta+_1%5E4%2B8+%5Ctheta+_1%5E2+%5Ctheta+_2%5E2%2B%5Cfrac%7B%5Ctheta+_2%5E4%7D%7B5%7D%5Cright%5C%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;left&#92;{2 &#92;theta _1,&#92;frac{1}{3} &#92;left(12 &#92;theta _1^2+&#92;theta _2^2&#92;right),2 &#92;theta _1 &#92;left(4 &#92;theta _1^2+&#92;theta _2^2&#92;right),16 &#92;theta _1^4+8 &#92;theta _1^2 &#92;theta _2^2+&#92;frac{&#92;theta _2^4}{5}&#92;right&#92;} ' title='&#92;left&#92;{2 &#92;theta _1,&#92;frac{1}{3} &#92;left(12 &#92;theta _1^2+&#92;theta _2^2&#92;right),2 &#92;theta _1 &#92;left(4 &#92;theta _1^2+&#92;theta _2^2&#92;right),16 &#92;theta _1^4+8 &#92;theta _1^2 &#92;theta _2^2+&#92;frac{&#92;theta _2^4}{5}&#92;right&#92;} ' class='latex' />.</p>
<p>Calculate the sample statistics.</p>
<pre>T=List[8.23,6.9,1.05,4.8,2.03,6.95];
{Mean[T],Variance[T]}</pre>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5C%7B4.99333%2C8.46171%5C%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;{4.99333,8.46171&#92;} ' title='&#92;{4.99333,8.46171&#92;} ' class='latex' />.</p>
<p style="text-align:left;">Now, we can use a simple moment matching technique to get estimates for the parameters.</p>
<pre>Solve[{Mean[T]-2*Subscript[θ, 1]==0,-(2*Subscript[θ, 1])^2+
1/3 (12 Subscript[θ, 1]^2+\!\*SubsuperscriptBox[\(θ\), \(2\), \(2\)])-
Variance[T]==0},{Subscript[θ, 2],Subscript[θ, 1]}]</pre>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cleft%5C%7B%5Cleft%5C%7B%5Ctheta+_1%5Cto+2.49667%2C%5Ctheta+_2%5Cto+-5.03836%5Cright%5C%7D%2C%5Cleft%5C%7B%5Ctheta+_1%5Cto+2.49667%2C%5Ctheta+_2%5Cto+5.03836%5Cright%5C%7D%5Cright%5C%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;left&#92;{&#92;left&#92;{&#92;theta _1&#92;to 2.49667,&#92;theta _2&#92;to -5.03836&#92;right&#92;},&#92;left&#92;{&#92;theta _1&#92;to 2.49667,&#92;theta _2&#92;to 5.03836&#92;right&#92;}&#92;right&#92;} ' title='&#92;left&#92;{&#92;left&#92;{&#92;theta _1&#92;to 2.49667,&#92;theta _2&#92;to -5.03836&#92;right&#92;},&#92;left&#92;{&#92;theta _1&#92;to 2.49667,&#92;theta _2&#92;to 5.03836&#92;right&#92;}&#92;right&#92;} ' class='latex' />.</p>
<p style="text-align:left;">Check the true value for the <img src='http://s0.wp.com/latex.php?latex=%5Ctheta+_2&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;theta _2' title='&#92;theta _2' class='latex' />.</p>
<pre>Reduce[2 Subscript[θ, 1]-Subscript[θ, 2]&lt;=2 Subscript[θ, 1]+Subscript[θ, 2],
Subscript[θ, 2]]</pre>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Ctheta+_1%5Cin+%5Ctext%7BReals%7D%5C%26%5C%26%5Ctheta+_2%5Cgeq+0+.&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;theta _1&#92;in &#92;text{Reals}&#92;&amp;&#92;&amp;&#92;theta _2&#92;geq 0 .' title='&#92;theta _1&#92;in &#92;text{Reals}&#92;&amp;&#92;&amp;&#92;theta _2&#92;geq 0 .' class='latex' /></p>
<p style="text-align:left;">Then, <img src='http://s0.wp.com/latex.php?latex=%5Cleft%5C%7B%5Cleft%5C%7B%5Ctheta+_1%5Cto+2.49667%2C%5Ctheta+_2%5Cto++5.03836%5Cright%5C%7D%5Cright%5C%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;left&#92;{&#92;left&#92;{&#92;theta _1&#92;to 2.49667,&#92;theta _2&#92;to  5.03836&#92;right&#92;}&#92;right&#92;} ' title='&#92;left&#92;{&#92;left&#92;{&#92;theta _1&#92;to 2.49667,&#92;theta _2&#92;to  5.03836&#92;right&#92;}&#92;right&#92;} ' class='latex' />.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/statsravingmad.wordpress.com/1148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/statsravingmad.wordpress.com/1148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/statsravingmad.wordpress.com/1148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/statsravingmad.wordpress.com/1148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/statsravingmad.wordpress.com/1148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/statsravingmad.wordpress.com/1148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/statsravingmad.wordpress.com/1148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/statsravingmad.wordpress.com/1148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/statsravingmad.wordpress.com/1148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/statsravingmad.wordpress.com/1148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/statsravingmad.wordpress.com/1148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/statsravingmad.wordpress.com/1148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/statsravingmad.wordpress.com/1148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/statsravingmad.wordpress.com/1148/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1148&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://statsravingmad.wordpress.com/2010/04/01/probability-manipulations-with-mathematica/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a327e204e4d170e1949ef27309a13cf5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">soundsofmine</media:title>
		</media:content>
	</item>
		<item>
		<title>A von Mises variate&#8230;</title>
		<link>http://statsravingmad.wordpress.com/2010/03/25/a-von-mises-variate/</link>
		<comments>http://statsravingmad.wordpress.com/2010/03/25/a-von-mises-variate/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 16:05:45 +0000</pubDate>
		<dc:creator>Manos Parzakonis</dc:creator>
				<category><![CDATA[probability]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[metropolis]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[von mises]]></category>

		<guid isPermaLink="false">http://statsravingmad.wordpress.com/?p=1124</guid>
		<description><![CDATA[Inspired from a mail that came along the previous random generation post the following question rised : How to draw random variates from the Von Mises distribution? First of all let&#8217;s check the pdf of the probability rule, it is , for . Ok, I admit that Bessels functions can be a bit frightening, but [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1124&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Inspired from a mail that came along the <a href="http://statsravingmad.wordpress.com/2010/03/16/in-search-of-a-random-gamma-variate/">previous</a> random generation post the following question rised :</p>
<blockquote><p>How to draw random variates from the Von Mises distribution?</p></blockquote>
<p>First of all let&#8217;s check the pdf of the probability rule, it is <img src='http://s0.wp.com/latex.php?latex=f%28x%29%3A%3D%5Cfrac%7Be%5E%7Bb+%5Ctext%7BCos%7D%5By-a%5D%7D%7D%7B2+%5Cpi++%5Ctext%7BBesselI%7D%5B0%2Cb%5D%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='f(x):=&#92;frac{e^{b &#92;text{Cos}[y-a]}}{2 &#92;pi  &#92;text{BesselI}[0,b]}' title='f(x):=&#92;frac{e^{b &#92;text{Cos}[y-a]}}{2 &#92;pi  &#92;text{BesselI}[0,b]}' class='latex' />, for <img src='http://s0.wp.com/latex.php?latex=-%5Cpi+%5Cleq+x%5Cleq+%5Cpi+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='-&#92;pi &#92;leq x&#92;leq &#92;pi ' title='-&#92;pi &#92;leq x&#92;leq &#92;pi ' class='latex' />.</p>
<p>Ok, I admit that Bessels functions can be a bit frightening, but there is a work around we can do. The solution is a Metropolis algorithm simulation. It is not necessary to know the normalizing constant, because it will cancel in the computation of the ratio. The following code is adapted from <a href="http://mason.gmu.edu/~jgentle/">James Gentle&#8217;s</a> notes on <a href="http://mason.gmu.edu/~jgentle/csi9723/MathStat.pdf">Mathematical Statistics</a> .</p>
<pre>n &lt;- 1000
x &lt;- rep(NA,n)
a &lt;-1
c &lt;-3
yi &lt;-3
j &lt;-0

i&lt;-2
while (i &lt; n) {
	i&lt;-i+1
	yip1 &lt;- yi + 2*a*runif(1)- 1
	if (yip1 &lt; pi &amp; yip1 &gt; - pi) {
		if (exp(c*(cos(yip1)-cos(yi))) &gt; runif(1)) yi &lt;- yip1
		else yi &lt;- x[i-1]
		x[i] &lt;- yip1
	}
}
hist(x,probability=TRUE,fg = gray(0.7), bty="7")
lines(density(x,na.rm=TRUE),col="red",lwd=2)</pre>
<p><a href="http://statsravingmad.files.wordpress.com/2010/03/vm-rg.jpeg"><img class="aligncenter size-medium wp-image-1142" title="vm.rg" src="http://statsravingmad.files.wordpress.com/2010/03/vm-rg.jpeg?w=342&#038;h=342" alt="" width="342" height="342" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/statsravingmad.wordpress.com/1124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/statsravingmad.wordpress.com/1124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/statsravingmad.wordpress.com/1124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/statsravingmad.wordpress.com/1124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/statsravingmad.wordpress.com/1124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/statsravingmad.wordpress.com/1124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/statsravingmad.wordpress.com/1124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/statsravingmad.wordpress.com/1124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/statsravingmad.wordpress.com/1124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/statsravingmad.wordpress.com/1124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/statsravingmad.wordpress.com/1124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/statsravingmad.wordpress.com/1124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/statsravingmad.wordpress.com/1124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/statsravingmad.wordpress.com/1124/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1124&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://statsravingmad.wordpress.com/2010/03/25/a-von-mises-variate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a327e204e4d170e1949ef27309a13cf5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">soundsofmine</media:title>
		</media:content>

		<media:content url="http://statsravingmad.files.wordpress.com/2010/03/vm-rg.jpeg?w=300" medium="image">
			<media:title type="html">vm.rg</media:title>
		</media:content>
	</item>
		<item>
		<title>R 2.11.0 due date</title>
		<link>http://statsravingmad.wordpress.com/2010/03/24/r-2-11-0-due-date/</link>
		<comments>http://statsravingmad.wordpress.com/2010/03/24/r-2-11-0-due-date/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 22:55:30 +0000</pubDate>
		<dc:creator>Manos Parzakonis</dc:creator>
				<category><![CDATA[infos]]></category>
		<category><![CDATA[announcement]]></category>
		<category><![CDATA[new]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[version]]></category>

		<guid isPermaLink="false">http://statsravingmad.wordpress.com/?p=1111</guid>
		<description><![CDATA[This is the announcement as posted in the mailing list : This is to announce that we plan to release R version 2.11.0 on Thursday, April 22, 2010. Those directly involved should review the generic schedule at http://developer.r-project.org/release-checklist.html The source tarballs will be made available daily (barring build troubles) via http://cran.r-project.org/src/base-prerelease/ For the R Core [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1111&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is the announcement as posted in the <a href="https://stat.ethz.ch/pipermail/r-announce/2010/000517.html">mailing list</a> :</p>
<pre>This is to announce that we plan to release R version 2.11.0 on Thursday,
April 22, 2010.

Those directly involved should review the generic schedule at
<a href="http://developer.r-project.org/release-checklist.html">http://developer.r-project.org/release-checklist.html</a>

The source tarballs will be made available daily (barring build
troubles) via
<a href="http://cran.r-project.org/src/base-prerelease/">http://cran.r-project.org/src/base-prerelease/</a>

For the R Core Team
Peter Dalgaard
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/statsravingmad.wordpress.com/1111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/statsravingmad.wordpress.com/1111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/statsravingmad.wordpress.com/1111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/statsravingmad.wordpress.com/1111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/statsravingmad.wordpress.com/1111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/statsravingmad.wordpress.com/1111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/statsravingmad.wordpress.com/1111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/statsravingmad.wordpress.com/1111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/statsravingmad.wordpress.com/1111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/statsravingmad.wordpress.com/1111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/statsravingmad.wordpress.com/1111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/statsravingmad.wordpress.com/1111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/statsravingmad.wordpress.com/1111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/statsravingmad.wordpress.com/1111/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1111&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://statsravingmad.wordpress.com/2010/03/24/r-2-11-0-due-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a327e204e4d170e1949ef27309a13cf5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">soundsofmine</media:title>
		</media:content>
	</item>
		<item>
		<title>The distribution of rho&#8230;</title>
		<link>http://statsravingmad.wordpress.com/2010/03/21/the-distribution-of-rho/</link>
		<comments>http://statsravingmad.wordpress.com/2010/03/21/the-distribution-of-rho/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 19:11:21 +0000</pubDate>
		<dc:creator>Manos Parzakonis</dc:creator>
				<category><![CDATA[statistics]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[hypothesis]]></category>
		<category><![CDATA[p-value]]></category>
		<category><![CDATA[pearson]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://statsravingmad.wordpress.com/?p=1093</guid>
		<description><![CDATA[There was a post here about obtaining non-standard p-values for testing the correlation coefficient. The R-library SuppDists deals with this problem efficiently. library(SuppDists) plot(function(x)dPearson(x,N=23,rho=0.7),-1,1,ylim=c(0,10),ylab="density") plot(function(x)dPearson(x,N=23,rho=0),-1,1,add=TRUE,col="steelblue") plot(function(x)dPearson(x,N=23,rho=-.2),-1,1,add=TRUE,col="green") plot(function(x)dPearson(x,N=23,rho=.9),-1,1,add=TRUE,col="red");grid() legend("topleft", col=c("black","steelblue","red","green"),lty=1, legend=c("rho=0.7","rho=0","rho=-.2","rho=.9"))&#60;/pre&#62; This is how it looks like, Now, let&#8217;s construct a table of critical values for some arbitrary or not significance levels. q=c(.025,.05,.075,.1,.15,.2) xtabs(qPearson(p=q, N=23, rho [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1093&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There was a post <a href="http://talkstats.com/showthread.php?t=11308">here</a> about obtaining non-standard p-values for testing the correlation coefficient. The R-library</p>
<pre><a href="cran.r-project.org/package=SuppDists">SuppDists</a></pre>
<p>deals with this problem efficiently.</p>
<pre>library(SuppDists)

plot(function(x)dPearson(x,N=23,rho=0.7),-1,1,ylim=c(0,10),ylab="density")
plot(function(x)dPearson(x,N=23,rho=0),-1,1,add=TRUE,col="steelblue")
plot(function(x)dPearson(x,N=23,rho=-.2),-1,1,add=TRUE,col="green")
plot(function(x)dPearson(x,N=23,rho=.9),-1,1,add=TRUE,col="red");grid()

legend("topleft", col=c("black","steelblue","red","green"),lty=1,
		legend=c("rho=0.7","rho=0","rho=-.2","rho=.9"))&lt;/pre&gt;</pre>
<p>This is how it looks like,<br />
<a href="http://statsravingmad.files.wordpress.com/2010/03/rho-dist.jpeg"><br />
</a><a href="http://statsravingmad.files.wordpress.com/2010/03/rho-dist1.jpeg"><img class="aligncenter size-medium wp-image-1097" title="rho.dist" src="http://statsravingmad.files.wordpress.com/2010/03/rho-dist1.jpeg?w=339&#038;h=314" alt="" width="339" height="314" /></a><br />
Now, let&#8217;s construct a table of critical values for some arbitrary or not significance levels.</p>
<pre>q=c(.025,.05,.075,.1,.15,.2)
xtabs(qPearson(p=q, N=23, rho = 0, lower.tail = FALSE, log.p = FALSE) ~ q )
<span style="color:#339966;"># q
#     0.025      0.05     0.075       0.1      0.15       0.2
# 0.4130710 0.3514298 0.3099236 0.2773518 0.2258566 0.1842217</span></pre>
<p>We can calculate p-values as usual too&#8230;</p>
<pre>1-pPearson(.41307,N=23,rho=0)
<span style="color:#339966;"># [1] 0.0250003</span></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/statsravingmad.wordpress.com/1093/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/statsravingmad.wordpress.com/1093/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/statsravingmad.wordpress.com/1093/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/statsravingmad.wordpress.com/1093/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/statsravingmad.wordpress.com/1093/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/statsravingmad.wordpress.com/1093/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/statsravingmad.wordpress.com/1093/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/statsravingmad.wordpress.com/1093/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/statsravingmad.wordpress.com/1093/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/statsravingmad.wordpress.com/1093/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/statsravingmad.wordpress.com/1093/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/statsravingmad.wordpress.com/1093/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/statsravingmad.wordpress.com/1093/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/statsravingmad.wordpress.com/1093/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1093&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://statsravingmad.wordpress.com/2010/03/21/the-distribution-of-rho/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a327e204e4d170e1949ef27309a13cf5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">soundsofmine</media:title>
		</media:content>

		<media:content url="http://statsravingmad.files.wordpress.com/2010/03/rho-dist1.jpeg?w=300" medium="image">
			<media:title type="html">rho.dist</media:title>
		</media:content>
	</item>
		<item>
		<title>Oh, mr counselor!</title>
		<link>http://statsravingmad.wordpress.com/2010/03/19/oh-mr-counselor/</link>
		<comments>http://statsravingmad.wordpress.com/2010/03/19/oh-mr-counselor/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 12:37:06 +0000</pubDate>
		<dc:creator>Manos Parzakonis</dc:creator>
				<category><![CDATA[infos]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[mathematician]]></category>
		<category><![CDATA[short]]></category>
		<category><![CDATA[story]]></category>
		<category><![CDATA[tale]]></category>

		<guid isPermaLink="false">http://statsravingmad.wordpress.com/?p=1081</guid>
		<description><![CDATA[Xm&#8230; There were two men trying to decide what to do for a living.  They went to see a counselor, and he decided that they had good problem solving skills. He tried a test to narrow the area of specialty.  He put each man in a room with a stove, a table, and a pot [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1081&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Xm&#8230;</p>
<blockquote><p>There were two men trying to decide what to do for a  living.  They went to see a counselor, and he decided that they had good  problem solving skills.</p>
<p>He tried a test to narrow the area of specialty.  He put each man in a  room with a stove, a table, and a pot of water on the table.  He said  &#8220;Boil the water&#8221;.  Both men moved the pot from the table to the stove  and turned on the burner to boil the water.  Next, he put them into a  room with a stove, a table, and a pot of water on the floor.  Again, he  said &#8220;Boil the water&#8221;.  The first man put the pot on the stove and  turned on the burner.  The counselor told him to be an Engineer,      because  he could solve each problem individually.  The second man moved the pot  from the floor to the table, and then moved the pot from the table to  the stove and turned on the burner.  The counselor told him to be a  mathematician because he reduced the problem to a previously solved  problem.</p>
<p>- From <a href="http://www.xs4all.nl/%7Ejcdverha/scijokes/6.html">The  Mathematician, The Physicist and The Engineer (and Others)</a></p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/statsravingmad.wordpress.com/1081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/statsravingmad.wordpress.com/1081/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/statsravingmad.wordpress.com/1081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/statsravingmad.wordpress.com/1081/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/statsravingmad.wordpress.com/1081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/statsravingmad.wordpress.com/1081/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/statsravingmad.wordpress.com/1081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/statsravingmad.wordpress.com/1081/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/statsravingmad.wordpress.com/1081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/statsravingmad.wordpress.com/1081/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/statsravingmad.wordpress.com/1081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/statsravingmad.wordpress.com/1081/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/statsravingmad.wordpress.com/1081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/statsravingmad.wordpress.com/1081/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1081&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://statsravingmad.wordpress.com/2010/03/19/oh-mr-counselor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a327e204e4d170e1949ef27309a13cf5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">soundsofmine</media:title>
		</media:content>
	</item>
		<item>
		<title>In search of a random gamma variate&#8230;</title>
		<link>http://statsravingmad.wordpress.com/2010/03/16/in-search-of-a-random-gamma-variate/</link>
		<comments>http://statsravingmad.wordpress.com/2010/03/16/in-search-of-a-random-gamma-variate/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 17:58:05 +0000</pubDate>
		<dc:creator>Manos Parzakonis</dc:creator>
				<category><![CDATA[statistics]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[gamma]]></category>
		<category><![CDATA[generation]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[sampler]]></category>
		<category><![CDATA[simulation]]></category>

		<guid isPermaLink="false">http://statsravingmad.wordpress.com/?p=1022</guid>
		<description><![CDATA[One of the most common exersices given to Statistical Computing,Simulation or relevant classes is the generation of random numbers from a gamma distribution. At first this might seem straightforward in terms of the lifesaving relation that exponential and gamma random variables share. So, it&#8217;s easy to get a gamma random variate using the fact that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1022&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:left;">One of the most common exersices given to Statistical Computing,Simulation or relevant classes is the generation of random numbers from a gamma distribution. At first this might seem straightforward in terms of the lifesaving relation that exponential and gamma random variables share. So, it&#8217;s easy to get a gamma random variate using the fact that</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%7B%7BX%7D_%7Bi%7D%7D%5Ctilde%7B%5C+%7DExp%28%5Clambda+%29%5CRightarrow+%5Csum%5Climits_%7Bi%7D%7B%7B%7BX%7D_%7Bi%7D%7D%7D%5Ctilde%7B%5C+%7DGa%28k%2C%5Clambda+%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='{{X}_{i}}&#92;tilde{&#92; }Exp(&#92;lambda )&#92;Rightarrow &#92;sum&#92;limits_{i}{{{X}_{i}}}&#92;tilde{&#92; }Ga(k,&#92;lambda )' title='{{X}_{i}}&#92;tilde{&#92; }Exp(&#92;lambda )&#92;Rightarrow &#92;sum&#92;limits_{i}{{{X}_{i}}}&#92;tilde{&#92; }Ga(k,&#92;lambda )' class='latex' />.</p>
<p style="text-align:left;">The code to do this is the following</p>
<pre>rexp1 &lt;- function(lambda, n) {
  u &lt;- runif(n)
  x &lt;- -log(u)/lambda
  }

rgamma1 &lt;- function(k, lambda) {
  sum(rexp1(lambda, k))
}</pre>
<p>This works unfortunately only for the case <img src='http://s0.wp.com/latex.php?latex=k%5Cin+%5Cmathbb%7BN%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='k&#92;in &#92;mathbb{N}' title='k&#92;in &#92;mathbb{N}' class='latex' /><br />
<span id="more-1022"></span></p>
<p>In the general case we got to result to more &#8220;complex&#8221; (?) simulation, hence programming. The first technique we gonna use is <a href="http://en.wikipedia.org/wiki/Rejection_sampling">rejection sampling</a>. As the proposal (or proxy or instrumental) density we set the <img src='http://s0.wp.com/latex.php?latex=Ga%28%5Cleft%5Clfloor+k+%5Cright%5Crfloor+%2C%5Clambda+-1%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='Ga(&#92;left&#92;lfloor k &#92;right&#92;rfloor ,&#92;lambda -1)' title='Ga(&#92;left&#92;lfloor k &#92;right&#92;rfloor ,&#92;lambda -1)' class='latex' />. The key to implementation is to maximise the ratio of the two densities, ie</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7Bf%28x%29%7D%7Bg%28x%29%7D%3D%5Cfrac%7B%7B%7Be%7D%5E%7Bx%28-1%2B%5Clambda+%29-x%5Clambda+%7D%7D%7B%7Bx%7D%5E%7B-k%2B%5Calpha+%7D%7D%7B%7B%28%5Clambda+-1%29%7D%5E%7B-k%7D%7D%7B%7B%5Clambda+%7D%5E%7B%5Calpha+%7D%7D%5CGamma+%28k%29%7D%7B%5CGamma+%28%5Calpha+%29%7D%3D%5Cfrac%7B%7B%7Be%7D%5E%7B-x%7D%7D%7B%7Bx%7D%5E%7B-k%2B%5Calpha+%7D%7D%7B%7B%28%5Clambda+-1%29%7D%5E%7B-k%7D%7D%7B%7B%5Clambda+%7D%5E%7B%5Calpha+%7D%7D%5CGamma+%28k%29%7D%7B%5CGamma+%28%5Calpha+%29%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;frac{f(x)}{g(x)}=&#92;frac{{{e}^{x(-1+&#92;lambda )-x&#92;lambda }}{{x}^{-k+&#92;alpha }}{{(&#92;lambda -1)}^{-k}}{{&#92;lambda }^{&#92;alpha }}&#92;Gamma (k)}{&#92;Gamma (&#92;alpha )}=&#92;frac{{{e}^{-x}}{{x}^{-k+&#92;alpha }}{{(&#92;lambda -1)}^{-k}}{{&#92;lambda }^{&#92;alpha }}&#92;Gamma (k)}{&#92;Gamma (&#92;alpha )}' title='&#92;frac{f(x)}{g(x)}=&#92;frac{{{e}^{x(-1+&#92;lambda )-x&#92;lambda }}{{x}^{-k+&#92;alpha }}{{(&#92;lambda -1)}^{-k}}{{&#92;lambda }^{&#92;alpha }}&#92;Gamma (k)}{&#92;Gamma (&#92;alpha )}=&#92;frac{{{e}^{-x}}{{x}^{-k+&#92;alpha }}{{(&#92;lambda -1)}^{-k}}{{&#92;lambda }^{&#92;alpha }}&#92;Gamma (k)}{&#92;Gamma (&#92;alpha )}' class='latex' />.</p>
<p style="text-align:left;">We find the maximum of the ratio along the next lines.</p>
<pre style="text-align:left;">m&lt;-function(x) exp(-x)*x^(-k+a)*(1/(-1+r))^k*(r^a)*gamma(k)/gamma(a)
grid&lt;-seq(0,10,by=.1)
a=3.45
k=3
r=2.06
plot(m(grid)~grid,type="l",col="red")
grid()
ind&lt;-which.max(m(grid))
<span style="color:#339966;"># 6</span>
m.max&lt;-grid[ind]
<span style="color:#339966;"># 0.5</span></pre>
<p>Analytically we can work out that the maximum is achieved at <img src='http://s0.wp.com/latex.php?latex=%5Calpha+-k&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;alpha -k' title='&#92;alpha -k' class='latex' />, then the actual value is <img src='http://s0.wp.com/latex.php?latex=M%3D%5Cfrac%7Bf%28%5Calpha+-k%29%7D%7Bg%28%5Calpha+-k%29%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='M=&#92;frac{f(&#92;alpha -k)}{g(&#92;alpha -k)}' title='M=&#92;frac{f(&#92;alpha -k)}{g(&#92;alpha -k)}' class='latex' />.</p>
<p><a href="http://statsravingmad.files.wordpress.com/2010/03/m-ratio.jpeg"><img class="aligncenter size-medium wp-image-1035" title="m.ratio" src="http://statsravingmad.files.wordpress.com/2010/03/m-ratio.jpeg?w=368&#038;h=299" alt="" width="368" height="299" /></a>Now, we draw variates from the integer gamma until one is accepted.</p>
<p><em>UPDATED</em></p>
<pre>n=200000
a=3.45
k=3
r=2.06
lambda=2.71

sample&lt;-rep(NA,n)

start&lt;-Sys.time()
for (i in 1:n) {
<span style="color:#339966;"># The following is a function tha draws ONE random variate.
# It's useful to have it in this form</span>
 one &lt;- function(a, lambda) {
 k &lt;- floor(a)
 m &lt;-m(a-k)
 while (TRUE) {
 x &lt;- rgamma1(k,lambda-1)
 p.accept &lt;- dgamma(x,a,lambda)/(m*dgamma(x,k,lambda-1))
if (runif(1)&lt;p.accept)
 return(x)
 }
 }
sample[i]&lt;-one(a, lambda)
}
Sys.time()-start
<span style="color:#339966;">
# Time difference of 25.738 secs</span>

grid2 &lt;- seq(0, 10, length.out=100)
plot(grid2, m(a-k)*dgamma(grid2,k,lambda-1), type="l", lty=2, col="red",
 xlab="x", ylab="Density",lwd=2)
lines(grid2, dgamma(grid2,a,lambda), col="green",lwd=2)
lines(density(sample),col="steelblue",lwd=2)
legend("topright", col=c("red","green","steelblue"),lty=c(2,1),
 legend=c("m(a-k)*g(x)","sample dansity","f(x)"))<a href="http://statsravingmad.files.wordpress.com/2010/03/gamma-sampler-density2.jpeg"><img class="aligncenter size-medium wp-image-1079" title="gamma.sampler.density" src="http://statsravingmad.files.wordpress.com/2010/03/gamma-sampler-density2.jpeg?w=333&#038;h=299" alt="" width="333" height="299" /></a></pre>
<p>Not bad!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/statsravingmad.wordpress.com/1022/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/statsravingmad.wordpress.com/1022/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/statsravingmad.wordpress.com/1022/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/statsravingmad.wordpress.com/1022/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/statsravingmad.wordpress.com/1022/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/statsravingmad.wordpress.com/1022/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/statsravingmad.wordpress.com/1022/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/statsravingmad.wordpress.com/1022/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/statsravingmad.wordpress.com/1022/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/statsravingmad.wordpress.com/1022/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/statsravingmad.wordpress.com/1022/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/statsravingmad.wordpress.com/1022/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/statsravingmad.wordpress.com/1022/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/statsravingmad.wordpress.com/1022/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1022&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://statsravingmad.wordpress.com/2010/03/16/in-search-of-a-random-gamma-variate/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a327e204e4d170e1949ef27309a13cf5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">soundsofmine</media:title>
		</media:content>

		<media:content url="http://statsravingmad.files.wordpress.com/2010/03/m-ratio.jpeg?w=300" medium="image">
			<media:title type="html">m.ratio</media:title>
		</media:content>

		<media:content url="http://statsravingmad.files.wordpress.com/2010/03/gamma-sampler-density2.jpeg?w=300" medium="image">
			<media:title type="html">gamma.sampler.density</media:title>
		</media:content>
	</item>
		<item>
		<title>\pi day!</title>
		<link>http://statsravingmad.wordpress.com/2010/03/14/pi-day/</link>
		<comments>http://statsravingmad.wordpress.com/2010/03/14/pi-day/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 20:47:31 +0000</pubDate>
		<dc:creator>Manos Parzakonis</dc:creator>
				<category><![CDATA[probability]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[Buffon's Needle]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[day]]></category>
		<category><![CDATA[estimate]]></category>
		<category><![CDATA[pi]]></category>
		<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://statsravingmad.wordpress.com/?p=1046</guid>
		<description><![CDATA[It&#8217;s π-day today so we gonna have a little fun today with Buffon&#8217;s needle and of course R. A well known approximation to the value of is the experiment tha Buffon performed using a needle of length,. What I do in the next is only to copy from the following file the function estPi and to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1046&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s π-day today so we gonna have a little fun today with Buffon&#8217;s needle and of course R. A well known approximation to the value of <img src='http://s0.wp.com/latex.php?latex=%5Cpi&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;pi' title='&#92;pi' class='latex' /> is the experiment tha Buffon performed using a needle of length,<img src='http://s0.wp.com/latex.php?latex=l&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='l' title='l' class='latex' />. What I do in the next is only to copy from the following file the function estPi and to use an ergodic sample plot&#8230; Lame,huh?</p>
<pre>estPi&lt;- function(n, l=1, t=2) {
 m &lt;- 0
 for (i in 1:n) {
 x &lt;- runif(1)
 theta &lt;- runif(1, min=0, max=pi/2)
 if (x &lt; l/2 * sin(theta)) {
 m &lt;- m +1
 }
 }
 return(2*l*n/(t*m))
}</pre>
<p>So, an estimate would be&#8230;<br />
<span id="more-1046"></span></p>
<pre>estPi(2000,l=1,t=2)
<span style="color:#339966;"># 3.267974</span></pre>
<p>Ok, not that great but for the whole scene it&#8217;s remarkable good! Now, we set some increasing sample sizes to account for the estimation.</p>
<pre>n=8000
r=15
mat=rep(NA,r)
size=rep(NA,r)
for (i in 1:r) {
 size[i]&lt;-n*i
 mat[i]&lt;-estPi(n*i,l=1,t=2)
}
matrix&lt;-expand.grid(size)
matrix[,2]&lt;-mat
names(matrix)&lt;-list("n","pi")
matrix
<span style="color:#339966;">#        n       pi
#1    8000 3.182180
#2   16000 3.165809
#3   24000 3.135615
#4   32000 3.145581
#5   40000 3.138486
#6   48000 3.144860
#7   56000 3.162412
#8   64000 3.111932
#9   72000 3.097574
#10  80000 3.155072
#11  88000 3.157404
#12  96000 3.144139
#13 104000 3.126597
#14 112000 3.150226
#15 120000 3.136599</span></pre>
<p>Which is the best estimate?</p>
<pre>matrix[which.min(abs(matrix[,2]-pi)),]
<span style="color:#339966;">#        n       pi
#   12 96000 3.144139</span>

plot(matrix,type="b");abline(h=pi,col="red",lty=2)</pre>
<p><a href="http://statsravingmad.files.wordpress.com/2010/03/pi-est.jpeg"></a><a href="http://statsravingmad.files.wordpress.com/2010/03/pi-est1.jpeg"><img class="aligncenter size-medium wp-image-1054" title="pi.est" src="http://statsravingmad.files.wordpress.com/2010/03/pi-est1.jpeg?w=337&#038;h=299" alt="" width="337" height="299" /></a><br />
source : [<a href="http://www.genetics.ucla.edu/labs/sabatti/home/index.html">Chiara Sabatti</a> , <a href="http://statsravingmad.wordpress.com/wp-admin/intercag.org/labs/sabatti/Stat202c/hw1.pdf">pdf</a>]</p>
<p>Take a look @</p>
<p>+ <a href="http://en.wikipedia.org/wiki/Buffon%27s_needle">Wiki</a></p>
<p>+ <a href="http://books.google.com.au/books?id=FV6XncZgfcwC&amp;q=buffon#v=snippet&amp;q=buffon&amp;f=false">An introduction to geometrical probability:  distributional aspects with applications</a> (A. M. Mathai)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/statsravingmad.wordpress.com/1046/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/statsravingmad.wordpress.com/1046/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/statsravingmad.wordpress.com/1046/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/statsravingmad.wordpress.com/1046/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/statsravingmad.wordpress.com/1046/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/statsravingmad.wordpress.com/1046/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/statsravingmad.wordpress.com/1046/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/statsravingmad.wordpress.com/1046/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/statsravingmad.wordpress.com/1046/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/statsravingmad.wordpress.com/1046/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/statsravingmad.wordpress.com/1046/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/statsravingmad.wordpress.com/1046/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/statsravingmad.wordpress.com/1046/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/statsravingmad.wordpress.com/1046/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1046&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://statsravingmad.wordpress.com/2010/03/14/pi-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a327e204e4d170e1949ef27309a13cf5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">soundsofmine</media:title>
		</media:content>

		<media:content url="http://statsravingmad.files.wordpress.com/2010/03/pi-est1.jpeg?w=300" medium="image">
			<media:title type="html">pi.est</media:title>
		</media:content>
	</item>
		<item>
		<title>A normal philosophy&#8230;</title>
		<link>http://statsravingmad.wordpress.com/2010/03/11/a-normal-philosophy/</link>
		<comments>http://statsravingmad.wordpress.com/2010/03/11/a-normal-philosophy/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 20:53:33 +0000</pubDate>
		<dc:creator>Manos Parzakonis</dc:creator>
				<category><![CDATA[infos]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[normal]]></category>
		<category><![CDATA[youden]]></category>

		<guid isPermaLink="false">http://statsravingmad.wordpress.com/?p=1013</guid>
		<description><![CDATA[The following was sent by email to me. It originates to Youden. THE NORMAL LAW OF ERROR STANDS OUT IN THE EXPERIENCE OF MANKIND AS ONE OF THE BROADEST GENERALIZATIONS OF NATURAL PHILOSOPHY . IT SERVES AS THE GUIDING INSTRUMENT IN RESEARCHES IN THE PHYSICAL AND SOCIAL SCIENCES AND IN MEDICINE AGRICULTURE AND ENGINEERING . [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1013&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The following was sent by email to me. It originates to <a href="http://www-gap.dcs.st-and.ac.uk/~history/Biographies/Youden.html">Youden</a>.</p>
<pre>                                 THE
                                NORMAL
                             LAW OF ERROR
                           STANDS OUT IN THE
                         EXPERIENCE OF MANKIND
                        AS ONE OF  THE BROADEST
                       GENERALIZATIONS OF NATURAL
                     PHILOSOPHY . IT SERVES AS THE
                   GUIDING INSTRUMENT IN RESEARCHES
                IN THE PHYSICAL AND SOCIAL SCIENCES AND
               IN MEDICINE AGRICULTURE AND ENGINEERING .
          IT IS AN INDISPENSABLE TOOL FOR THE ANALYSIS AND THE
INTERPRETATION OF THE BASIC DATA OBTAINED BY OBSERVATION AND EXPERIMENT</pre>
<p><em>&#8211;W.J. Youden</em></p>
<p>Youden is one of the truly inspiring statisticians to me.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/statsravingmad.wordpress.com/1013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/statsravingmad.wordpress.com/1013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/statsravingmad.wordpress.com/1013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/statsravingmad.wordpress.com/1013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/statsravingmad.wordpress.com/1013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/statsravingmad.wordpress.com/1013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/statsravingmad.wordpress.com/1013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/statsravingmad.wordpress.com/1013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/statsravingmad.wordpress.com/1013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/statsravingmad.wordpress.com/1013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/statsravingmad.wordpress.com/1013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/statsravingmad.wordpress.com/1013/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/statsravingmad.wordpress.com/1013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/statsravingmad.wordpress.com/1013/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=statsravingmad.wordpress.com&amp;blog=10224980&amp;post=1013&amp;subd=statsravingmad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://statsravingmad.wordpress.com/2010/03/11/a-normal-philosophy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a327e204e4d170e1949ef27309a13cf5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">soundsofmine</media:title>
		</media:content>
	</item>
	</channel>
</rss>
