<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Rrasch]]></title>
  <link href="http://empty-moon-9726.heroku.com//atom.xml" rel="self"/>
  <link href="http://empty-moon-9726.heroku.com//"/>
  <updated>2012-03-03T13:33:15+00:00</updated>
  <id>http://empty-moon-9726.heroku.com//</id>
  <author>
    <name><![CDATA[Chris Wheadon]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[R jags rjags on an ec2 instance]]></title>
    <link href="http://empty-moon-9726.heroku.com//blog/2012/02/11/r-jags-rjags-on-an-ec2-instance/"/>
    <updated>2012-02-11T11:31:00+00:00</updated>
    <id>http://empty-moon-9726.heroku.com//blog/2012/02/11/r-jags-rjags-on-an-ec2-instance</id>
    <content type="html"><![CDATA[<p>Winbugs and Jags free Item Response Theory from the dot matrix plots of proprietary software and open up a multicoloured world of posterior predictive model checking. Fitting IRT models using brute force is not for the impatient, however. That&#8217;s why, just as early psychometricians shipped off their calculations to teams of monks. I&#8217;ve shipped off my model fitting to the West Coast of Ireland (seems apt considering the number of monasteries there) so that I can use my computer to do more important things. Like write about why I&#8217;ve shipped off my model fitting to the West Coast of Ireland.</p>

<p>Thanks to Michael Rutter (and the ever-vigilant Dirk Eddelbuettel for the prompt) getting jags and r up and ready on a 64-bit server is as simple as:</p>

<figure class='code'><figcaption><span>CloudR - cloudr.sh </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='sh'><span class='line'>sudo add-apt-repository ppa:marutter/rrutter
</span><span class='line'>sudo apt-get update
</span><span class='line'>sudo apt-get install r-base-dev jags r-cran-rjags
</span></code></pre></td></tr></table></div></figure>




<h2>Is running your model in the cloud worth a few bob?</h2>


<p>If you want to run JAGS in the cloud it&#8217;ll probably cost you a few bob. That&#8217;s because on the EC2 micro instances JAGS models tend to trigger the CPU limit and grind to a halt. If you want to run odd jobs then I&#8217;d suggest setting up JAGS on an official Ubuntu EC2 Large image, shutting it down, saving the image, then running it at a spot price. That means for a you&#8217;ll be paying about $0.144 per hour when it is running. If you want an image that is always running I&#8217;d suggest you check out monthly hosting rates with other cloud services which can be cheaper than EC2.</p>

<h2>Which ubuntu image should you use?</h2>


<p>I should check out which ones are supported by Michael Rutter.</p>

<h2>What is EC2?</h2>


<p>If none of this means anything to you I&#8217;d recommend playing about with EC2 micro instances and ensuring you can get into and out of them using SSH. As my main computer is Windows based I use putty and FileZilla. FileZilla allows you to configure a default text editor so it is fine for writing most programming languages.</p>

<p><A href="https://help.ubuntu.com/community/EC2StartersGuide">A useful guide on setting yourself up on EC2 with ubuntu</A><BR>
<A href="https://help.ubuntu.com/10.10/serverguide/C/ftp-server.html">Setting up ftp on ubuntu</A></p>

<h2>Only pay for what you use</h2>


<p>Don&#8217;t forget to stop the instance and save the image on AWS. Then, when you are ready to run your job you can request a spot instance and pay for only the time it takes to run your job.</p>

<h2>Keep your job running while you are away</h2>


<p>If you are SSHing into your instance don&#8217;t forget to set your analysis going using the <A href="http://ss64.com/bash/nohup.html">nohup</A> command, otherwise your analysis will be terminated as soon as you log out.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Ten reasons to love the cloud]]></title>
    <link href="http://empty-moon-9726.heroku.com//blog/2012/01/21/10-reasons-to-love-the-cloud/"/>
    <updated>2012-01-21T18:31:00+00:00</updated>
    <id>http://empty-moon-9726.heroku.com//blog/2012/01/21/10-reasons-to-love-the-cloud</id>
    <content type="html"><![CDATA[<p>Ten reasons to love the cloud:</p>

<ol>
<li>The names on Heroku. empty-moon-9726. Suddenly the cloud seems prosaic when you can have the moon.</li>
<li>Being reunited with putty. It&#8217;s like catching up with an old friend. At first the conversation is a little stilted, but then you soon remember just how well you got on and what brought you together in the first place. Things will never be the same between you and the command prompt ever again.</li>
<li>Never having to talk to anyone in systems admin ever again.</li>
<li>Having one instance for one programming language. Let&#8217;s face it, Ruby and Python don&#8217;t really get on so keep them on different boxes, in different continents.</li>
<li>Running 64-bit R from your phone. Just because you can.</li>
<li>Being able to say &#8216;I&#8217;ve just set the analysis going on my cluster in Rio de Janeiro&#8217;</li>
<li>Never having to talk to anyone in systems. oh, did I say that?</li>
<li>Telling your boss that 4 virtual cores with 2 EC2 Compute Units should do it. It&#8217;s just so Star Trek. Throw in a few Tachions and we&#8217;ll hit warp speed.</li>
<li>Never ever writing a line of PHP again.</li>
<li>sudo apt-get install r-base-dev</li>
</ol>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[R in the cloud]]></title>
    <link href="http://empty-moon-9726.heroku.com//blog/2012/01/19/r-in-the-cloud/"/>
    <updated>2012-01-19T10:03:00+00:00</updated>
    <id>http://empty-moon-9726.heroku.com//blog/2012/01/19/r-in-the-cloud</id>
    <content type="html"><![CDATA[<p>Psychometrics, Qu&#8217;est-ce que c&#8217;est?</p>

<p>Say psychometrics to people and they think IQ tests. Fair enough.</p>

<p>I think <A href="http://cran.r-project.org/web/packages/eRm/eRm.pdf">eRm</A>:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>
</span><span class='line'># Rasch model with beta.1 restricted to 0
</span><span class='line'>data(raschdat1)
</span><span class='line'>res &lt;- RM(raschdat1, sum0 = FALSE)
</span><span class='line'>print(res)
</span><span class='line'>summary(res)
</span><span class='line'>res$W
</span></code></pre></td></tr></table></div></figure>


<p>The joy of fitting your first Rasch model in R is unparallelled. Go on try, it. Hmmm, a list of numbers. No idea what they mean?</p>

<p>ok. so you take an IQ test. How do we know how clever you are? We&#8217;ve fitted a model to the test, and the model tells us. Ah, but what interests
a psychometrician is the residuals. What the model doesn&#8217;t tell us. You may not fit our model. Interesting. Perhaps we need different questions for you, or perhaps we need a different model (sorry <A href="http://www.rasch.org/">Benjamin D. Wright</A>). In the old days that would mean expensive software where you spend days figuring out that 0 is not allowed as a valid response. Really? Who writes <A href="http://www.ssicentral.com/">this</A> software!</p>

<p>Ah, R has an answer. And I love R. I mean really love R. <A href="http://cran.r-project.org/web/packages/ltm/ltm.pdf">ltm</A>. Eat your heart out with generalised models. Only now the misfit is getting quite obscure. I no longer know if you fit my model or the items fit my model or if nothing fits at all because there is a distribution of a statistic that Sitjsma has told me has certain properties, but I have no way of following his proof.</p>

<p>And so to Bayes, to JAGS, to WinBUGS, RJags, R2WinBUGS and models that have an elegance that was dreamt of but unrealised before Gibbs sampling. Models galore: <A href="http://www.jstatsoft.org/v36/c01/paper">S. Mackay Curtis</A> and the testlet model. Now my items can live within testlets!</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>model {
</span><span class='line'> for (i in 1:n){
</span><span class='line'> for (j in 1:p){
</span><span class='line'> Y[i , j] ~ dbern ( prob [i , j])
</span><span class='line'> logit ( prob [i , j]) &lt;- alpha [j] * ( theta [i] - delta [j ] + gamma [i,d[j]])
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>theta [i] ~ dnorm (0.0 , 1.0)
</span><span class='line'>
</span><span class='line'>for (k in 1:n.t){
</span><span class='line'> gamma [i , k] ~ dnorm (0.0 , pr. gamma [k])
</span><span class='line'>}
</span><span class='line'> gamma [i , n.t + 1] &lt;- 0.0
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>for (j in 1:p){
</span><span class='line'> alpha [j] ~ dnorm (m.alpha , pr. alpha ) I (0.0 , )
</span><span class='line'> delta [j] ~ dnorm (m.delta , pr. delta )
</span><span class='line'>}
</span><span class='line'> pr. alpha &lt;- pow(s.alpha , -2)
</span><span class='line'> pr. delta &lt;- pow(s.delta , -2)
</span><span class='line'>
</span><span class='line'>for (k in 1:n.t){
</span><span class='line'> pr. gamma [k] ~ dgamma (a. sigsq .gamma , b. sigsq . gamma )
</span><span class='line'> sigsq . gamma [k] &lt;- 1.0 /pr. gamma [k]
</span><span class='line'> }
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>


<p></p>

<p>So you fit your model. And you load up your data. And you iterate. And iterate. And iterate. Minutes turn to hours turn to days. And if you are on Windows you have rebooted six times to install security updates. There must be a better way. Enter stage left Django, Python rpy2 and the cloud.</p>

<p>Follow me into the cloud.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Rooks in the cloud]]></title>
    <link href="http://empty-moon-9726.heroku.com//blog/2012/01/19/rooks-in-the-cloud/"/>
    <updated>2012-01-19T09:32:00+00:00</updated>
    <id>http://empty-moon-9726.heroku.com//blog/2012/01/19/rooks-in-the-cloud</id>
    <content type="html"><![CDATA[<p>Ever since R was born (evoked?) geeks have been trying to get it to talk HTML. A list of web interfaces for R is updated on CRAN <A href="http://cran.r-project.org/doc/FAQ/R-FAQ.html#R-Web-Interfaces">here</A>. Aims are various. Some seek to replace R with a traditional GUI. Others are more ambitious and open up a glimpse of an architecture that provides live analysis of ever changing data.</p>

<p>Perhaps the most exciting of the architectures is <A href="http://jeffreyhorner.tumblr.com/post/4723187316/introducing-rook">Rook</A> a R web service that takes advantage of the built in web server in R.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>function(env){
</span><span class='line'>  body = paste("&lt;h1&gt;Hello World! This is Rook",env$rook.version,".&lt;/h1&gt;")
</span><span class='line'>  list(
</span><span class='line'>  status = 200L,
</span><span class='line'>  headers = list(
</span><span class='line'>  "Content-Type" = "text/html"
</span><span class='line'>  ),
</span><span class='line'>  body = body
</span><span class='line'>  )
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>setRefClass(
</span><span class='line'>  "HelloWorld",
</span><span class='line'>  methods = list(
</span><span class='line'>  call = function(env){
</span><span class='line'>  list(
</span><span class='line'>    status = 200L,
</span><span class='line'>    headers = list(
</span><span class='line'>    "Content-Type" = "text/html"
</span><span class='line'>    ),
</span><span class='line'>    body = paste("&lt;h1&gt;Hello World! This is Rook",env$rook.version,".&lt;/h1&gt;")
</span><span class='line'>    )
</span><span class='line'>  }
</span><span class='line'>  )
</span><span class='line'>)</span></code></pre></td></tr></table></div></figure>


<p>Cool!</p>

<p>While I love R, however, there are some things that I&#8217;m really not sure it should be doing everything. Making toast and being a web server two of them. The joy of django and Ruby is that they do stuff for you like look after cross site validation forgery requests. I&#8217;m a whizz with R, but I wouldn&#8217;t know where to start with those ones.</p>

<p>Anyhow, if the architecture exists where are the applications?</p>

<p>Over at Cambridge we have the brilliant <A href="http://www.psychometrics.cam.ac.uk/news.41.htm">Concerto</A> which makes writing an adaptive test using <A href="http://cran.r-project.org/web/packages/catR/index.html">catR</A> a breeze. It really is worth a go. They will even host a demo account for you.</p>

<p>Elsewhere Jeroen Ooms cuts a lonely figure in R web services. Linear models and ggplots in web interfaces. Check them out <A  href="http://www.stat.ucla.edu/~jeroen/">here</A> and how he did it <A href="http://www.stat.ucla.edu/~jeroen/files/barug2010.pdf">here</A>.</p>

<p>But where are the applications reaching critical mass? Where is the Ruby, django R integration work going on?</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[GIBBS us a break]]></title>
    <link href="http://empty-moon-9726.heroku.com//blog/2012/01/19/gibbs-in-the-cloud/"/>
    <updated>2012-01-19T09:30:00+00:00</updated>
    <id>http://empty-moon-9726.heroku.com//blog/2012/01/19/gibbs-in-the-cloud</id>
    <content type="html"><![CDATA[<p>So you want to run R in the cloud so you can set your Gibbs sampling off, forget about it, and not be paranoid about power cuts and reboots. Andrew Gelman hosted a good debate on the pros and cons of R in the cloud on his <A href="http://andrewgelman.com/2011/07/r_on_the_cloud/">blog</A>.</p>

<p>The consensus seems to be <A href="http://rstudio.org/">RStudio and EC2</A>. P.S. If you haven&#8217;t got Andrew&#8217;s book <A href="http://www.stat.columbia.edu/~gelman/arm/">Data Analysis Using Regression and Multilevel/Hierarchical Models (2007)</A> go and steal one. Seriously. Anyway, here is a lovely intro on how how to go down the <A href="http://toreopsahl.com/2011/10/17/securely-using-r-and-rstudio-on-amazons-ec2/">R EC2 route</A></p>

<p>There you have it. If you want to run R on a 64-bit server with googles of power, that is your answer. So long as you know your cat from your whoami and you don&#8217;t want to use JAGS or BUGS. Really? ok, so it wouldn&#8217;t be too hard to get JAGS talking to RStudio, but is there more to web services R than this?</p>
]]></content>
  </entry>
  
</feed>
