<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Lab Notebook</title>
 <link href="/atom.xml" rel="self"/>
 <link href=""/>
 <updated>2013-05-21T17:19:02-07:00</updated>
 <id>http://www.carlboettiger.info</id>
 <author>
   <name>Carl Boettiger</name>
 </author>
 <rights>CC0</rights>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/05/20/notes.html"/>
   <updated>2013-05-20T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/05/20/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;ews-te-revisions&quot;&gt;EWS TE revisions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Finalized manuscript(?) Checking references, reply letter, closing remaining &lt;a href=&quot;https://github.com/cboettig/ews-review/issues&quot;&gt;issues&lt;/a&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Very annoying to submit to a journal system that takes LaTeX but not any external style or class file dependencies. For instance, how does one add two footnotes to the same author without adding any such dependencies (oh, and writing macros that do not involve pairs of &lt;code&gt;$&lt;/code&gt; which pandoc mistakes for its own macros…) Reasonable author affiliations done otherwise using &lt;code&gt;\and&lt;/code&gt;, &lt;code&gt;\thanks&lt;/code&gt;, and &lt;code&gt;\footnotemark&lt;/code&gt;; see &lt;a href=&quot;&quot;&gt;simple.latex&lt;/a&gt; pandoc template.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Final edits from Alan.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;prosecutor-comment-revisions&quot;&gt;prosecutor comment revisions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;added Figure for Allee model into reply document.&lt;/li&gt;
&lt;li&gt;added code for generating figures &lt;a href=&quot;https://raw.github.com/cboettig/earlywarning/68f7bba05586d425f1bbfcdb1fe66f0597a3d35b/inst/doc/Figure1.Rmd&quot;&gt;Figure1.Rmd&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;combined all four data files into a single tidy data.frame as &lt;a href=&quot;https://raw.github.com/cboettig/earlywarning/68f7bba05586d425f1bbfcdb1fe66f0597a3d35b/inst/doc/Figure1.csv&quot;&gt;csv&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;ropensci&quot;&gt;ropensci&lt;/h2&gt;
&lt;p&gt;Example API queries using Whitehouse Open Data &lt;a href=&quot;https://github.com/project-open-data/csv-to-api&quot;&gt;CSV-API&lt;/a&gt; tool.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://ropensci.org/csv-to-api/index.php?source=https://explore.data.gov/download/7tag-iwnu/CSV&amp;amp;source_format=csv&amp;amp;format=html&quot;&gt;CSV file&lt;/a&gt; (as displayed from the API)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://ropensci.org/csv-to-api/index.php?source=https://explore.data.gov/download/7tag-iwnu/CSV&amp;amp;source_format=csv&amp;amp;format=xml&amp;amp;Magnitude=1.6&quot;&gt;XML query&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://ropensci.org/csv-to-api/index.php?source=https://explore.data.gov/download/7tag-iwnu/CSV&amp;amp;source_format=csv&amp;amp;format=json&amp;amp;callback=parse_results&quot;&gt;JSON query&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;rfishbase-queries&quot;&gt;rfishbase queries&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Continue to get questions about performing queries on fishbase that are just not possible with their current awful data model. This time: how can one extract the 400 natural mortality rate estimates mentioned on &lt;a href=&quot;http://www.fishbase.org/manual/fishbasenatural_mortality00002689.htm&quot;&gt;this page&lt;/a&gt;. No, the page entitled &lt;a href=&quot;http://www.fishbase.org/manual/fishbasethe_popgrowth_table.htm&quot;&gt;popgrowth&lt;/a&gt; doesn’t actually show you the table.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;pdg-control-policycosts&quot;&gt;pdg-control: policycosts&lt;/h3&gt;
&lt;p&gt;Over the weekend, re-ran the policy costs analysis with the simpler apples-to-apples comparison (after stream-lining the code a bit more). General patterns remain the same. Also added a block for showing how well we are doing on our grid sampling at getting to a shared npv0 level.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Comparison when adjustment costs reduce net present value by 50% &lt;a href=&quot;https://github.com/cboettig/pdg_control/blob/582cc266eeda686ac42c9e1e652cc809b2f861f0/inst/examples/policycosts/writeup.md&quot;&gt;pdg_control/582cc26&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;The original 25% reduction (e.g. to 75% of the NPV) &lt;a href=&quot;https://github.com/cboettig/pdg_control/blob/59dca5fc085b93c4f9f833562267b6bdc5a10a55/inst/examples/policycosts/writeup.md&quot;&gt;pdg_control/59dca5f&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;misc&quot;&gt;Misc&lt;/h2&gt;
&lt;h3 id=&quot;notebook&quot;&gt;Notebook&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;obfuscated email via &lt;a href=&quot;https://github.com/cboettig/labnotebook/blob/36b4cd8bdf2f9c943619631dc17e867c0c951d38/assets/js/obfuscate-email.js&quot;&gt;javascript&lt;/a&gt;, copy-paste and mailto: should still work. (Of course a scraper could use the very javascript code to access the email addresses, but I find this preferable to a solution that intenionally burdens the user). Spam filters should handle the rest.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Interesting reading about &lt;a href=&quot;http://mikegerwitz.com/docs/git-horror-story.html&quot;&gt;signing individual Git commits&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Null Distribution Width Minor Puzzle</title>
   <link href="/2013/05/17/null-distribution-width-minor-puzzle.html"/>
   <updated>2013-05-17T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/05/17/null-distribution-width-minor-puzzle</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;A quick foray into trying to understand why I see the wider distribution (though still symmetric) in the null of the OU model then in the null from the Allee model in the Prosecutor’s fallacy.&lt;/p&gt;
&lt;p&gt;Load the original run of the &lt;a href=&quot;https://github.com/cboettig/earlywarning/blob/712b63d2719839b6bbf4188d9affb34d7cec68ce/inst/examples/beer.md&quot;&gt;ou model&lt;/a&gt; and increase the &lt;code&gt;nulldt&lt;/code&gt; data frame to use all points instead of a sample of length 5000&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;load&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;beer_run.rda&amp;quot;&lt;/span&gt;)

ou_dat &amp;lt;- dat
ou_null &amp;lt;- nulldat
&lt;span class=&quot;co&quot;&gt;#ou_null_ts &amp;lt;- nulldt&lt;/span&gt;

null &amp;lt;- timeseries &lt;span class=&quot;co&quot;&gt;#[1000:6010,]&lt;/span&gt;
null &amp;lt;- &lt;span class=&quot;kw&quot;&gt;as.data.frame&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;cbind&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;kw&quot;&gt;dim&lt;/span&gt;(null)[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], null))
ndf &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(null, &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;time&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(ndf) = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;time&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;reps&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;value&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;levels&lt;/span&gt;(ndf$reps) &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;levels&lt;/span&gt;(ndf$reps)) &lt;span class=&quot;co&quot;&gt;# use numbers for reps instead of V1, V2, etc&lt;/span&gt;
nulldt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.table&lt;/span&gt;(ndf)
ou_null_ts &amp;lt;- nulldt&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Plot the final distribution of indicator statistics, showing the width of the null,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dat) + &lt;span class=&quot;kw&quot;&gt;geom_histogram&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value, &lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;..density..), &lt;span class=&quot;dt&quot;&gt;binwidth=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.3&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;.&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;) +
 &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~variable) + &lt;span class=&quot;kw&quot;&gt;xlim&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)) + 
  &lt;span class=&quot;kw&quot;&gt;geom_density&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;nulldat, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value), &lt;span class=&quot;dt&quot;&gt;adjust=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;xlab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;Kendall&amp;#39;s tau&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;theme_bw&lt;/span&gt;()&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8558/8747591959_9944ea987d_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-4&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-4&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Load the &lt;a href=&quot;https://github.com/cboettig/earlywarning/blob/712b63d2719839b6bbf4188d9affb34d7cec68ce/inst/examples/comment.md&quot;&gt;allee model&lt;/a&gt; and rename variables appropriately,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;load&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;comment_run.rda&amp;quot;&lt;/span&gt;)
allee_dat &amp;lt;- dat
allee_null &amp;lt;- nulldat
allee_null_ts &amp;lt;- nulldt&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For the Allee model, also plot the final distribution of indicator statistics, showing the width of the null,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dat) + &lt;span class=&quot;kw&quot;&gt;geom_histogram&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value, &lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;..density..), &lt;span class=&quot;dt&quot;&gt;binwidth=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.3&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;.&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;) +
 &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~variable) + &lt;span class=&quot;kw&quot;&gt;xlim&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)) + 
  &lt;span class=&quot;kw&quot;&gt;geom_density&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;nulldat, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value), &lt;span class=&quot;dt&quot;&gt;adjust=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;xlab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;Kendall&amp;#39;s tau&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;theme_bw&lt;/span&gt;()&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm8.staticflickr.com/7315/8748715116_c9440843f1_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-6&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-6&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Tidy the data and plot a single replicate from each. Note the OU process has the correspondingly much wider null distribution due to&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;allee_x &amp;lt;- &lt;span class=&quot;kw&quot;&gt;subset&lt;/span&gt;(allee_null_ts, reps==&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)
ou_x &amp;lt;- &lt;span class=&quot;kw&quot;&gt;subset&lt;/span&gt;(ou_null_ts, reps==&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)
allee_x &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time =&lt;/span&gt; allee_x$time, &lt;span class=&quot;dt&quot;&gt;value =&lt;/span&gt; allee_x$value)
ou_x &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time =&lt;/span&gt; ou_x$time, &lt;span class=&quot;dt&quot;&gt;value =&lt;/span&gt; ou_x$value)

&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(allee_x, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, value)) + &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;()&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm8.staticflickr.com/7323/8747593003_dfbd94b355_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-7&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-7&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(ou_x, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, value)) + &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;()&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm8.staticflickr.com/7295/8747593115_4320618635_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-7&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-7&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Note that subsampling the data at coarser interval doesn’t matter&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;warningtrend&lt;/span&gt;(ou_x[&lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(ou_x$value),&lt;span class=&quot;dt&quot;&gt;by=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;50&lt;/span&gt;),], window_var)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;    tau 
-0.5527 &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nor does scaling matter (recall Kendall’s &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?tau\inline&quot;/&gt;&lt;/span&gt; is a rank-correlation test)&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;warningtrend&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time=&lt;/span&gt;ou_x$time, &lt;span class=&quot;dt&quot;&gt;value=&lt;/span&gt;(ou_x$value&lt;span class=&quot;dv&quot;&gt;+1&lt;/span&gt;)*&lt;span class=&quot;dv&quot;&gt;500&lt;/span&gt;), window_var)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;    tau 
-0.5516 &lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;warningtrend&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time=&lt;/span&gt;ou_x$time, &lt;span class=&quot;dt&quot;&gt;value=&lt;/span&gt;ou_x$value), window_var)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;    tau 
-0.5516 &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lengthening the sample suggests the sampling is not long enough to have converged in distribution of this statistic. Computing on this fine sampling resolution over adequate length of time quickly becomes prohibitive.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;20000&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;by=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;), function(i) &lt;span class=&quot;kw&quot;&gt;warningtrend&lt;/span&gt;(ou_x[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:i,], window_var))&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;       tau        tau        tau        tau        tau        tau 
 0.1802475 -0.0832527  0.6365570  0.1787726 -0.1747774 -0.5295226 
       tau        tau        tau        tau        tau        tau 
-0.5403782 -0.6790710 -0.6114706 -0.2950858 -0.0444861  0.0006919 
       tau        tau        tau        tau        tau        tau 
-0.2579410 -0.5220490 -0.6439519 -0.6221482 -0.5545048 -0.5134236 
       tau        tau 
-0.5265975 -0.5515807 &lt;/code&gt;&lt;/pre&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/05/16/notes.html"/>
   <updated>2013-05-16T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/05/16/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;prosecutor&quot;&gt;Prosecutor&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Add figures for both examples with and without ASS&lt;/li&gt;
&lt;li&gt;text to accomidate both examples&lt;/li&gt;
&lt;li&gt;ROC curves?&lt;/li&gt;
&lt;li&gt;proof-reading&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;ews-review&quot;&gt;ews-review&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;looking over revisions, touch-ups&lt;/li&gt;
&lt;li&gt;See issues log for details&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;links&quot;&gt;Links&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Impressive set of tools provided by the Whitehouse &lt;a href=&quot;http://project-open-data.github.io/&quot;&gt;open data project&lt;/a&gt; In particular, see the &lt;a href=&quot;https://github.com/project-open-data/csv-to-api&quot;&gt;tool&lt;/a&gt; for generating a RESTful API from CSV files and the “common core” &lt;a href=&quot;http://project-open-data.github.io/metadata-resources/#common_core_required_fields_equivalents&quot;&gt;metadata definitions&lt;/a&gt;. Notebook complies with many of these (throught the Dublin core RDFa), but looks like I could benefit from adding some more terms from the &lt;a href=&quot;http://www.w3.org/TR/vocab-dcat/#property--access-download&quot;&gt;Data Catalog Vocabulary&lt;/a&gt;. Awesome that this site is built with Twitter-Bootstrap and Jekyll, hosted on Github, and licenced as CC-BY (content) and MIT (code). See for example, the &lt;a href=&quot;https://github.com/project-open-data/project-open-data.github.io/issues&quot;&gt;issues log&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;notebook&quot;&gt;Notebook&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;added black-white theme for readers that prefer higher contrast / more traditional appearance. Otherwise matches the orginal feel reasonably well. (&lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/70&quot;&gt;#70&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dropped the local javascript based search using the stemming engine (&lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/7&quot;&gt;#7&lt;/a&gt;). The stemming search was reasonably fast, but only matches words instead of phrases (and adds considerable overhead to generating the site).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;*&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/05/14/notes.html"/>
   <updated>2013-05-14T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/05/14/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Exploring potential plots that would allow for some visualization of the uncertainty in each of the models. Example follows up on analysis of &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/e97043d690b81e1fdd777e7d2f927cdee8fba653/inst/examples/BUGS/allen.md&quot;&gt;e97043d/allen.md&lt;/a&gt;, as also in the script from &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/b5d78b9bca5dbf08828f1882eda1676e29958df3/inst/examples/BUGS/step_ahead_plots.md&quot;&gt;b5d78b9/step_ahead_plots.md&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;one-step-ahead-predictor-plots-and-forecasting-plots&quot;&gt;One-step ahead predictor plots and forecasting plots&lt;/h2&gt;
&lt;p&gt;Set our usual plotting options for the notebook&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;opts_chunk$&lt;span class=&quot;kw&quot;&gt;set&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;tidy =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;warning =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;message =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;cache =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, 
    &lt;span class=&quot;dt&quot;&gt;comment =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;NA&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;fig.width =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;7&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;fig.height =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(ggplot2)
opts_knit$&lt;span class=&quot;kw&quot;&gt;set&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;upload.fun =&lt;/span&gt; socialR::flickr.url)
&lt;span class=&quot;kw&quot;&gt;theme_set&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;theme_bw&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;base_size =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;12&lt;/span&gt;))
&lt;span class=&quot;kw&quot;&gt;theme_update&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;panel.background =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;element_rect&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;fill =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;transparent&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;colour =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;NA&lt;/span&gt;), 
    &lt;span class=&quot;dt&quot;&gt;plot.background =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;element_rect&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;fill =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;transparent&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;colour =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;NA&lt;/span&gt;))
cbPalette &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;#000000&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;#E69F00&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;#56B4E9&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;#009E73&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;#F0E442&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;#0072B2&amp;quot;&lt;/span&gt;, 
    &lt;span class=&quot;st&quot;&gt;&amp;quot;#D55E00&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;#CC79A7&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we show how each of the fitted models performs on the training data (e.g. plot of the step-ahead predictors). For the GP, we need to predict on the training data first:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;gp_f_at_obs &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gp_predict&lt;/span&gt;(gp, x, &lt;span class=&quot;dt&quot;&gt;burnin=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;1e4&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;thin=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;300&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For the parametric models, prediction is a matter of feeding in each of the observed data points to the fitted parameters, like so&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;step_ahead &amp;lt;- function(x, f, p){
  h = &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;
  x_predict &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(x, f, h, p)
  n &amp;lt;- &lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(x_predict) - &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;
  y &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(x[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], x_predict[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:n])
  y
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Which we apply over each of the fitted models, including the GP, organizing the “expected” transition points (given the previous point) into a data frame.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;df &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(x), &lt;span class=&quot;dt&quot;&gt;stock =&lt;/span&gt; x, 
                &lt;span class=&quot;dt&quot;&gt;GP =&lt;/span&gt; gp_f_at_obs$E_Ef,
                &lt;span class=&quot;dt&quot;&gt;True =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;step_ahead&lt;/span&gt;(x,f,p),  
                &lt;span class=&quot;dt&quot;&gt;MLE =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;step_ahead&lt;/span&gt;(x,f,est$p), 
                &lt;span class=&quot;dt&quot;&gt;Parametric.Bayes =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;step_ahead&lt;/span&gt;(x, f, bayes_pars), 
                &lt;span class=&quot;dt&quot;&gt;Ricker =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;step_ahead&lt;/span&gt;(x,alt$f, ricker_bayes_pars), 
                &lt;span class=&quot;dt&quot;&gt;Myers =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;step_ahead&lt;/span&gt;(x, Myer_harvest, myers_bayes_pars)
                 ), &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;time&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;stock&amp;quot;&lt;/span&gt;))

&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(df) + &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, stock)) + 
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, value, &lt;span class=&quot;dt&quot;&gt;col=&lt;/span&gt;variable)) +
    &lt;span class=&quot;kw&quot;&gt;scale_colour_manual&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;values=&lt;/span&gt;colorkey) &lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm8.staticflickr.com/7294/8743766846_a5d6b20f15_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;posterior-predictive-curves&quot;&gt;Posterior predictive curves&lt;/h2&gt;
&lt;p&gt;This shows only the mean predictions. For the Bayesian cases, we can instead loop over the posteriors of the parameters (or samples from the GP posterior) to get the distribution of such curves in each case.&lt;/p&gt;
&lt;p&gt;We will need a vector version (&lt;code&gt;pmin&lt;/code&gt; in place of &lt;code&gt;min&lt;/code&gt;) of this function that can operate on the posteriors, others are vectorized already.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;ricker_f &amp;lt;- function(x,h,p){
  &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(x, function(x){ 
    x &amp;lt;- &lt;span class=&quot;kw&quot;&gt;pmax&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, x-h) 
    &lt;span class=&quot;kw&quot;&gt;pmax&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, x * &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;] * (&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt; - x / p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] )) )
  })
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then we proceed as before, now looping over 100 random samples from the posterior for each Bayesian estimate. We write this as a function for easy reuse.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(MASS)

step_ahead_posteriors &amp;lt;- function(x){
gp_f_at_obs &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gp_predict&lt;/span&gt;(gp, x, &lt;span class=&quot;dt&quot;&gt;burnin=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;1e4&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;thin=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;300&lt;/span&gt;)
df_post &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;sample&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;), 
  function(i){
    &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(x), &lt;span class=&quot;dt&quot;&gt;stock =&lt;/span&gt; x, 
                &lt;span class=&quot;dt&quot;&gt;GP =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;mvrnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, gp_f_at_obs$Ef_posterior[,i], gp_f_at_obs$Cf_posterior[[i]]),
                &lt;span class=&quot;dt&quot;&gt;True =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;step_ahead&lt;/span&gt;(x,f,p),  
                &lt;span class=&quot;dt&quot;&gt;MLE =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;step_ahead&lt;/span&gt;(x,f,est$p), 
                &lt;span class=&quot;dt&quot;&gt;Parametric.Bayes =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;step_ahead&lt;/span&gt;(x, allen_f, pardist[i,]), 
                &lt;span class=&quot;dt&quot;&gt;Ricker =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;step_ahead&lt;/span&gt;(x, ricker_f, ricker_pardist[i,]), 
                &lt;span class=&quot;dt&quot;&gt;Myers =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;step_ahead&lt;/span&gt;(x, myers_f, myers_pardist[i,]))
  }), &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;time&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;stock&amp;quot;&lt;/span&gt;))

}


df_post &amp;lt;- &lt;span class=&quot;kw&quot;&gt;step_ahead_posteriors&lt;/span&gt;(x)
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(df_post) + &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, stock)) + 
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, value, &lt;span class=&quot;dt&quot;&gt;col=&lt;/span&gt;variable, &lt;span class=&quot;dt&quot;&gt;group=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;interaction&lt;/span&gt;(L1,variable)), &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;.&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) + 
  &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~variable) + 
  &lt;span class=&quot;kw&quot;&gt;scale_colour_manual&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;values=&lt;/span&gt;colorkey, &lt;span class=&quot;dt&quot;&gt;guide =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;guide_legend&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;override.aes =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;alpha =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;))) &lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm8.staticflickr.com/7290/8742650211_92d087672b_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;alternately, try the plot without facets&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(df_post) + &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, stock)) + 
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, value, &lt;span class=&quot;dt&quot;&gt;col=&lt;/span&gt;variable, &lt;span class=&quot;dt&quot;&gt;group=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;interaction&lt;/span&gt;(L1,variable)), &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;.&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) + 
  &lt;span class=&quot;kw&quot;&gt;scale_colour_manual&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;values=&lt;/span&gt;colorkey, &lt;span class=&quot;dt&quot;&gt;guide =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;guide_legend&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;override.aes =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;alpha =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;))) &lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm8.staticflickr.com/7284/8743767710_17a0bc6428_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;performance-on-data-outside-of-observations&quot;&gt;Performance on data outside of observations&lt;/h2&gt;
&lt;p&gt;Of course it is hardly suprising that all models do reasonably well on the data on which they were trained. A crux of the problem is the model performance on data outside the observed range. (Though we might also wish to repeat the above plot on data in the observed range but a different sequence from the observed data).&lt;/p&gt;
&lt;p&gt;First we generate some data from the underlying model coming from below the tipping point:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;Tobs &amp;lt;- &lt;span class=&quot;dv&quot;&gt;8&lt;/span&gt;
y &amp;lt;- &lt;span class=&quot;kw&quot;&gt;numeric&lt;/span&gt;(Tobs)
y[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] = &lt;span class=&quot;fl&quot;&gt;4.5&lt;/span&gt;
for(t in &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:(Tobs&lt;span class=&quot;dv&quot;&gt;-1&lt;/span&gt;))
    y[t&lt;span class=&quot;dv&quot;&gt;+1&lt;/span&gt;] = &lt;span class=&quot;kw&quot;&gt;z_g&lt;/span&gt;() * &lt;span class=&quot;kw&quot;&gt;f&lt;/span&gt;(y[t], &lt;span class=&quot;dt&quot;&gt;h=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;p=&lt;/span&gt;p)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Proceed as before on this data:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;crash_data &amp;lt;- &lt;span class=&quot;kw&quot;&gt;step_ahead_posteriors&lt;/span&gt;(y)

&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(crash_data) + &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, stock)) + 
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, value, &lt;span class=&quot;dt&quot;&gt;col=&lt;/span&gt;variable, &lt;span class=&quot;dt&quot;&gt;group=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;interaction&lt;/span&gt;(L1,variable)), &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;.&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) + 
  &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~variable) + 
  &lt;span class=&quot;kw&quot;&gt;scale_colour_manual&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;values=&lt;/span&gt;colorkey, &lt;span class=&quot;dt&quot;&gt;guide =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;guide_legend&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;override.aes =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;alpha =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;))) &lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm8.staticflickr.com/7282/8742650625_efd126ef62_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;Note that the GP is doing remarkably well even outside the observed range, though with greater uncertainty as well. Other models tend to be overly optimistic, often predicting an increase instead of a decline, hence the many trajectories that continually float above the data.&lt;/p&gt;
&lt;h2 id=&quot;forecast-distributions&quot;&gt;Forecast Distributions&lt;/h2&gt;
&lt;p&gt;Another way to visualize this is to look directly at the distribution predicted under each model, one step and several steps into the future (say, at a fixed harvest level). Here we have a simple function that will look one step ahead of the given &lt;code&gt;x&lt;/code&gt; (given as index &lt;code&gt;i&lt;/code&gt;), then &lt;code&gt;Tobs&lt;/code&gt; steps ahead, then &lt;code&gt;2*Tobs&lt;/code&gt; steps ahead, each at a fixed harvest. This lets us compare both the expected outcome over short and long term under a given harvest policy, as well as seeing how the distribution of possible outcomes evolves.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(expm)
get_forecasts &amp;lt;- function(i, Tobs, h_i){

df &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(
  &lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; x_grid,  
  &lt;span class=&quot;dt&quot;&gt;GP =&lt;/span&gt; matrices_gp[[h_i]][i,], 
  &lt;span class=&quot;dt&quot;&gt;True =&lt;/span&gt; matrices_true[[h_i]][i,], 
  &lt;span class=&quot;dt&quot;&gt;MLE =&lt;/span&gt; matrices_estimated[[h_i]][i,], 
  &lt;span class=&quot;dt&quot;&gt;Parametric.Bayes =&lt;/span&gt; matrices_par_bayes[[h_i]][i,], 
  &lt;span class=&quot;dt&quot;&gt;Ricker =&lt;/span&gt; matrices_alt[[h_i]][i,],
  &lt;span class=&quot;dt&quot;&gt;Myers =&lt;/span&gt; matrices_myers[[h_i]][i,])

df2 &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(
  &lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; x_grid,
  &lt;span class=&quot;dt&quot;&gt;GP =&lt;/span&gt; (matrices_gp[[h_i]] %^% Tobs)[i,], 
  &lt;span class=&quot;dt&quot;&gt;True =&lt;/span&gt; (matrices_true[[h_i]] %^% Tobs)[i,], 
  &lt;span class=&quot;dt&quot;&gt;MLE =&lt;/span&gt; (matrices_estimated[[h_i]] %^% Tobs)[i,],
  &lt;span class=&quot;dt&quot;&gt;Parametric.Bayes =&lt;/span&gt; (matrices_par_bayes[[h_i]] %^% Tobs)[i,], 
  &lt;span class=&quot;dt&quot;&gt;Ricker =&lt;/span&gt; (matrices_alt[[h_i]] %^% Tobs)[i,], 
  &lt;span class=&quot;dt&quot;&gt;Myers =&lt;/span&gt; (matrices_myers[[h_i]] %^% Tobs)[i,])

T2 &amp;lt;- &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * Tobs

df4 &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(
  &lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; x_grid,
  &lt;span class=&quot;dt&quot;&gt;GP =&lt;/span&gt; (matrices_gp[[h_i]] %^% T2)[i,], 
  &lt;span class=&quot;dt&quot;&gt;True =&lt;/span&gt; (matrices_true[[h_i]] %^% T2)[i,], 
  &lt;span class=&quot;dt&quot;&gt;MLE =&lt;/span&gt; (matrices_estimated[[h_i]] %^% T2)[i,],
  &lt;span class=&quot;dt&quot;&gt;Parametric.Bayes =&lt;/span&gt; (matrices_par_bayes[[h_i]] %^% T2)[i,], 
  &lt;span class=&quot;dt&quot;&gt;Ricker =&lt;/span&gt; (matrices_alt[[h_i]] %^% T2)[i,], 
  &lt;span class=&quot;dt&quot;&gt;Myers =&lt;/span&gt; (matrices_myers[[h_i]] %^% T2)[i,])

forecasts &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;T_start =&lt;/span&gt; df, &lt;span class=&quot;dt&quot;&gt;T_mid =&lt;/span&gt; df2, &lt;span class=&quot;dt&quot;&gt;T_end =&lt;/span&gt; df4), &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;)

}

i = &lt;span class=&quot;dv&quot;&gt;15&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This takes &lt;code&gt;i&lt;/code&gt;, an index to &lt;code&gt;x_grid&lt;/code&gt; value (e.g. for &lt;code&gt;i&lt;/code&gt;=15 corresponds to a starting postion &lt;code&gt;x&lt;/code&gt; = 3.4286)&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;forecasts &amp;lt;- &lt;span class=&quot;kw&quot;&gt;get_forecasts&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;i =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;15&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;Tobs =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;h_i =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)

&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(forecasts) +
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, value, &lt;span class=&quot;dt&quot;&gt;group=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;interaction&lt;/span&gt;(variable, L1), &lt;span class=&quot;dt&quot;&gt;col=&lt;/span&gt;variable, &lt;span class=&quot;dt&quot;&gt;lty=&lt;/span&gt;L1)) +
  &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~ variable, &lt;span class=&quot;dt&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free_y&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ncol=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;) + 
  &lt;span class=&quot;kw&quot;&gt;scale_colour_manual&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;values=&lt;/span&gt;colorkey) &lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm8.staticflickr.com/7283/8743768066_ae4cb1a63d_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-10&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-10&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;We can compare to a better starting stock,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;i&amp;lt;-&lt;span class=&quot;dv&quot;&gt;30&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;where &lt;code&gt;i&lt;/code&gt;=30 corresponds to a starting postion &lt;code&gt;x&lt;/code&gt; = 7.102&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;forecasts &amp;lt;- &lt;span class=&quot;kw&quot;&gt;get_forecasts&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;i =&lt;/span&gt; i, &lt;span class=&quot;dt&quot;&gt;Tobs =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;h_i =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)

&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(forecasts) +
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, value, &lt;span class=&quot;dt&quot;&gt;group=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;interaction&lt;/span&gt;(variable, L1), &lt;span class=&quot;dt&quot;&gt;col=&lt;/span&gt;variable, &lt;span class=&quot;dt&quot;&gt;lty=&lt;/span&gt;L1)) +
  &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~ variable, &lt;span class=&quot;dt&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free_y&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ncol=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;) + 
  &lt;span class=&quot;kw&quot;&gt;scale_colour_manual&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;values=&lt;/span&gt;colorkey) &lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm8.staticflickr.com/7289/8743768174_106af587ce_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;Note the greater uncertainty in both the positive and negative outcomes under the parametric Bayesian models (of correct and incorrect structure).&lt;/p&gt;
&lt;h2 id=&quot;misc-reading&quot;&gt;Misc reading&lt;/h2&gt;
&lt;p&gt;Apparently I am catching up on my C. Titus Brown reading… Achiving comments for my records &amp;amp; to keep them in my local search index.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://ivory.idyll.org/blog/blog-practicing-open-science.html&quot;&gt;Titus Brown on if he really practices Open Science?&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Methinks:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I think you undersell your Github practices regarding Open Science. While I agree entirely that anyone reading through your source-code to scoop you is incredibly unlikely; I imagine many researchers would still fear the practice of using a public, Google-indexed repository, particularly if they also practice reasonable literate programming documentation, provide test cases, and use issue tracking that could allow some close rival to scoop them.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;It sounds like you are talking more about not marketing your work before it is “finished”, rather not being open. (When you say “to really open up about what we’re doing” I assume you mean advertising the results, rather than something like simply putting your notebook or publication drafts on github). Though “Open Science” is used in in both contexts, marketing your pre-publication science takes additional time that exposing your workflow on Github does not. The latter practice provides transparency, provenance machine-discoverability, (and cool graphs of research contributions like https://github.com/ctb/khmer/c… etc. Perhaps you are too hard on yourself here.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Meanwhile, I think suggesting that being open prematurely would “waste other people’s time, energy, and attention” is misleading and damaging here. Sure, I understand you mean that marketing unfinished results (blog, tweet, present at conferences) would do these things, but when the same reason is frequently given for not sharing data, code, etc this becomes very damaging. Some people may find it useful to blog/tweet/present unfinished work (with appropriate disclaimer) to get feedback, build audience, or for all the same reasons one would do so with published work, but to me that is really just a question of timing &amp;amp; marketing, not a question of “openness”.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;a href=&quot;http://ivory.idyll.org/blog/research-software-reuse.html&quot;&gt;On Research Software Reuse&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://ivory.idyll.org/blog/the-cost-of-open-science.html&quot;&gt;On the Costs of Open Science&lt;/a&gt;, which I refute:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Great post and important question. I certainly agree that it is all about incentives, but I think an important missing part of that discussion is in the timescales. Certainly there is a cost to not writing up the low-lying fruit following up on your work, but surely such exercises would take non-trivial time away from doing whatever (presumably more interesting) stuff you did instead. Perhaps the it is the benefits, not the costs, that are hidden:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;It sounds like you may have forgone a short-term cost in not publishing these easy follow-ups while gaining a benefit both of time to work on other interesting things and of getting other researchers invested in your work, who might not have taken it up at all if there was no low-hanging fruit to entice them in. Once invested in it, no doubt they can continue to be a multiplier of impact. Meanwhile you break new ground rather than appearing to continue to wring every ounce from one good idea, right? (If I read this correctly, both you and George Gey appear to regard these other publications as not particularly exciting work; the regret comes only because they are intrinsically valued publications)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;It sounds like the difficulty with these benefits is that they pay off only on a longer timescale than the gristmill publication strategy. On the longest timescales, e.g. career lifetime, it seems clear that at least in a statistical sense, researchers who keep breaking new ground while allowing others to pick the low-hanging follow-up work will be much more likely to end up as the most distinguished researchers, etc. When the relevant timescale is a tenure clock rather than a career, the perhaps the calculus is different?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Without open science, moving on to other exciting stuff is far less effective, since it leaves both unfinished work and less impact. Perhaps this a somewhat idealized view, and perhaps the timescales for tenure etc work against this strategy. You and others could no doubt better speak to whether the candidate who says “look at all the papers I wrote about X” or the one who says “look at all the papers others have built upon my method X while I break ground in hard problem Y” has the stronger case.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://gist.github.com/hadley/5576263&quot;&gt;Partial implementation of R to Latex equation converter&lt;/a&gt; from @hadleywickam.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ah ha! &lt;a href=&quot;http://stackoverflow.com/questions/14041601/documenting-equations-with-deqn-and-roxygen&quot;&gt;Documenting equations in ROxygen&lt;/a&gt;. Guess one day I (or devtools) will move to Roxygen3.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/05/13/notes.html"/>
   <updated>2013-05-13T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/05/13/notes</id>
   
   <content type="html">&lt;h3 id=&quot;prosecutors-fallacy-comment&quot;&gt;Prosecutor’s Fallacy comment&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Fallacy comment revisions&lt;/li&gt;
&lt;li&gt;Comment reply letter (draft)&lt;/li&gt;
&lt;li&gt;ROC curves instead? (&lt;a href=&quot;https://github.com/cboettig/earlywarning/blob/abcc1cd727f2a45ee7cbb2220135a6ebfc3e4277/inst/doc/roc_curves.md&quot;&gt;examples&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Add example of system with an alternative stable state?&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;policy-costs-pdg-control&quot;&gt;Policy costs (pdg-control)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;touched up &lt;a href=&quot;https://github.com/cboettig/pdg_control/blob/master/inst/doc/policycosts/policycosts_PRA.tex&quot;&gt;tex document&lt;/a&gt; following Paul’s edits (mostly reflects comments and decisions from Meeting 3). Reminder of why collaborating on TeX documents can be annoying even when co-authors are tex-literate. Attempted quick conversion to markdown but mapping is troublesome.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;misc&quot;&gt;Misc&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Some &lt;a href=&quot;https://github.com/coolwanglu/pdf2htmlEX&quot;&gt;software&lt;/a&gt; providing rather impressive/high fidelity pdf to html conversion… Not just rendering as images – the text is searchable, though in the html source it just looks like a bunch of binary data URIs.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Scathingly honest review of the classical ecological statistics text by Sokal and Rohlf (&lt;a href=&quot;http://t.co/5IioNf1p1y&quot;&gt;pdf&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.steinsaltz.me.uk/pnas.html&quot;&gt;PNAS hates mathematics&lt;/a&gt; Not really, but a depressing example of poor reviewing.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Prep for ERE talk</title>
   <link href="/2013/05/09/notes.html"/>
   <updated>2013-05-09T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/05/09/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;talk-prep&quot;&gt;Talk prep&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Finished preparing slides for Environmental Resources Economics talk&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Toying around with animations for final plots. Building up plot by subsetting progressively more of the data each time is a bit of a nuciance (both in coding and efficiency). Can convert replicates to characters and assign as a data.table &lt;code&gt;key&lt;/code&gt; for fast join subsetting, but straight-forward subsetting seems best (e.g. once we want reps 1:5 from both “True” and “Ricker” models, &lt;code&gt;dt[J(c(&amp;quot;True&amp;quot;, &amp;quot;Ricker&amp;quot;), as.character(1:5)]&lt;/code&gt; doesn’t quite do this. (Can you guess what it gives? Actually alternates “True”+rep1, “Ricker”+rep2, “True”+rep3, …)&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(animation)
&lt;span class=&quot;kw&quot;&gt;ani.options&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;loop=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;saveMovie&lt;/span&gt;({    
    for (i in &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, OptTime, &lt;span class=&quot;dt&quot;&gt;by=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)) {
      &lt;span class=&quot;kw&quot;&gt;print&lt;/span&gt;(
        &lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;subset&lt;/span&gt;(dt, method %in% &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;True&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;Ricker&amp;quot;&lt;/span&gt;) &amp;amp; reps &amp;lt; &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt; &amp;amp; time &amp;lt;= i), 
               &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, fishstock, &lt;span class=&quot;dt&quot;&gt;group=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;interaction&lt;/span&gt;(reps,method), &lt;span class=&quot;dt&quot;&gt;color =&lt;/span&gt; method), &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;.&lt;span class=&quot;dv&quot;&gt;9&lt;/span&gt;) + 
          &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;() + &lt;span class=&quot;kw&quot;&gt;xlim&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, OptTime)
        )
    }
}, &lt;span class=&quot;dt&quot;&gt;interval =&lt;/span&gt; &lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;movie.name =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;wrong-model.gif&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ani.width =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;600&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ani.height =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;600&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Added plots of one-step-ahead predictors, e.g.&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm8.staticflickr.com/7317/8736417226_03129480a9_c.jpg&quot; alt=&quot;One-step ahead predictions on orginal (training) data by each model&quot; /&gt;&lt;figcaption&gt;One-step ahead predictions on orginal (training) data by each model&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;All plots for slides also archived in &lt;a href=&quot;http://www.flickr.com/photos/cboettig/tags/ere2013&quot;&gt;flickr/ere2013&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Which were quickly converted from vector pdfs into decent resolution pngs with a few commands:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;sourceCode bash&quot;&gt;&lt;code class=&quot;sourceCode bash&quot;&gt;&lt;span class=&quot;kw&quot;&gt;for&lt;/span&gt; f &lt;span class=&quot;kw&quot;&gt;in&lt;/span&gt; *.pdf ; &lt;span class=&quot;kw&quot;&gt;do&lt;/span&gt; convert -density 300 &lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;$f&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;${f/&lt;/span&gt;.pdf&lt;span class=&quot;ot&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt;.png ; &lt;span class=&quot;kw&quot;&gt;done&lt;/span&gt;
flickr_upload --tag=&lt;span class=&quot;st&quot;&gt;&amp;quot;nonparametric-bayes ere2013 talk&amp;quot;&lt;/span&gt; *.png&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;(&lt;span class=&quot;showtooltip&quot; title=&quot;Sirota J, Baiser B, Gotelli N and Ellison A (2013). 'Organic-Matter Loading Determines Regime Shifts And Alternative States in an Aquatic Ecosystem.' Proceedings of The National Academy of Sciences, 110, pp. 7742-7747. ISSN 0027-8424.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1221037110&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Sirota et al. 2013&lt;/a&gt;&lt;/span&gt; ) provide a cute example of a system that can be manipulated through a tipping point of eutrophication in the tiny pools forming inside pitcher plants by adding ground-up dead insects. A nice natural system that provides a more realistic setting than lab manipulations of single species micro-organisms while also being more accessible to replication that the whole-lake experiments in Wisconsin. I do note they critique retrospective analyses on the basis of length, but don’t mention the prosecutor’s fallacy. Five stars for archiving the raw data very nicely (see below) along with the mathematica notebook file used for the analysis. Also notable that the first author is an undergrad at North Dakota State.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Wow, Harvard Forest provides a data repository with EML files for each data entry (&lt;a href=&quot;http://t.co/G2sgd2n5L9&quot;&gt;example&lt;/a&gt;). EML file serves more as a metadata description, raw data provided as an 8.8 MB .csv file in tidy (long) format. Very nice.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;From the Whitehouse, executive order: &lt;a href=&quot;http://t.co/4mtDCuNoIG&quot;&gt;The default state of new and modernized Government information resources shall be open and machine readable&lt;/a&gt; I can’t really express just how incredible that is. May it impact government funded science appropriately. Whitehouse Chief technology officer and chief information officer explain the policy in &lt;a href=&quot;http://www.youtube.com/watch?v=n603rEnEGXA&quot;&gt;one minute&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;J. Sirota, B. Baiser, N. J. Gotelli, A. M. Ellison, (2013) Organic-Matter Loading Determines Regime Shifts And Alternative States in an Aquatic Ecosystem. &lt;em&gt;Proceedings of The National Academy of Sciences&lt;/em&gt; &lt;strong&gt;110&lt;/strong&gt; 7742-7747 &lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1221037110&quot;&gt;10.1073/pnas.1221037110&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/05/07/notes.html"/>
   <updated>2013-05-07T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/05/07/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;monday&quot;&gt;Monday&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;MacKenzie meeting&lt;/li&gt;
&lt;li&gt;paperwork to Marc&lt;/li&gt;
&lt;li&gt;paperwork to Karthik&lt;/li&gt;
&lt;li&gt;Writing&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;tuesday&quot;&gt;Tuesday&lt;/h2&gt;
&lt;h3 id=&quot;log&quot;&gt;Log&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Weak thresholds example – no cost but no profit if stocks are reduced below a certain threshold &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/6bdc9535f0def3c5f2ed168bfac9c86517d48466&quot;&gt;09:31 pm 2013/05/07&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;example using short (20 pts) observation period &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/ac225715a20a0628d84d33d240bced834228424c&quot;&gt;02:00 pm 2013/05/07&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;subset plotting of simulations (for slides potentially) &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/04ddf0d5022ed66d214d58232224dc618f7fa898&quot;&gt;02:00 pm 2013/05/07&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;script for the parallel analysis based on policy thresholds &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/ca0219bd833cae278aa855fc42c1c07b6aaf850f&quot;&gt;01:59 pm 2013/05/07&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;short vs long observation time runs &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/d420c0578e8c77906b4d4e7f94fa4c4dcdfefeee&quot;&gt;12:54 pm 2013/05/07&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;online example of replicates comparing all models &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/0f682028113e42355f811793c915252d40ac45bb&quot;&gt;12:28 pm 2013/05/07&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;misc&quot;&gt;Misc&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/cboettig/sandbox/blob/c319b983535be2e79ea8987d68ad6d21f7bc5381/tex-pandoc-tricks/ucscletter.cls&quot;&gt;latex templates for UCSC AMS dept&lt;/a&gt; Gosh sometimes it’s nice to be officially in a department that understands tex.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://news.harvard.edu/gazette/story/2013/04/understanding-student-weaknesses/&quot;&gt;Best teacher’s know student’s misconceptions&lt;/a&gt; Hmm, our misconceptions are probably a bigger barrier than lack of knowledge for most scientists too…&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ohh, &lt;a href=&quot;http://jekyllrb.com/docs/upgrading/&quot;&gt;Jekyll 1.0 released&lt;/a&gt;, &lt;a href=&quot;https://github.com/mojombo/jekyll/blob/v1.0.0/History.txt&quot;&gt;changelog&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=pFJtwSXC6qA&quot;&gt;#openoxford’s debate&lt;/a&gt; Elseiver rep says that if they disclose prices, prices would be driven so low that they’d go out of buisness. Yikes, what would the economists say!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, you can &lt;a href=&quot;https://github.com/blog/1492-repository-search-on-all-repositories&quot;&gt;search within a git repositories&lt;/a&gt; (without cloning first and using grep obviously. Before one was had global search options only, albeit filtered by language, etc).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;span class=&quot;showtooltip&quot; title=&quot;Callaway E (2013). 'Biomedical Journal And Publisher Hope to Bring Preprints to Life.' Nature Medicine, 19, pp. 512-512. ISSN 1078-8956.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1038/nm0513-512&quot; rel=&quot;http://purl.org/spar/cito/critiques&quot; &gt;Callaway (2013)&lt;/a&gt;&lt;/span&gt; Ironic that they quote @mfenner saying that peerJ preprints are too like Nature Preceedings while also pointing out the role of archiving things like slides and posters (as these were categories of objects in Preceedings, but not in arXiv or PeerJ). Of course I agree with Martin about diverse outputs, but there appears to be something about the concept of preprint server that carries more meaning for people. Clearly figshare is a viable preprint server that is both the most discipline agonstic (arXiv isn’t interesting in expanding its scope, and peerJ’s stated scope does not cover earth science / climate science / physical oceanography side of things) and content-type agnostic (paper, poster, data, code, or anything else), and has a rich API that is absent or minimal in the other platforms.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;esa-schedule&quot;&gt;ESA schedule&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Sun Aug 4 noon-5pm &lt;a href=&quot;http://eco.confex.com/eco/2013/webprogrampreliminary/Session9030.html&quot;&gt;Conducting Open Science Using R and DataOne&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Tues Aug 6 8-10 pm &lt;a href=&quot;http://eco.confex.com/eco/2013/webprogrampreliminary/Session8911.html&quot;&gt;Open Science and Ecology&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Ewen Callaway, (2013) Biomedical Journal And Publisher Hope to Bring Preprints to Life. &lt;em&gt;Nature Medicine&lt;/em&gt; &lt;strong&gt;19&lt;/strong&gt; 512-512 &lt;a href=&quot;http://dx.doi.org/10.1038/nm0513-512&quot;&gt;10.1038/nm0513-512&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Reading and potential examples for talk to ERE next week</title>
   <link href="/2013/05/03/notes.html"/>
   <updated>2013-05-03T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/05/03/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;parametric-bayesian-comparisons&quot;&gt;Parametric Bayesian comparisons&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Added parameteric Bayesian version of Ricker to the set of comparisons, see &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/ee4467c8defe81a27aadfbc4359cd0695339de6b/inst/examples/BUGS/allen.md&quot;&gt;allen.Rmd&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Adjusted thinning of posterior sample before determining optimum of GP&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reading-examples&quot;&gt;Reading / Examples&lt;/h2&gt;
&lt;p&gt;Need a nice set of basic fisheries examples involving potential tipping points for ERE talk. hmm.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;As mentioned in &lt;span class=&quot;showtooltip&quot; title=&quot;Worm B, Hilborn R, Baum J, Branch T, Collie J, Costello C, Fogarty M, Fulton E, Hutchings J, Jennings S, Jensen O, Lotze H, Mace P, McClanahan T, Minto C, Palumbi S, Parma A, Ricard D, Rosenberg A, Watson R and Zeller D (2009). 'Rebuilding Global Fisheries.' Science, 325, pp. 578-585. ISSN 0036-8075.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1126/science.1173146&quot; rel=&quot;http://purl.org/spar/cito/citesAsEvidence&quot; &gt;Worm et al. (2009)&lt;/a&gt;&lt;/span&gt; .&lt;/li&gt;
&lt;li&gt;Algal-reef example from &lt;span class=&quot;showtooltip&quot; title=&quot;Aronson R and Precht W (2000). 'Herbivory And Algal Dynamics on The Coral Reef at Discovery Bay, Jamaica.' Limnology And Oceanography, 45, pp. 251-255. .&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.4319/lo.2000.45.1.0251&quot; rel=&quot;http://purl.org/spar/cito/citesAsEvidence&quot; &gt;Aronson &amp;amp; Precht (2000)&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Fish collapse following reef distruction &lt;span class=&quot;showtooltip&quot; title=&quot;Paddack M, Reynolds J, Aguilar C, Appeldoorn R, Beets J, Burkett E, Chittaro P, Clarke K, Esteves R, Fonseca A, Forrester G, Friedlander A, García-Sais J, González-Sansón G, Jordan L, McClellan D, Miller M, Molloy P, Mumby P, Nagelkerken I, Nemeth M, Navas-Camacho R, Pitt J, Polunin N, Reyes-Nivia M, Robertson D, Rodríguez-Ramírez A, Salas E, Smith S, Spieler R, Steele M, Williams I, Wormald C, Watkinson A and Côté I (2009). 'Recent Region-Wide Declines in Caribbean Reef Fish Abundance.' Current Biology, 19, pp. 590-595. ISSN 09609822.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1016/j.cub.2009.02.041&quot; rel=&quot;http://purl.org/spar/cito/citesAsEvidence&quot; &gt;Paddack et al. (2009)&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Alt stable states in marine systems &lt;span class=&quot;showtooltip&quot; title=&quot;Petraitis P and Dudgeon S (2004). 'Detection of Alternative Stable States in Marine Communities.' Journal of Experimental Marine Biology And Ecology, 300, pp. 343-371. ISSN 00220981.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1016/j.jembe.2003.12.026&quot; rel=&quot;http://purl.org/spar/cito/citesAsEvidence&quot; &gt;Petraitis &amp;amp; Dudgeon (2004)&lt;/a&gt;&lt;/span&gt; , &lt;span class=&quot;showtooltip&quot; title=&quot;Osman R, Munguia P and Zajac R (2010). 'Ecological Thresholds in Marine Communities: Theory, Experiments And Management.' Marine Ecology Progress Series, 413, pp. 185-187. ISSN 0171-8630.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.3354/meps08765&quot; rel=&quot;http://purl.org/spar/cito/citesAsEvidence&quot; &gt;Osman et al. (2010)&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cod examples? Forage fish? Peruvian Anchovy. Overfishing vs climate variability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And more examples from marine systems in &lt;span class=&quot;showtooltip&quot; title=&quot;Oguz T and Velikova V (2010). 'Abrupt Transition of The Northwestern Black Sea Shelf Ecosystem From A Eutrophic to an Alternative Pristine State.' Marine Ecology Progress Series, 405, pp. 231-242. ISSN 0171-8630.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.3354/meps08538&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Oguz &amp;amp; Velikova (2010)&lt;/a&gt;&lt;/span&gt; , &lt;span class=&quot;showtooltip&quot; title=&quot;Lindegren M, Diekmann R and Möllmann C (2010). 'Regime Shifts, Resilience And Recovery of A Cod Stock.' Marine Ecology Progress Series, 402, pp. 239-253. ISSN 0171-8630.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.3354/meps08454&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Lindegren et al. (2010)&lt;/a&gt;&lt;/span&gt; , &lt;span class=&quot;showtooltip&quot; title=&quot;deYoung B, Barange M, Beaugrand G, Harris R, Perry R, Scheffer M and Werner F (2008). 'Regime Shifts in Marine Ecosystems: Detection, Prediction And Management.' Trends in Ecology &amp;amp; Evolution, 23, pp. 402-409. ISSN 01695347.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2008.03.008&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;deYoung et al. (2008)&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Beyond tipping points: avoiding policy-based thresholds. &lt;span class=&quot;showtooltip&quot; title=&quot;Pikitch E (2012). 'The Risks of Overfishing.' Science, 338, pp. 474-475. ISSN 0036-8075.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1126/science.1229965&quot; rel=&quot;http://purl.org/spar/cito/citesAsEvidence&quot; &gt;Pikitch (2012)&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;http://www.ecotippingpoints.org/our-stories/indepth/usa-hawaii-hanauma-environmental-management.html ?&lt;/li&gt;
&lt;li&gt;&lt;p&gt;http://www.ecotippingpoints.org/our-stories/indepth/philippines-apo-marine-sanctuary-coral-reef-fishery.html&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Richard B. Aronson, William F. Precht, (2000) Herbivory And Algal Dynamics on The Coral Reef at Discovery Bay, Jamaica. &lt;em&gt;Limnology And Oceanography&lt;/em&gt; &lt;strong&gt;45&lt;/strong&gt; 251-255 &lt;a href=&quot;http://dx.doi.org/10.4319/lo.2000.45.1.0251&quot;&gt;10.4319/lo.2000.45.1.0251&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;M Lindegren, R Diekmann, C Möllmann, (2010) Regime Shifts, Resilience And Recovery of A Cod Stock. &lt;em&gt;Marine Ecology Progress Series&lt;/em&gt; &lt;strong&gt;402&lt;/strong&gt; 239-253 &lt;a href=&quot;http://dx.doi.org/10.3354/meps08454&quot;&gt;10.3354/meps08454&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;T Oguz, V Velikova, (2010) Abrupt Transition of The Northwestern Black Sea Shelf Ecosystem From A Eutrophic to an Alternative Pristine State. &lt;em&gt;Marine Ecology Progress Series&lt;/em&gt; &lt;strong&gt;405&lt;/strong&gt; 231-242 &lt;a href=&quot;http://dx.doi.org/10.3354/meps08538&quot;&gt;10.3354/meps08538&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;RW Osman, P Munguia, RN Zajac, (2010) Ecological Thresholds in Marine Communities: Theory, Experiments And Management. &lt;em&gt;Marine Ecology Progress Series&lt;/em&gt; &lt;strong&gt;413&lt;/strong&gt; 185-187 &lt;a href=&quot;http://dx.doi.org/10.3354/meps08765&quot;&gt;10.3354/meps08765&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Michelle J. Paddack, John D. Reynolds, Consuelo Aguilar, Richard S. Appeldoorn, Jim Beets, Edward W. Burkett, Paul M. Chittaro, Kristen Clarke, Rene Esteves, Ana C. Fonseca, Graham E. Forrester, Alan M. Friedlander, Jorge García-Sais, Gaspar González-Sansón, Lance K.B. Jordan, David B. McClellan, Margaret W. Miller, Philip P. Molloy, Peter J. Mumby, Ivan Nagelkerken, Michael Nemeth, Raúl Navas-Camacho, Joanna Pitt, Nicholas V.C. Polunin, Maria Catalina Reyes-Nivia, D. Ross Robertson, Alberto Rodríguez-Ramírez, Eva Salas, Struan R. Smith, Richard E. Spieler, Mark A. Steele, Ivor D. Williams, Clare L. Wormald, Andrew R. Watkinson, Isabelle M. Côté, (2009) Recent Region-Wide Declines in Caribbean Reef Fish Abundance. &lt;em&gt;Current Biology&lt;/em&gt; &lt;strong&gt;19&lt;/strong&gt; 590-595 &lt;a href=&quot;http://dx.doi.org/10.1016/j.cub.2009.02.041&quot;&gt;10.1016/j.cub.2009.02.041&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Peter S. Petraitis, Steve R. Dudgeon, (2004) Detection of Alternative Stable States in Marine Communities. &lt;em&gt;Journal of Experimental Marine Biology And Ecology&lt;/em&gt; &lt;strong&gt;300&lt;/strong&gt; 343-371 &lt;a href=&quot;http://dx.doi.org/10.1016/j.jembe.2003.12.026&quot;&gt;10.1016/j.jembe.2003.12.026&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;E. K. Pikitch, (2012) The Risks of Overfishing. &lt;em&gt;Science&lt;/em&gt; &lt;strong&gt;338&lt;/strong&gt; 474-475 &lt;a href=&quot;http://dx.doi.org/10.1126/science.1229965&quot;&gt;10.1126/science.1229965&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;B. Worm, R. Hilborn, J. K. Baum, T. A. Branch, J. S. Collie, C. Costello, M. J. Fogarty, E. A. Fulton, J. A. Hutchings, S. Jennings, O. P. Jensen, H. K. Lotze, P. M. Mace, T. R. McClanahan, C. Minto, S. R. Palumbi, A. M. Parma, D. Ricard, A. A. Rosenberg, R. Watson, D. Zeller, (2009) Rebuilding Global Fisheries. &lt;em&gt;Science&lt;/em&gt; &lt;strong&gt;325&lt;/strong&gt; 578-585 &lt;a href=&quot;http://dx.doi.org/10.1126/science.1173146&quot;&gt;10.1126/science.1173146&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Brad deYoung, Manuel Barange, Gregory Beaugrand, Roger Harris, R. Ian Perry, Marten Scheffer, Francisco Werner, (2008) Regime Shifts in Marine Ecosystems: Detection, Prediction And Management. &lt;em&gt;Trends in Ecology &amp;amp; Evolution&lt;/em&gt; &lt;strong&gt;23&lt;/strong&gt; 402-409 &lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2008.03.008&quot;&gt;10.1016/j.tree.2008.03.008&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notebook features: SHA Hashes</title>
   <link href="/2013/05/03/notebook-features-hashes-providing-an-immutable-and-verifiable-research-record.html"/>
   <updated>2013-05-03T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/05/03/notebook-features-hashes-providing-an-immutable-and-verifiable-research-record</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;Note: this entry is part of a &lt;a href=&quot;http://carlboettiger.info/2013/04/26/notebook-features-introduction.html&quot;&gt;series of posts&lt;/a&gt; which explain some of the techinical features of my lab notebook.&lt;/p&gt;
&lt;p&gt;I version manage all changes to my entry using git. Each page is linked to its source history on Github, which will display a list of all previous edits to the post with an easy-to-read commit log and highlighted diffs. A version history is often considered an essential part of an open lab notebook, where changes to the notebook are documented and preserved. While wikis, google docs, dropbox, wordpress plugins, or just regular backups can provide version history of pages, none come close to comparison with a full version management system such as git. This is because git’s underlying architecture is based on&lt;br /&gt;&lt;a href=&quot;http://www-cs-students.stanford.edu/~blynn/gitmagic/ch08.html&quot;&gt;The magic of cryptographic SHA hashes&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Hashes provide an immutable and verifiable record of any all changes I make. Because the hash is generated by the cryptographic SHA1 algorithm from the contents of the site, it is impossible to make changes without causing the hash to update. By referencing the content’s hash value we can be sure to link to a constant version of the entry. These can be verified by re-generating the hash (requiring the previous state of the repository in this case, see note below). Unlike publication timestamps, versions, or DOIs, this provides a way not only to reference particular versions of a file, but a cryptographically secure way to &lt;em&gt;verify&lt;/em&gt; that the version is what it claims to be. &lt;a href=&quot;http://www.tkuhn.ch/&quot;&gt;Tobias Kuhn&lt;/a&gt; has &lt;a href=&quot;http://www.force11.org/node/4301&quot;&gt;observed&lt;/a&gt; that this is a valuable feature we should want to see for all scientific publishing. Each of my posts now displays its SHA hash on the sidebar along with other metadata. While the &lt;code&gt;history&lt;/code&gt; button already provides a convient way to browse all previous versions of a post, I chose to display the SHA hash directly so that the hash value would be part of the document metadata, while also highlighting this feature.&lt;/p&gt;
&lt;p&gt;In addition to the GitHub repository for my lab notebook, My research code, analyses, and manuscripts are collected into Github repositories by project. This allows my analysis and paper writing to benefit from this same immutable and verifiable record. Because GitHub uses the SHA hashes in its link structure, this also provides a convenient way to link to a particular version of code in a given entry. This way, I can be sure the contents of the file displayed at that link never change, even as I continue to update that file. Even if the file or containing directory is later deleted or moved, the link will still resolve. Only if the entire project repo were deleted or if Github itself dissolved would the link be lost. Even then, using the SHA hash given in the link we could determine the contents of the file from some other copy of the repository (such as a local or figshare archive).&lt;/p&gt;
&lt;p&gt;Tobias is actually working on his own SHA hash approach which is somewhat superior to the simpler method of using git. The Github hash corresponds to the state of the entire repository/notebook at the time of the commit, rather than the contents of an individual file. Consequently, one would need a snapshot of the entire repository, available on Github, to perform the verification. Tobias is looking into generating hashes based on the contents of the file directly – so far, only RDF data – that could proivde a unique and verifiable reference for any scholarly data or publication.&lt;/p&gt;
&lt;p&gt;Version managing the notebook and code has many more practical day-to-day benefits, such as recovering from a mistaken deleted or corrupted file, merging changes made on different machines or by collaborators, or creating branches to test new features without disrupting current version, and comparing differences as a file evolves.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Scholarly Infrastructure Thoughts</title>
   <link href="/2013/05/02/scholarly-infrastructure-thoughts.html"/>
   <updated>2013-05-02T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/05/02/scholarly-infrastructure-thoughts</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;h2 id=&quot;sustainable-research&quot;&gt;Sustainable Research&lt;/h2&gt;
&lt;p&gt;Happened across a provocative &lt;a href=&quot;http://cran.r-project.org/web/packages/mcmc/ChangeLog&quot;&gt;example&lt;/a&gt; of why we need a software ecosystem, though it was certainly not intended to be one, which led me to ask myself:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;How complex does an algorithm have to be before a talented researcher with expertise in both the relevant mathematics and computer science will make a significant mistake in their first release of the software?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;As a corollary we might also ask, “How much less care do we put into research code not destined for release?”&lt;/p&gt;
&lt;p&gt;This changelog clearly reflects these difficulties face well-established researchers with long publication records on these very methods. If such individuals can make mistakes in packages, are we supposed to trust the myriad personal implementations of this and more complex algorithms that bulwark our literature today?&lt;/p&gt;
&lt;p&gt;Academic knowledge is currently built in the mortar and bricks of publication and citation. Publications advance new claims built up on existing claims (and very occasionally replacing them) through citations. It an approach that does not scale well on many fronts. To verify information we must trace the citation chain, which grows far to quickly to for human processing and is not usually amenable to computer processing. Yet here it is the statistical scaling that concerns me more – a paper advances that a claim is true with a certain probability, given that the methods are implemented without error. The more publications we string together, the higher the probability that we observe false positives, but also that we observe implementation errors. For much of research today, we need not construct the scientific argument in this manner.&lt;/p&gt;
&lt;p&gt;Thanks to computational advances of the last several decades, public repositories of the data and the methods (such as can be implemented as software anyway), we can build on existing work by direct analysis of the data and methods, rather than treating the conclusions as given. Evidence would no longer come primarily in the highly circumstantial manner of citations to previous claims, but to direct analysis of data. Using a common pool of data and methods would align incentives better to maintain and improve upon this infrastructure (the way major companies contribute to the underlying ‘plumbing’ provided by shared open source infrastructure), while there is no incentive for the literature to work in such a way.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://cameronneylon.net/blog/whats-the-right-model-for-shared-scholarly-communications-infrastructure&quot;&gt;Cameron Neylon&lt;/a&gt;, and link in my comment.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Musings On Conservation Literature</title>
   <link href="/2013/05/02/musings-on-conservation-literature.html"/>
   <updated>2013-05-02T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/05/02/musings-on-conservation-literature</id>
   
   <content type="html">&lt;p&gt;Just because I’m a theorist deeply entrenched in methodological concerns about uncertainty and decision making doesn’t mean I don’t think about practical conservation from time to time. Some musings from my &lt;a href=&quot;http://dynamicecology.wordpress.com/2013/04/29/the-implementation-gap-in-conservation-biology-is-math-contributing-to-the-problem&quot;&gt;comment here&lt;/a&gt;, copied over for my own reference.&lt;/p&gt;
&lt;p&gt;Though I would like to believe the gap stems from the problems you discuss, I think that differing objectives between research and application may play a much larger role. I suspect that scientific papers that are most useful and influential for conservation practitioners and policymakers are those which confirm what they already believe, or whatever the interests opposed to them least want to hear. Let’s call these “Cassandra” papers, since in this context they usually forecast disaster. For the practitioner it may matters little whether the math is simple or complex, clearly explained or impenetrable, or even right or not so right. Worm et al 2006 paper which the media quickly decided predicted the end of global fisheries within 50 years is perhaps a good example.&lt;/p&gt;
&lt;p&gt;Okay, so beyond bolstering arguments already being made by those who propose, implement or legislate conservation against their opposition, there are certainly unknowns that they might turn to research to answer. Resource allocation might be an example of this; e.g. do we prioritize purchasing pristine areas that are not likely to be threatened or less pristine areas in more immediate danger (a la Pfaff). Let’s call these “rule of thumb” papers, where the conclusion is an easily applied guide-line. It seems doubtful that the practitioners would be inhibited by their access and understanding of the math in this case, since they want the research to provide an answer they can trust, and not worry so much about what math justifies it. They are more likely to use proxies of quality (journal, researcher, affiliation, popularity of the method), then working through the assumptions to see if they like them; no?&lt;/p&gt;
&lt;p&gt;So there is a third case in which the conclusion is of the sort “apply my method and it will tell you what to do”, as opposed to “here’s what to do”. I think only this case falls at risk to the mathematics being a barrier, though when accompanied by user-friendly software tools perhaps that can be dismissed as well. These “methods” papers are probably the favorite option of many researchers, as they seem the most rigorous, accurate way, reflecting the details of the problem at hand. Scientists are probably least fond of the first example, where even the paper’s authors may feel the conclusions are being overstated, while others feel such work is wrong and counterproductive. I’d guess many researchers are lukewarm towards the middle case, as better than a coin flip. I imagine from the conservation practitioner’s ranking is reversed. To what extent would you agree with this classification? If so, how is the conservation literature distributed across these categories, and how might we want it to be distributed? Do we indeed have the greatest impact writing Cassandra papers rather than writing nice clear methods, and if so, what are the implications?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Integrating Over Posterior Gp</title>
   <link href="/2013/05/01/integrating-over-posterior-gp.html"/>
   <updated>2013-05-01T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/05/01/integrating-over-posterior-gp</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Added integration over the posterior distribution of the GP&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Added example of parametric Bayesian inference based on Ricker&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;log&quot;&gt;Log&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;varying parameters &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/eecb2c12c33a522fb8dcbe588d7cf4fcbb0269eb&quot;&gt;06:07 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;example based on gp means &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/68004b28ab15e89c6f6e05cd2953a4844385dca2&quot;&gt;03:44 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;run means example as separate script &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/91a21b655f6fadeb8daf364c87bcd87d5069c2e7&quot;&gt;02:55 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;compare against just using means &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/ba4e491d6ecd0fd3fae533337e099d522d5a6b8d&quot;&gt;02:52 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Merge branch ‘master’ of github.com:cboettig/nonparametric-bayes &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/9a58d0f9c73f85dee5b7010d895f024cd3f6dbb5&quot;&gt;02:26 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Merge branch ‘master’ of github.com:cboettig/nonparametric-bayes &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/eb9ee9f76f6638d8300132a4830e39a052cb223f&quot;&gt;02:23 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;add gp posteriors to package &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/e32361cdc39e7902d9374b303d9474f0f26a860c&quot;&gt;02:16 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;staging run for integrating over GP posterior (large memory reqs) &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/50c0bc655f8d71f98f7b144f6d51d2e269d878fc&quot;&gt;02:13 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;updated example of gp basics includes mcmc and shows influence of the prior &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/e6c9b3048fd0cc50d0ec7eb00ac7cb9b00591618&quot;&gt;01:15 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;example testing new routine &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/331a441ca8bdf83ce660e9fc35c58bb9fb5e2a47&quot;&gt;01:14 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;tidying repo &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/2b33ab0323778dfc7a60c18fc62acb98486d9c72&quot;&gt;01:07 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;merge analyses back into allen.Rmd &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/27f4db239583bd861d58d9a2e63a9e3c2907a943&quot;&gt;12:48 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;adapted to the custom version &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/368456178edc571bb4d48b1c5952f40c1224f187&quot;&gt;12:37 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Test examples demonstrating the custom mcmc GP &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/a1a2c37aae225005193029d19d6a9b435cbf3921&quot;&gt;12:36 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;package updates with the custom gp method &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/61508484713958d00dc8072fb9d224749f1a9915&quot;&gt;12:35 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Example using custom GP routine. In this case, both MLE methods fail, while the GP does fine and the parametric Bayesian method performs best. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/ff33c9b6f78ffa1e135204789e730e65e82951b5&quot;&gt;12:34 pm 2013/05/01&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Bayesian Gp Regression By Metropolis Hastings</title>
   <link href="/2013/05/01/bayesian-GP-regression-by-metropolis-hastings.html"/>
   <updated>2013-05-01T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/05/01/bayesian-GP-regression-by-metropolis-hastings</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;(Development version for reference; code functions now in &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/331a441ca8bdf83ce660e9fc35c58bb9fb5e2a47/R/gp_mcmc.R&quot;&gt;R/gp_mcmc.R&lt;/a&gt;)&lt;/p&gt;
&lt;h3 id=&quot;function-definitions&quot;&gt;Function definitions&lt;/h3&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(mcmc)
&lt;span class=&quot;co&quot;&gt;#&amp;#39; Basic regression in Gaussian processes  &lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; &lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; &lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @param x Observed x values, (vector or matrix with columns for each dimension of data)&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @param y Vector of observed y values in the training data&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @param init_pars the initial guesses for lengthscale l and process noise sigma_n&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @param n iterations of the metropolis algorithm&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @details Currently assumes the covariance function.  By default we will use &lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; the squared exponential (also called radial basis or Gaussian, &lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; though it is not this that gives Gaussian process it&amp;#39;s name; &lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; any covariance function would do) as the covariance function, &lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; $\operatorname{cov}(X_i, X_j) = \exp\left(-\frac{(X_i - X_j)^2}{2 \ell ^ 2}\right)$&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @return the MCMC output, as constructed by \link{metrop} from the mcmc package.&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @export&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @import mcmc  &lt;/span&gt;
gp_mcmc &amp;lt;- function(x, y, &lt;span class=&quot;dt&quot;&gt;init_pars =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;l=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;sigma.n=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;n =&lt;/span&gt; &lt;span class=&quot;fl&quot;&gt;1e4&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;d.p =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;s2.p =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;)){

  lpriors &amp;lt;- function(pars){
    prior &amp;lt;- &lt;span class=&quot;kw&quot;&gt;unname&lt;/span&gt;(
      &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(pars[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]), d.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; d.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]) *
      &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(pars[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]), s2.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], s2.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]) 
    )
    &lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(prior)
  }
  posterior &amp;lt;- function(pars, x, y){ 
    l &amp;lt;- &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(pars[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;])
    sigma.n &amp;lt;- &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(pars[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;])
    
    cov &amp;lt;- function(X, Y) &lt;span class=&quot;kw&quot;&gt;outer&lt;/span&gt;(X, Y, SE, l)
    I &amp;lt;- &lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(x))
    K &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x, x) 
    
    loglik &amp;lt;- - &lt;span class=&quot;fl&quot;&gt;0.5&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(y) %*% &lt;span class=&quot;kw&quot;&gt;solve&lt;/span&gt;(K + sigma.n^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * I) %*% y -
      &lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;det&lt;/span&gt;(K + sigma.n^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;*I)) -
      &lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(y) * &lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * pi) / &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;
    
    loglik + &lt;span class=&quot;kw&quot;&gt;lpriors&lt;/span&gt;(pars)
  }
  
  out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;metrop&lt;/span&gt;(posterior, &lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(init_pars), n, &lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; obs$x, &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; obs$y)  
  out$d.p &amp;lt;- d.p
  out$s2.p &amp;lt;- s2.p
  
  out
}&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;co&quot;&gt;#&amp;#39; predict the expected values and posterior distributions of the Gaussian Process&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; &lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @param x_predict the values at which we desire predictions&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @param covs if TRUE, return covariances instead of variances (set high thinning as this is memory intensive)&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @import reshape2&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @export&lt;/span&gt;
gp_predict &amp;lt;- function(gp, x_predict, &lt;span class=&quot;dt&quot;&gt;burnin=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;thin=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;covs=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;){

  postdist &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cbind&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;index=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:gp$nbatch, &lt;span class=&quot;kw&quot;&gt;as.data.frame&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(gp$batch)))
  s &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(burnin&lt;span class=&quot;dv&quot;&gt;+1&lt;/span&gt;, gp$nbatch, &lt;span class=&quot;dt&quot;&gt;by=&lt;/span&gt;thin)
  postdist &amp;lt;- postdist[s,]
  &lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(postdist) &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;index&amp;quot;&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(gp$initial))
  
  indices &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;kw&quot;&gt;dim&lt;/span&gt;(postdist)[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]
  
  out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(indices, function(i){
    l &amp;lt;- postdist[i, &lt;span class=&quot;st&quot;&gt;&amp;quot;l&amp;quot;&lt;/span&gt;]
    sigma.n &amp;lt;- postdist[i, &lt;span class=&quot;st&quot;&gt;&amp;quot;sigma.n&amp;quot;&lt;/span&gt;]
    
    cov &amp;lt;- function(X, Y) &lt;span class=&quot;kw&quot;&gt;outer&lt;/span&gt;(X, Y, SE, l)
    cov_xx_inv &amp;lt;- &lt;span class=&quot;kw&quot;&gt;solve&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(obs$x, obs$x) + sigma.n^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(obs$x)))
    Ef &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x_predict, obs$x) %*% cov_xx_inv %*% obs$y
    Cf &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x_predict, x_predict) - &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x_predict, obs$x)  %*% cov_xx_inv %*% &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(obs$x, x_predict)
    &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;Ef =&lt;/span&gt; Ef, &lt;span class=&quot;dt&quot;&gt;Cf =&lt;/span&gt; Cf, &lt;span class=&quot;dt&quot;&gt;Vf =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(Cf))
  })
  
  Ef_posterior &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(out, &lt;span class=&quot;st&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;dt&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;`&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;Ef&amp;quot;&lt;/span&gt;)
  Cf_posterior &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(out, &lt;span class=&quot;st&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;dt&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;`&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;Cf&amp;quot;&lt;/span&gt;)
  Vf_posterior &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(out, &lt;span class=&quot;st&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;dt&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;`&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;Vf&amp;quot;&lt;/span&gt;)
  
  
  E_Ef &amp;lt;- &lt;span class=&quot;kw&quot;&gt;rowMeans&lt;/span&gt;(Ef_posterior)
  E_Cf &amp;lt;- &lt;span class=&quot;kw&quot;&gt;matrix&lt;/span&gt;( &lt;span class=&quot;kw&quot;&gt;apply&lt;/span&gt;(Cf_posterior, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, sum) / &lt;span class=&quot;kw&quot;&gt;dim&lt;/span&gt;(Cf_posterior)[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;ncol =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;dim&lt;/span&gt;(Cf_posterior)[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]) )
  E_Vf &amp;lt;- &lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(E_Cf) &lt;span class=&quot;co&quot;&gt;# same as rowMeans(Vf_posterior)&lt;/span&gt;
  
  &lt;span class=&quot;co&quot;&gt;# list format better for return&lt;/span&gt;
  Cf_posterior &amp;lt;- &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(out, &lt;span class=&quot;st&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;dt&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;`&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;Cf&amp;quot;&lt;/span&gt;)
  
  &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;Ef_posterior =&lt;/span&gt; Ef_posterior, 
       &lt;span class=&quot;dt&quot;&gt;Vf_posterior =&lt;/span&gt; Vf_posterior,
       &lt;span class=&quot;dt&quot;&gt;Cf_posterior =&lt;/span&gt; Cf_posterior,
       &lt;span class=&quot;dt&quot;&gt;E_Ef =&lt;/span&gt; E_Ef, &lt;span class=&quot;dt&quot;&gt;E_Cf =&lt;/span&gt; E_Cf, &lt;span class=&quot;dt&quot;&gt;E_Vf =&lt;/span&gt; E_Vf)
  
}  &lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(reshape2)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(ggplot2)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(plyr)
&lt;span class=&quot;co&quot;&gt;#&amp;#39; Summary plots showing the trace and posteriors for the gp_mcmc estimates&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; &lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @param gp a fit of the gaussian process from gp_mcmc&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @param burnin length of sequence to discard as a transient&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @param thin frequency of sub-sampling (make posterior distribution smaller if necessary)&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @return two ggplot2 objects, one plotting the trace and one &lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; plotting the posteriors in black with priors overlaid in red.  &lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @import reshape2&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @import ggplot2&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @import plyr&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;#&amp;#39; @export&lt;/span&gt;
summary_gp_mcmc &amp;lt;- function(gp, &lt;span class=&quot;dt&quot;&gt;burnin=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;thin=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;){

  postdist &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cbind&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;index=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:gp$nbatch, &lt;span class=&quot;kw&quot;&gt;as.data.frame&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(gp$batch)))
  s &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(burnin&lt;span class=&quot;dv&quot;&gt;+1&lt;/span&gt;, gp$nbatch, &lt;span class=&quot;dt&quot;&gt;by=&lt;/span&gt;thin)
  postdist &amp;lt;- postdist[s,]
  &lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(postdist) &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;index&amp;quot;&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(gp$initial))
  
  &lt;span class=&quot;co&quot;&gt;# TRACES&lt;/span&gt;
  df &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(postdist, &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;index&amp;quot;&lt;/span&gt;)
  traces_plot &amp;lt;- 
    &lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(df) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(index, value)) + 
    &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~ variable, &lt;span class=&quot;dt&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ncol=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)
  
  s2.p &amp;lt;- gp$s2.p
  d.p &amp;lt;- gp$d.p
  s2_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, s2.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], s2.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;])
  d_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, d.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; d.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;])
  prior_fns &amp;lt;- &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;l =&lt;/span&gt; d_prior, &lt;span class=&quot;dt&quot;&gt;sigma.n =&lt;/span&gt; s2_prior)
  
  prior_curves &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ddply&lt;/span&gt;(df, &lt;span class=&quot;st&quot;&gt;&amp;quot;variable&amp;quot;&lt;/span&gt;, function(dd){
    grid &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;min&lt;/span&gt;(dd$value), &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(dd$value), &lt;span class=&quot;dt&quot;&gt;length =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;)
    &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;value =&lt;/span&gt; grid, &lt;span class=&quot;dt&quot;&gt;density =&lt;/span&gt; prior_fns[[dd$variable[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]]](grid))
  })
  
  &lt;span class=&quot;co&quot;&gt;# Posteriors (easier to read than histograms)&lt;/span&gt;
  posteriors_plot &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(df, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value)) + 
    &lt;span class=&quot;kw&quot;&gt;stat_density&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;geom=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;path&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;position=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;identity&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.7&lt;/span&gt;) +
    &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;prior_curves, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;value, &lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;density), &lt;span class=&quot;dt&quot;&gt;col=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;) + 
    &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~ variable, &lt;span class=&quot;dt&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ncol=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)
  
  &lt;span class=&quot;kw&quot;&gt;print&lt;/span&gt;(traces_plot)
  &lt;span class=&quot;kw&quot;&gt;print&lt;/span&gt;(posteriors_plot)
  
  out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;traces_plot =&lt;/span&gt; traces_plot, &lt;span class=&quot;dt&quot;&gt;posteriors_plot =&lt;/span&gt; posteriors_plot)
  &lt;span class=&quot;kw&quot;&gt;invisible&lt;/span&gt;(out)
}

&lt;span class=&quot;co&quot;&gt;# Helper function: The default covariance function&lt;/span&gt;
SE &amp;lt;- function(Xi,Xj, l) &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(-&lt;span class=&quot;fl&quot;&gt;0.5&lt;/span&gt; * (Xi - Xj) ^ &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; / l ^ &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;/h2&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;x_predict &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;dt&quot;&gt;len=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;50&lt;/span&gt;)
obs &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;, -&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;, -&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;),
                  &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, -&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;))&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gp_mcmc&lt;/span&gt;(obs$x, obs$y, &lt;span class=&quot;dt&quot;&gt;d.p =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;,.&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;s2.p =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;,.&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;))&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;summary_gp_mcmc&lt;/span&gt;(gp)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;http://farm8.staticflickr.com/7285/8739390350_c4c06db5ab_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-6&quot; /&gt; &lt;img src=&quot;http://farm8.staticflickr.com/7285/8739390438_50350c1a38_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-6&quot; /&gt;&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;gp_dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gp_predict&lt;/span&gt;(gp, x_predict)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;tgp_dat &amp;lt;- 
    &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(  &lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; x_predict, 
                 &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; gp_dat$E_Ef, 
                 &lt;span class=&quot;dt&quot;&gt;ymin =&lt;/span&gt; gp_dat$E_Ef - &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(gp_dat$E_Vf), 
                 &lt;span class=&quot;dt&quot;&gt;ymax =&lt;/span&gt; gp_dat$E_Ef + &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(gp_dat$E_Vf) )

&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(tgp_dat) + &lt;span class=&quot;kw&quot;&gt;geom_ribbon&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x,y,&lt;span class=&quot;dt&quot;&gt;ymin=&lt;/span&gt;ymin,&lt;span class=&quot;dt&quot;&gt;ymax=&lt;/span&gt;ymax), &lt;span class=&quot;dt&quot;&gt;fill=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;gray80&amp;quot;&lt;/span&gt;) +
    &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y), &lt;span class=&quot;dt&quot;&gt;lwd=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.8&lt;/span&gt;) + 
    &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;obs, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x,y), &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.8&lt;/span&gt;) + 
    &lt;span class=&quot;kw&quot;&gt;xlab&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;expression&lt;/span&gt;(X[t])) + &lt;span class=&quot;kw&quot;&gt;ylab&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;expression&lt;/span&gt;(X[t&lt;span class=&quot;dv&quot;&gt;+1&lt;/span&gt;])) &lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm8.staticflickr.com/7282/8738272607_d913f04a10_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-8&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-8&lt;/figcaption&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>Difficulties with tgp; taking custom mcmc approach for GPs</title>
   <link href="/2013/04/30/tgp-difficulties-and-custom-mcmc-for-gp.html"/>
   <updated>2013-04-30T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/30/tgp-difficulties-and-custom-mcmc-for-gp</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Running into some unpredictable and not consistently replicable memory errors in the tgp function calls. Also rather troublesome that return object provides only posterior means for the process mean and covariance matrix.&lt;/p&gt;
&lt;h2 id=&quot;generic-gp-methods&quot;&gt;Generic GP methods&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Implemented MCMC sampler. Excerpt below based on my &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/e6c9b3048fd0cc50d0ec7eb00ac7cb9b00591618/inst/examples/gaussian-process-basics.md&quot;&gt;gaussian-process-basics.md&lt;/a&gt; script, as updated to include this case.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Define some example priors&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;lpriors &amp;lt;- function(pars){
   d.p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;)
  s2.p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;)  
   
  prior &amp;lt;- &lt;span class=&quot;kw&quot;&gt;unname&lt;/span&gt;(
    &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(pars[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]), d.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; d.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]) *
    &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(pars[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]), s2.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], s2.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]) 
  )
  
  &lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(prior)
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Define the posterior function for our metropolis sampler&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;posterior &amp;lt;- function(pars, x, y){
  
  l &amp;lt;- &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(pars[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;])
  sigma.n &amp;lt;- &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(pars[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;])
  
  cov &amp;lt;- function(X, Y) &lt;span class=&quot;kw&quot;&gt;outer&lt;/span&gt;(X, Y, SE, l)
  I &amp;lt;- &lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(x))
  K &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x, x) 
  
  loglik &amp;lt;- - &lt;span class=&quot;fl&quot;&gt;0.5&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(y) %*% &lt;span class=&quot;kw&quot;&gt;solve&lt;/span&gt;(K + sigma.n^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * I) %*% y -
    &lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;det&lt;/span&gt;(K + sigma.n^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;*I)) -
    &lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(y) * &lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * pi) / &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;

  loglik + &lt;span class=&quot;kw&quot;&gt;lpriors&lt;/span&gt;(pars)
}
  &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I do not think we have good conjugate priors we can use in this situation to accomplish Gibbs sampling. Instead we simply MCMC by the Metropolis-Hastings alogrithm,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(mcmc)
n &amp;lt;- &lt;span class=&quot;fl&quot;&gt;1e4&lt;/span&gt;
out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;metrop&lt;/span&gt;(posterior, &lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(pars), n, &lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; obs$x, &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; obs$y)
out$accept&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;[1] 0.1509&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Very good, we want an acceptance rate around 20%, if the literature can be trusted on this account. We then plot transformed and untransformed traces.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;postdist &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cbind&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;index=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:n, &lt;span class=&quot;kw&quot;&gt;as.data.frame&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(out$batch)))
&lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(postdist) &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;index&amp;quot;&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(pars))
df &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(postdist, &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;index&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;co&quot;&gt;# TRACES&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(df) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(index, value)) + &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~ variable, &lt;span class=&quot;dt&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ncol=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8395/8699032953_76e91621c7_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(df) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(index, &lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(value))) + &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~ variable, &lt;span class=&quot;dt&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ncol=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8265/8699033067_631d27e6f7_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;Generate a plot to compare priors and posteriors&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;d.p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;)
s2.p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;)  
   
s2_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, s2.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], s2.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;])
d_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, d.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; d.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;])
prior_fns &amp;lt;- &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;l =&lt;/span&gt; d_prior, &lt;span class=&quot;dt&quot;&gt;sigma.n =&lt;/span&gt; s2_prior)


&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(plyr)
prior_curves &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ddply&lt;/span&gt;(df, &lt;span class=&quot;st&quot;&gt;&amp;quot;variable&amp;quot;&lt;/span&gt;, function(dd){
    grid &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;min&lt;/span&gt;(dd$value), &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(dd$value), &lt;span class=&quot;dt&quot;&gt;length =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;)
    &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;value =&lt;/span&gt; grid, &lt;span class=&quot;dt&quot;&gt;density =&lt;/span&gt; prior_fns[[dd$variable[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]]](grid))
})

&lt;span class=&quot;co&quot;&gt;# Posteriors (easier to read than histograms)&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(df, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value)) + 
  &lt;span class=&quot;kw&quot;&gt;stat_density&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;geom=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;path&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;position=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;identity&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.7&lt;/span&gt;) +
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;prior_curves, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;value, &lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;density), &lt;span class=&quot;dt&quot;&gt;col=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;) + 
  &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~ variable, &lt;span class=&quot;dt&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ncol=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8405/8700155554_67aa26e564_o.png&quot; alt=&quot;Note that posteriors closely match our priors, as we have only 4 data points in this toy example and our priors are reasonably informative.&quot; /&gt;&lt;figcaption&gt;Note that posteriors closely match our priors, as we have only 4 data points in this toy example and our priors are reasonably informative.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;steve-chat&quot;&gt;Steve chat&lt;/h2&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;integrate over posteriors in GP case&lt;/li&gt;
&lt;li&gt;Ignore measurement uncertainty for the moment&lt;/li&gt;
&lt;li&gt;General status updates, etc.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;marc-meeting&quot;&gt;Marc meeting&lt;/h2&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;Ricker case, but with constraint (e.g. maintain above n%)&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Consider Ricker model with external management constraint $ (Y / Y_opt) + (1 - ) Pr(  )$&lt;/li&gt;
&lt;li&gt;Consider time horizon of learning vs implementing; see diagram&lt;/li&gt;
&lt;/ol&gt;
&lt;figure&gt;
&lt;img src=&quot;https://lh3.googleusercontent.com/-56MSu3YuJsI/UYFrPQmvR3I/AAAAAAAADYg/_fSPs0czpCA/w548-h731/IMG_20130501_122021.jpg&quot; /&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;simone-talk&quot;&gt;Simone talk&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;General interests: adaptive potential of small pops, demography of small pops, extinction processes in communities, evol life histories &amp;amp; enviroment, ML for species distribution models.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Marble trout system under the influence of regular catastrophic floods&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;misc&quot;&gt;Misc&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;6 hours on trains, 2 hours on buses, 1.25 hours on bicycle, 6 hours in lab.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Interesting reading in &lt;a href=&quot;http://www.wired.com/wiredenterprise/2012/04/openstack/&quot;&gt;The Secret History of OpenStack, the Free Cloud Software That’s Changing Everything&lt;/a&gt;. Sounds just like the unlikely collaboration we need to emerge for a more robust and sustainable underlying scientific infrastructure.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Finishing Comparison Parametric And Nonparametric</title>
   <link href="/2013/04/29/finishing-comparison-parametric-and-nonparametric.html"/>
   <updated>2013-04-29T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/29/finishing-comparison-parametric-and-nonparametric</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Implemented in &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/75df9413c016480f935867d88345ddaa36d07a82/inst/examples/BUGS/allen.md&quot;&gt;BUGS/allen.md&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;[x] Inverse gamma priors on variances &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/36888da01d7e36e58fc15c671e858be6fcf8a02d&quot;&gt;36888da&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;[x] Uniform prior on standard deviations &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/75df9413c016480f935867d88345ddaa36d07a82&quot;&gt;75df941&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;[x] Mean plot for parametric fit &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/75df9413c016480f935867d88345ddaa36d07a82&quot;&gt;75df941&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;[x] Convergence diagnostics for both parametric and nonparametric MCMC, using similar visual layout &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/75df9413c016480f935867d88345ddaa36d07a82&quot;&gt;75df941&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Oh, Jeromy Anglim has a rather nice collection of &lt;a href=&quot;http://jeromyanglim.blogspot.com/2012/04/getting-started-with-jags-rjags-and.html&quot;&gt;jags links&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;on-variance-priors-for-the-parametric-mcmc&quot;&gt;On Variance Priors for the Parametric MCMC&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Gelman recommends uniform priors on standard deviations for the noise terms: in the &lt;code&gt;.bugs&lt;/code&gt; file we have&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;stdQ ~ dunif(0,100)
stdR ~ dunif(0,100)
# as &amp;quot;precision&amp;quot; tau instead of stdev sigma
iQ &amp;lt;- 1/(stdQ*stdQ);
iR &amp;lt;- 1/(stdR*stdR);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Where these enter the model as&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;for(t in 1:(N-1)){
    mu[t] &amp;lt;- x[t] + exp(r0 * (1 - x[t]/K)* (x[t] - theta) )
      x[t+1] ~ dnorm(mu[t],iQ)
}


for(t in 1:(N)){
    y[t] ~ dnorm(x[t],iR)
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that &lt;code&gt;dnorm&lt;/code&gt; in JAGS notation is defined in terms of the mean and the precision (reciprocal of the variance), rather than standard deviation (e.g. in R’s &lt;code&gt;dnorm&lt;/code&gt; function), see the &lt;a href=&quot;http://ftp.iinet.net.au/pub/FreeBSD/distfiles/mcmc-jags/jags_user_manual.pdf&quot;&gt;JAGS manual&lt;/a&gt;, particularly Table 6.1 pg 29, below. Note that the standard deviation has the uniform prior, not the precision.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Also try inverse gamma priors,&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;iQ ~ dgamma(0.0001,0.0001)
iR ~ dgamma(0.0001,0.0001)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(Precision is Gamma distributed when the variances are inverse-gamma distributed.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Both are quite uniformative, results appear quite comparable.&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8119/8692697741_fa2dfb83b1_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;markov-chain-monte-carlo-convergence-analysis&quot;&gt;Markov Chain Monte Carlo Convergence Analysis&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Add for both parametric and non-parametric cases&lt;/li&gt;
&lt;li&gt;Extra long runs before finalizing analysis&lt;/li&gt;
&lt;li&gt;Some &lt;a href=&quot;http://www.people.fas.harvard.edu/~plam/teaching/methods/convergence/convergence_print.pdf&quot;&gt;examples&lt;/a&gt; with R code&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A variety of tools from &lt;code&gt;coda&lt;/code&gt; package. Of course these methods are designed from toy problems and cannot guarentee convergence.&lt;/p&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;Traceplots, density plots&lt;/li&gt;
&lt;li&gt;Running mean, autocorrelation plots &lt;code&gt;autocorr.plot&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Metropolis acceptance/rejection rate &lt;code&gt;rejectionRate&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Multiple chain diagonostics: Gelman-Rubin &lt;code&gt;gelman.diag&lt;/code&gt;, &lt;code&gt;gelman.plot&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Geweke (compare means between different sections) &lt;code&gt;geweke.diag&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Raferty-Lewis &lt;code&gt;raferty.diag&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Heidelberg and Welch &lt;code&gt;heidel.diag&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>A comparison of nonparametric Bayesian Gaussian process estimates to standard the parametric Bayesian approach</title>
   <link href="/2013/04/27/comparison-of-nonparametric-and-parametric-approaches.html"/>
   <updated>2013-04-27T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/27/comparison-of-nonparametric-and-parametric-approaches</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Load necessary libraries,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(pdgControl)  &lt;span class=&quot;co&quot;&gt;# custom SDP functions&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(nonparametricbayes)  &lt;span class=&quot;co&quot;&gt;# custom&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(reshape2)  &lt;span class=&quot;co&quot;&gt;# data manipulation&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(data.table)  &lt;span class=&quot;co&quot;&gt;# data manipulation&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(plyr)  &lt;span class=&quot;co&quot;&gt;# data manipulation&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(ggplot2)  &lt;span class=&quot;co&quot;&gt;# plotting&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(tgp)  &lt;span class=&quot;co&quot;&gt;# Gaussian Processes&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(MCMCpack)  &lt;span class=&quot;co&quot;&gt;# Markov Chain Monte Carlo tools&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(R2jags)  &lt;span class=&quot;co&quot;&gt;# Markov Chain Monte Carlo tools&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(emdbook)  &lt;span class=&quot;co&quot;&gt;# Markov Chain Monte Carlo tools&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(coda)  &lt;span class=&quot;co&quot;&gt;# Markov Chain Monte Carlo tools&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Plotting and knitr options, (can generally be ignored)&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(knitcitations)
opts_chunk$&lt;span class=&quot;kw&quot;&gt;set&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;tidy =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;warning =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;message =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;cache =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;)
opts_knit$&lt;span class=&quot;kw&quot;&gt;set&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;upload.fun =&lt;/span&gt; socialR::flickr.url)
&lt;span class=&quot;kw&quot;&gt;theme_set&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;theme_bw&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;base_size =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;))
&lt;span class=&quot;kw&quot;&gt;theme_update&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;panel.background =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;element_rect&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;fill =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;transparent&amp;quot;&lt;/span&gt;, 
    &lt;span class=&quot;dt&quot;&gt;colour =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;NA&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;plot.background =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;element_rect&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;fill =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;transparent&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;colour =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;NA&lt;/span&gt;))
cbPalette &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;#000000&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;#E69F00&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;#56B4E9&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;#009E73&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;#F0E442&amp;quot;&lt;/span&gt;, 
    &lt;span class=&quot;st&quot;&gt;&amp;quot;#0072B2&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;#D55E00&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;#CC79A7&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;model-and-parameters&quot;&gt;Model and parameters&lt;/h3&gt;
&lt;p&gt;Uses the model derived in Allen et al, of a Ricker-like growth curve with an allee effect, defined in the pdgControl package,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;f &amp;lt;- RickerAllee
p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;) 
K &amp;lt;- p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]
allee &amp;lt;- p[&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Various parameters defining noise dynamics, grid, and policy costs.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;sigma_g &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.05&lt;/span&gt;
sigma_m &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.0&lt;/span&gt;
z_g &amp;lt;- function() &lt;span class=&quot;kw&quot;&gt;rlnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, sigma_g)
z_m &amp;lt;- function() &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;+(&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;runif&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)-&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) * sigma_m
x_grid &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;1.5&lt;/span&gt; * K, &lt;span class=&quot;dt&quot;&gt;length=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;101&lt;/span&gt;)
h_grid &amp;lt;- x_grid
profit &amp;lt;- function(x,h) &lt;span class=&quot;kw&quot;&gt;pmin&lt;/span&gt;(x, h)
delta &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.01&lt;/span&gt;
OptTime &amp;lt;- &lt;span class=&quot;dv&quot;&gt;20&lt;/span&gt;  &lt;span class=&quot;co&quot;&gt;# stationarity with unstable models is tricky thing&lt;/span&gt;
reward &amp;lt;- &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;
xT &amp;lt;- &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;
seed_i &amp;lt;- &lt;span class=&quot;dv&quot;&gt;111&lt;/span&gt;
Xo &amp;lt;- K &lt;span class=&quot;co&quot;&gt;# observations start from&lt;/span&gt;
x0 &amp;lt;- Xo &lt;span class=&quot;co&quot;&gt;# simulation under policy starts from&lt;/span&gt;
Tobs &amp;lt;- &lt;span class=&quot;dv&quot;&gt;35&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;sample-data&quot;&gt;Sample Data&lt;/h3&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;obs &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sim_obs&lt;/span&gt;(Xo, z_g, f, p, &lt;span class=&quot;dt&quot;&gt;Tobs=&lt;/span&gt;Tobs, &lt;span class=&quot;dt&quot;&gt;nz=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;15&lt;/span&gt;, 
                &lt;span class=&quot;dt&quot;&gt;harvest =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;sort&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;rep&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, .&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;length=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;7&lt;/span&gt;), &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;)), &lt;span class=&quot;dt&quot;&gt;seed =&lt;/span&gt; seed_i)&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;maximum-likelihood&quot;&gt;Maximum Likelihood&lt;/h2&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;alt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;par_est&lt;/span&gt;(obs,  &lt;span class=&quot;dt&quot;&gt;init =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;r =&lt;/span&gt; p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], 
                              &lt;span class=&quot;dt&quot;&gt;K =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;mean&lt;/span&gt;(obs$x[obs$x&amp;gt;&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;]), 
                              &lt;span class=&quot;dt&quot;&gt;s =&lt;/span&gt; sigma_g))
est &amp;lt;- &lt;span class=&quot;kw&quot;&gt;par_est_allee&lt;/span&gt;(obs, f, p,  
                     &lt;span class=&quot;dt&quot;&gt;init =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;r =&lt;/span&gt; p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] + &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, 
                              &lt;span class=&quot;dt&quot;&gt;K =&lt;/span&gt; p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;] + &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, 
                              &lt;span class=&quot;dt&quot;&gt;C =&lt;/span&gt; p[&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;] + &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, 
                              &lt;span class=&quot;dt&quot;&gt;s =&lt;/span&gt; sigma_g))&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;non-parametric-bayes&quot;&gt;Non-parametric Bayes&lt;/h2&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;co&quot;&gt;#inv gamma has mean b / (a - 1) (assuming a&amp;gt;1) and variance b ^ 2 / ((a - 2) * (a - 1) ^ 2) (assuming a&amp;gt;2)&lt;/span&gt;
s2.p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;)  
tau2.p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)
d.p = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;)
nug.p = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;) &lt;span class=&quot;co&quot;&gt;# gamma mean&lt;/span&gt;
s2_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dinvgamma&lt;/span&gt;(x, s2.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], s2.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;])
tau2_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dinvgamma&lt;/span&gt;(x, tau2.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], tau2.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;])
d_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, d.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; d.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]) + &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, d.p[&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; d.p[&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;])
nug_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, nug.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; nug.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]) + &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, nug.p[&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; nug.p[&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;])
beta0_prior &amp;lt;- function(x, tau) &lt;span class=&quot;kw&quot;&gt;dnorm&lt;/span&gt;(x, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, tau)
beta = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)
priors &amp;lt;- &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;s2 =&lt;/span&gt; s2_prior, &lt;span class=&quot;dt&quot;&gt;tau2 =&lt;/span&gt; tau2_prior, &lt;span class=&quot;dt&quot;&gt;beta0 =&lt;/span&gt; dnorm, &lt;span class=&quot;dt&quot;&gt;nug =&lt;/span&gt; nug_prior, &lt;span class=&quot;dt&quot;&gt;d =&lt;/span&gt; d_prior, &lt;span class=&quot;dt&quot;&gt;ldetK =&lt;/span&gt; function(x) &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;  gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;bgp&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;X=&lt;/span&gt;obs$x, &lt;span class=&quot;dt&quot;&gt;XX=&lt;/span&gt;x_grid, &lt;span class=&quot;dt&quot;&gt;Z=&lt;/span&gt;obs$y, &lt;span class=&quot;dt&quot;&gt;verb=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,
          &lt;span class=&quot;dt&quot;&gt;meanfn=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;constant&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;bprior=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;b0&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;BTE=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;2000&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;20000&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;),
          &lt;span class=&quot;dt&quot;&gt;m0r1=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;corr=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;exp&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;trace=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;, 
          &lt;span class=&quot;dt&quot;&gt;beta =&lt;/span&gt; beta, &lt;span class=&quot;dt&quot;&gt;s2.p =&lt;/span&gt; s2.p, &lt;span class=&quot;dt&quot;&gt;d.p =&lt;/span&gt; d.p, &lt;span class=&quot;dt&quot;&gt;nug.p =&lt;/span&gt; nug.p, &lt;span class=&quot;dt&quot;&gt;tau2.p =&lt;/span&gt; tau2.p,
          &lt;span class=&quot;dt&quot;&gt;s2.lam =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;d.lam =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;nug.lam =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;tau2.lam =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;)      &lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;hyperparameters &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;index&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;s2&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;tau2&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;beta0&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;nug&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;d&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;ldetK&amp;quot;&lt;/span&gt;)
posteriors &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(gp$trace$XX[[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]][,hyperparameters], &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;index&amp;quot;&lt;/span&gt;)

&lt;span class=&quot;co&quot;&gt;# Traces &lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(posteriors) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(index, value)) + &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~ variable, &lt;span class=&quot;dt&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ncol=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8261/8685360238_353dbc5894_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-3&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-3&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;

prior_curves &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ddply&lt;/span&gt;(posteriors, &lt;span class=&quot;st&quot;&gt;&amp;quot;variable&amp;quot;&lt;/span&gt;, function(dd){
    grid &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;min&lt;/span&gt;(dd$value), &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(dd$value), &lt;span class=&quot;dt&quot;&gt;length =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;)
    &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;value =&lt;/span&gt; grid, &lt;span class=&quot;dt&quot;&gt;density =&lt;/span&gt; priors[[dd$variable[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]]](grid))
})

&lt;span class=&quot;co&quot;&gt;# &lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(posteriors) + &lt;span class=&quot;kw&quot;&gt;geom_histogram&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;value, &lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;..density..), &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.7&lt;/span&gt;) +
    &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;prior_curves, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;value, &lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;density), &lt;span class=&quot;dt&quot;&gt;col=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;lwd=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;) +
    &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~ variable, &lt;span class=&quot;dt&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8521/8685360484_e2ce943ebd_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-3&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-3&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(posteriors, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value)) + &lt;span class=&quot;kw&quot;&gt;stat_density&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;geom=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;path&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;position=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;identity&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.7&lt;/span&gt;) +
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;prior_curves, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;value, &lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;density), &lt;span class=&quot;dt&quot;&gt;col=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;) + 
  &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~ variable, &lt;span class=&quot;dt&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ncol=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8398/8685360552_d9ba680ff7_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-3&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-3&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h4 id=&quot;parametric-bayes&quot;&gt;Parametric Bayes&lt;/h4&gt;
&lt;p&gt;We initiate the MCMC chain (&lt;code&gt;init_p&lt;/code&gt;) using the true values of the parameters &lt;code&gt;p&lt;/code&gt; from the simulation. While impossible in real data, this gives the parametric Bayesian approach the best chance at succeeding. &lt;code&gt;y&lt;/code&gt; is the timeseries (recall &lt;code&gt;obs&lt;/code&gt; has the &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_t\inline&quot;/&gt;&lt;/span&gt;, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_{t+1}\inline&quot;/&gt;&lt;/span&gt; pairs)&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;co&quot;&gt;# a bit unfair to start with the correct values, but anyhow...&lt;/span&gt;
init_p = p
&lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(init_p) = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;r0&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;K&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;theta&amp;quot;&lt;/span&gt;)
y &amp;lt;- obs$y[-&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] 
N=&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(y);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We’ll be using the JAGS Gibbs sampler, a recent open source BUGS implementation with an R interface that works on most platforms. We initialize the usual MCMC parameters; see &lt;code&gt;?jags&lt;/code&gt; for details.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;jags.data &amp;lt;- &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;N&amp;quot;&lt;/span&gt;,&lt;span class=&quot;st&quot;&gt;&amp;quot;y&amp;quot;&lt;/span&gt;)
n.chains = &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;
n.iter = &lt;span class=&quot;dv&quot;&gt;20000&lt;/span&gt;
n.burnin = &lt;span class=&quot;kw&quot;&gt;floor&lt;/span&gt;(n.iter/&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)
n.thin = &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;floor&lt;/span&gt;(n.chains * (n.iter - n.burnin)/&lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The actual model is defined in a &lt;code&gt;model.file&lt;/code&gt; that contains an R function that is automatically translated into BUGS code by &lt;em&gt;R2WinBUGS&lt;/em&gt;. The file defines the priors and the model, as seen when read in here&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;cat&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;readLines&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;con=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;bugmodel-GammaPrior.txt&amp;quot;&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;sep=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## # Allen&amp;#39;s Allee model based on a Ricker
## 
## model{
## 
## # Define prior densities for parameters
## K     ~ dunif(1.0, 22000.0)
## logr0    ~ dunif(-4.0, 2.0)
## logtheta ~ dunif(-4.0, 2.0)
## iQ ~ dgamma(0.0001,0.0001)
## iR ~ dgamma(0.0001,0.0001)
## 
## # Transform parameters to fit in the model
## r0 &amp;lt;- exp(logr0)
## theta &amp;lt;- exp(logtheta)
## 
## # Initial state
## x[1] ~ dunif(0,10)
## 
## # Loop over all states, 
## for(t in 1:(N-1)){
##   mu[t] &amp;lt;- x[t] + exp(r0 * (1 - x[t] / K) * (x[t] - theta) )
##   x[t+1] ~ dnorm(mu[t],iQ)
## }
## 
## # Loop over all observations, 
## for(t in 1:(N)){
##   y[t] ~ dnorm(x[t],iR)
## }
## 
## }&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We define which parameters to keep track of, and set the initial values of parameters in the transformed space used by the MCMC. We use logarithms to maintain strictly positive values of parameters where appropriate. Because our priors on the noise parameters are inverse gamma distributed.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;jags.params=&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;K&amp;quot;&lt;/span&gt;,&lt;span class=&quot;st&quot;&gt;&amp;quot;logr0&amp;quot;&lt;/span&gt;,&lt;span class=&quot;st&quot;&gt;&amp;quot;logtheta&amp;quot;&lt;/span&gt;,&lt;span class=&quot;st&quot;&gt;&amp;quot;iR&amp;quot;&lt;/span&gt;,&lt;span class=&quot;st&quot;&gt;&amp;quot;iQ&amp;quot;&lt;/span&gt;) &lt;span class=&quot;co&quot;&gt;# Don&amp;#39;t need to save &amp;quot;x&amp;quot;&lt;/span&gt;
jags.inits &amp;lt;- function(){
  &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;K&amp;quot;&lt;/span&gt;=init_p[&lt;span class=&quot;st&quot;&gt;&amp;quot;K&amp;quot;&lt;/span&gt;],&lt;span class=&quot;st&quot;&gt;&amp;quot;logr0&amp;quot;&lt;/span&gt;=&lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(init_p[&lt;span class=&quot;st&quot;&gt;&amp;quot;r0&amp;quot;&lt;/span&gt;]),&lt;span class=&quot;st&quot;&gt;&amp;quot;logtheta&amp;quot;&lt;/span&gt;=&lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(init_p[&lt;span class=&quot;st&quot;&gt;&amp;quot;theta&amp;quot;&lt;/span&gt;]),&lt;span class=&quot;st&quot;&gt;&amp;quot;iQ&amp;quot;&lt;/span&gt;=&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.05&lt;/span&gt;,&lt;span class=&quot;st&quot;&gt;&amp;quot;iR&amp;quot;&lt;/span&gt;=&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;,&lt;span class=&quot;st&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;=y,&lt;span class=&quot;dt&quot;&gt;.RNG.name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;base::Wichmann-Hill&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;.RNG.seed=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;123&lt;/span&gt;)
}
&lt;span class=&quot;kw&quot;&gt;set.seed&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;12345&lt;/span&gt;)
time&amp;lt;-&lt;span class=&quot;kw&quot;&gt;system.time&lt;/span&gt;(       
  jagsfit &amp;lt;- &lt;span class=&quot;kw&quot;&gt;jags&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;jags.data, &lt;span class=&quot;dt&quot;&gt;inits=&lt;/span&gt;jags.inits, jags.params, &lt;span class=&quot;dt&quot;&gt;n.chains=&lt;/span&gt;n.chains, 
                  &lt;span class=&quot;dt&quot;&gt;n.iter=&lt;/span&gt;n.iter, &lt;span class=&quot;dt&quot;&gt;n.thin=&lt;/span&gt;n.thin, &lt;span class=&quot;dt&quot;&gt;n.burnin=&lt;/span&gt;n.burnin,&lt;span class=&quot;dt&quot;&gt;model.file=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;bugmodel-GammaPrior.txt&amp;quot;&lt;/span&gt;)
)         &lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Compiling model graph
##    Resolving undeclared variables
##    Allocating nodes
##    Graph Size: 394
## 
## Initializing model&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;time &amp;lt;- &lt;span class=&quot;kw&quot;&gt;unname&lt;/span&gt;(time[&lt;span class=&quot;st&quot;&gt;&amp;quot;elapsed&amp;quot;&lt;/span&gt;]);&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;convergence-diagnostics-for-parametric-bayes&quot;&gt;Convergence diagnostics for parametric bayes&lt;/h4&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;jags_matrix &amp;lt;- &lt;span class=&quot;kw&quot;&gt;as.data.frame&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;as.mcmc.bugs&lt;/span&gt;(jagsfit$BUGSoutput))
par_posteriors &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;cbind&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;index =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;kw&quot;&gt;dim&lt;/span&gt;(jags_matrix)[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], jags_matrix), &lt;span class=&quot;dt&quot;&gt;id =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;index&amp;quot;&lt;/span&gt;)

&lt;span class=&quot;co&quot;&gt;# Traces&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(par_posteriors) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(index, value)) + &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~ variable, &lt;span class=&quot;dt&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ncol=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8401/8684242957_c1958f5a03_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-8&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-8&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;
&lt;span class=&quot;co&quot;&gt;# posterior distributiosn&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(par_posteriors, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value)) + &lt;span class=&quot;kw&quot;&gt;stat_density&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;geom=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;path&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;position=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;identity&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.7&lt;/span&gt;) +
  &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~ variable, &lt;span class=&quot;dt&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ncol=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8255/8684243073_7a0daf0466_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-8&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-8&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;mcmc &amp;lt;- &lt;span class=&quot;kw&quot;&gt;as.mcmc&lt;/span&gt;(jagsfit)
mcmcall &amp;lt;- mcmc[,-&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]
who &amp;lt;- &lt;span class=&quot;kw&quot;&gt;colnames&lt;/span&gt;(mcmcall)
who &lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] &amp;quot;K&amp;quot;        &amp;quot;iQ&amp;quot;       &amp;quot;iR&amp;quot;       &amp;quot;logr0&amp;quot;    &amp;quot;logtheta&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;mcmcall &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cbind&lt;/span&gt;(mcmcall[,&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;],mcmcall[,&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;],mcmcall[,&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;],mcmcall[,&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;],mcmcall[,&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;])
&lt;span class=&quot;kw&quot;&gt;colnames&lt;/span&gt;(mcmcall) &amp;lt;- who&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;phase-space-diagram-of-the-expected-dynamics&quot;&gt;Phase-space diagram of the expected dynamics&lt;/h4&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;  &lt;span class=&quot;kw&quot;&gt;gp_plot&lt;/span&gt;(gp, f, p, est$f, est$p, alt$f, alt$p, x_grid, obs, seed_i)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8535/8684243227_41391fdd48_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-10&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-10&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;optimal-policies-by-value-iteration&quot;&gt;Optimal policies by value iteration&lt;/h2&gt;
&lt;p&gt;Compute the optimal policy under each model using stochastic dynamic programming.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;MaxT = &lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;
matrices_gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gp_transition_matrix&lt;/span&gt;(gp$ZZ.km, gp$ZZ.ks2, x_grid, h_grid)
opt_gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;value_iteration&lt;/span&gt;(matrices_gp, x_grid, h_grid, MaxT, xT, profit, delta, reward)

matrices_true &amp;lt;- &lt;span class=&quot;kw&quot;&gt;f_transition_matrix&lt;/span&gt;(f, p, x_grid, h_grid, sigma_g)
opt_true &amp;lt;- &lt;span class=&quot;kw&quot;&gt;value_iteration&lt;/span&gt;(matrices_true, x_grid, h_grid, &lt;span class=&quot;dt&quot;&gt;OptTime=&lt;/span&gt;MaxT, xT, profit, &lt;span class=&quot;dt&quot;&gt;delta=&lt;/span&gt;delta)

matrices_estimated &amp;lt;- &lt;span class=&quot;kw&quot;&gt;f_transition_matrix&lt;/span&gt;(est$f, est$p, x_grid, h_grid, est$sigma_g)
opt_estimated &amp;lt;- &lt;span class=&quot;kw&quot;&gt;value_iteration&lt;/span&gt;(matrices_estimated, x_grid, h_grid, &lt;span class=&quot;dt&quot;&gt;OptTime=&lt;/span&gt;MaxT, xT, profit, &lt;span class=&quot;dt&quot;&gt;delta=&lt;/span&gt;delta)

matrices_alt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;f_transition_matrix&lt;/span&gt;(alt$f, alt$p, x_grid, h_grid, alt$sigma_g)
opt_alt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;value_iteration&lt;/span&gt;(matrices_alt, x_grid, h_grid, &lt;span class=&quot;dt&quot;&gt;OptTime=&lt;/span&gt;MaxT, xT, profit, &lt;span class=&quot;dt&quot;&gt;delta=&lt;/span&gt;delta)


pardist &amp;lt;- mcmcall
pardist[,&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;] = &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(pardist[,&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;]) &lt;span class=&quot;co&quot;&gt;# transform model parameters back first&lt;/span&gt;
pardist[,&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;] = &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(pardist[,&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;])


matrices_par_bayes &amp;lt;- &lt;span class=&quot;kw&quot;&gt;parameter_uncertainty_SDP&lt;/span&gt;(f, p, x_grid, h_grid, pardist)
opt_par_bayes &amp;lt;- &lt;span class=&quot;kw&quot;&gt;value_iteration&lt;/span&gt;(matrices_par_bayes, x_grid, h_grid, &lt;span class=&quot;dt&quot;&gt;OptTime=&lt;/span&gt;MaxT, xT, profit, &lt;span class=&quot;dt&quot;&gt;delta=&lt;/span&gt;delta)


OPT = &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;GP =&lt;/span&gt; opt_gp$D, &lt;span class=&quot;dt&quot;&gt;True =&lt;/span&gt; opt_true$D, &lt;span class=&quot;dt&quot;&gt;MLE =&lt;/span&gt; opt_estimated$D, &lt;span class=&quot;dt&quot;&gt;Ricker.MLE =&lt;/span&gt; opt_alt$D, &lt;span class=&quot;dt&quot;&gt;Parametric.Bayes =&lt;/span&gt; opt_par_bayes$D)
colorkey=cbPalette
&lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(colorkey) = &lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(OPT) &lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;graph-of-the-optimal-policies&quot;&gt;Graph of the optimal policies&lt;/h2&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;policies &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;stock=&lt;/span&gt;x_grid, &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(OPT, function(x) x_grid[x])), &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;stock&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(policies) &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;stock&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;method&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;value&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(policies, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(stock, stock - value, &lt;span class=&quot;dt&quot;&gt;color=&lt;/span&gt;method)) +
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;lwd=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;1.2&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.8&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;xlab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;stock size&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;ylab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;escapement&amp;quot;&lt;/span&gt;)  +
  &lt;span class=&quot;kw&quot;&gt;scale_colour_manual&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;values=&lt;/span&gt;colorkey)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8542/8685372902_e8719a0c51_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-12&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-12&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;simulate-100-realizations-managed-under-each-of-the-policies&quot;&gt;Simulate 100 realizations managed under each of the policies&lt;/h2&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;

sims &amp;lt;- &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(OPT, function(D){
  &lt;span class=&quot;kw&quot;&gt;set.seed&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)
  &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;, function(i) 
    &lt;span class=&quot;kw&quot;&gt;ForwardSimulate&lt;/span&gt;(f, p, x_grid, h_grid, x0, D, z_g, &lt;span class=&quot;dt&quot;&gt;profit=&lt;/span&gt;profit, &lt;span class=&quot;dt&quot;&gt;OptTime=&lt;/span&gt;OptTime)
  )
})

  
dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(sims, &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(sims[[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]][[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]]))
dt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.table&lt;/span&gt;(dat)
&lt;span class=&quot;kw&quot;&gt;setnames&lt;/span&gt;(dt, &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;L1&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;L2&amp;quot;&lt;/span&gt;), &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;method&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;reps&amp;quot;&lt;/span&gt;)) 
&lt;span class=&quot;co&quot;&gt;# Legend in original ordering please, not alphabetical: &lt;/span&gt;
dt$method = &lt;span class=&quot;kw&quot;&gt;factor&lt;/span&gt;(dt$method, &lt;span class=&quot;dt&quot;&gt;ordered=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;levels=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(OPT))

&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dt) + 
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, fishstock, &lt;span class=&quot;dt&quot;&gt;group=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;interaction&lt;/span&gt;(reps,method), &lt;span class=&quot;dt&quot;&gt;color=&lt;/span&gt;method), &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;.&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) +
  &lt;span class=&quot;kw&quot;&gt;scale_colour_manual&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;values=&lt;/span&gt;colorkey, &lt;span class=&quot;dt&quot;&gt;guide =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;guide_legend&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;override.aes =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;alpha =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)))&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8400/8685373300_18931d5055_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-13&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-13&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dt) + 
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, harvest, &lt;span class=&quot;dt&quot;&gt;group=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;interaction&lt;/span&gt;(reps,method), &lt;span class=&quot;dt&quot;&gt;color=&lt;/span&gt;method), &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;.&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) +
  &lt;span class=&quot;kw&quot;&gt;scale_colour_manual&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;values=&lt;/span&gt;colorkey, &lt;span class=&quot;dt&quot;&gt;guide =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;guide_legend&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;override.aes =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;alpha =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)))&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8535/8685373378_da45da3cbd_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-13&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-13&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;  &lt;/code&gt;&lt;/pre&gt;
</content>
 </entry>
 
 <entry>
   <title>Notebook features: reproducible code</title>
   <link href="/2013/04/26/notebook-features-reproducible-code.html"/>
   <updated>2013-04-26T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/26/notebook-features-reproducible-code</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;I now use the dynamic documentation software called &lt;a href=&quot;http://yihui.name/knitr&quot;&gt;knitr&lt;/a&gt; to write most entries that shore results and figures. The code to replicate the results is included automatically, ensuring that what I say I did and what code I actually ran to get the results are consistent. Though I have written about knitr before, both regarding its &lt;a href=&quot;http://carlboettiger.info/2012/03/21/knitr-github-and-a-new-phase-for-the-lab-notebook.html&quot;&gt;use in my notebook&lt;/a&gt; and &lt;a href=&quot;http://carlboettiger.info/2012/04/07/writing-reproducibly-in-the-open-with-knitr.html&quot;&gt;in my manuscripts&lt;/a&gt;, here I provide a quick summary of how a reader might actually reproduce a figure or result they come across in the notebook, as well as some of the possible problems involved.&lt;/p&gt;
&lt;p&gt;As the code required for any given analysis can be quite involved, it is not pratical to provide free-standing scripts in this way. Instead, I write the algorithms as functions provided by an R package dedicated to the project, e.g. &lt;a href=&quot;http://github.com/cboettig/nonparametric-bayes&quot;&gt;nonparametric-bayes&lt;/a&gt;, &lt;a href=&quot;http://github.com/cboettig/multiple_uncertainty&quot;&gt;multiple-uncertainty&lt;/a&gt;, or &lt;a href=&quot;http://github.com/cboettig/earlywarning&quot;&gt;warning-signals&lt;/a&gt;, which is version-managed on Github. The code displayed in the post can then be limited to the specific calls to analysis, data manipulation, and plotting functions unique to the exploration shown, without repeating the code for all algorithms involved.&lt;/p&gt;
&lt;p&gt;The code for the analyses is also stored on github using the same dynamic documentation approach with knitr. These scripts are found in the &lt;code&gt;inst/examples&lt;/code&gt; directory of my packages. This approach allows a given analysis to evolve with my research in a more tractable way than simply pasting updated copies as successive notebook entries. The notebook entries then become a place for me to synthesize the results of a script.&lt;/p&gt;
&lt;p&gt;Though the package functions are usually backwards-compatible, proper reproducibility is only attained by having the version of the package from time of the result. This is easily accomplished by the seemless integration of Github and R using the devtools package. Consider a figure from a page of the notebook, such as the final histogram plot from &lt;a href=&quot;http://www.carlboettiger.info/2012/12/20/results-comparing-gp-to-parametric.html&quot;&gt;this entry&lt;/a&gt;. The entry links to the script responsible for the figure, &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/9d5cd1f027bdfe5f356dce83756726c95a6fcdd8/inst/examples/myers-exploration.md&quot;&gt;https://github.com/cboettig/nonparametric-bayes/blob/9d5cd1f027bdfe5f356dce83756726c95a6fcdd8/inst/examples/myers-exploration.md&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We can install the entire research compendium at exactly the state it was at the time of the analysis using the hash (long chain of seemingly random characters, see the (upcoming) entry on &lt;a href=&quot;&quot;&gt;hashes&lt;/a&gt;) using the clever &lt;code&gt;devtools&lt;/code&gt; R package,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;install_github&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;nonparametric-bayes&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;cboettig&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;9d5cd1f027bdfe5f356dce83756726c95a6fcdd8&amp;quot;&lt;/span&gt;) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can then copy and paste the code linked from the figure to replicate the results. This provides a fast and effective way replicate the work appearing in or linked to any entry. More importantly perhaps, this approach also allows one to repeat any given analysis with the most recent version of an algorithm and compare the results, since the package structure provides a logical seperation between algorithm and analysis. In practice such fine-grained control and invistigation is more important than simply being able to regenerate what has already been done without any further input.&lt;/p&gt;
&lt;p&gt;This is not entirely failsafe. The package may depend on other packages, which themselves may have changed. For my use cases, it is a deal more reliable than running the current version of a package that is actively changing during my research. Readers interested in even more robust replication and verification should take a look at Roger Peng’s package &lt;code&gt;stashR&lt;/code&gt; package and associated publications &lt;span class=&quot;showtooltip&quot; data-html=&quot;true&quot; title=&quot;&lt;p&gt;Eckel S and Peng RD (2012). stashR: A Set of Tools for Administering SHared Repositories. R package version 0.3-5.&amp;quot;&amp;gt;&lt;a href=&quot;http://CRAN.R-project.org/package=stashR&quot;&gt;Eckel &amp;amp; Peng (2012)&lt;/a&gt;&lt;/span&gt; .&lt;/p&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Sandy Eckel, Roger Peng, (2012) stashR: A Set of Tools for Administering SHared Repositories. &lt;a href=&quot;http://CRAN.R-project.org/package=stashR&quot;&gt;http://CRAN.R-project.org/package=stashR&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notebook features: an introduction</title>
   <link href="/2013/04/26/notebook-features-introduction.html"/>
   <updated>2013-04-26T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/26/notebook-features-introduction</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;In keeping this open lab notebook, I have sought to address three goals (in addition to all the traditional reasons for keeping a lab notebook)&lt;/p&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;Provide an educational resource&lt;/li&gt;
&lt;li&gt;Experiment with scientific infrastructure and tools for sharing and replicating research&lt;/li&gt;
&lt;li&gt;Facilitate the rapid and open dissemination of scientific research&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;which are coincidentally evocative of &lt;a href=&quot;http://www.nsf.gov/pubs/2007/nsf07046/nsf07046.jsp&quot;&gt;NSF’s Broader Impacts&lt;/a&gt; areas. In this series of posts I plan to explore and illustrate some of my experiments to address these goals through various web-based tools available for an open notebook platform. Many of these have been documented in the notebook itself as I experiment with them (see &lt;a href=&quot;http://www.carlboettiger.info/tags.html#notebook-technology&quot;&gt;#notebook-technology&lt;/a&gt;). Not all of those experiments pan out and older tools and techniques are often replaced with newer ones as I explore, and these posts are usually more technical notes written to help me think through and remember what I’m trying out. In order to provide a more accessible snapshot of notebook features, I thought it might be helpful to write a series of posts describing these tools and techniques.&lt;/p&gt;
&lt;p&gt;Below is an index of posts in this theme that I will continue to update as I have a chance to finish them. If there’s anything about the notebook that you’d like to hear more about, feel free to suggest it in the comments.&lt;/p&gt;
&lt;h3 id=&quot;written&quot;&gt;Written&lt;/h3&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;&lt;a href=&quot;http://carlboettiger.info/2013/04/26/notebook-features-reproducible-code.html&quot;&gt;Reproducible code: embedding code and dynamic documents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://carlboettiger.info/2013/04/04/notebook-parsing.html&quot;&gt;Parsing linked data in the semantic notebook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://carlboettiger.info/2013/05/03/notebook-features-hashes-providing-an-immutable-and-verifiable-research-record.html&quot;&gt;Hashes: An immutable and verifiable record of research&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;planned&quot;&gt;Planned&lt;/h3&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;&lt;a href=&quot;&quot;&gt;Digital archiving&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;&quot;&gt;Readable, multi-device typography&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;&quot;&gt;Notebook analytics: Who reads this stuff anyway?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;&quot;&gt;A fast, inexpensive, and scalable online platform&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;&quot;&gt;Online notebook essentials: link, tag, search&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;&quot;&gt;Integrating social networks with the notebook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;…&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/04/25/notes.html"/>
   <updated>2013-04-25T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/25/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;ul&gt;
&lt;li&gt;finish pmc post from Tuesday (done).&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Submit comment reply (done).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;nonparametric-bayes&quot;&gt;Nonparametric-bayes&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Finishing up parametric vs nonparametric Bayes comparison runs&lt;/li&gt;
&lt;li&gt;Need to add parametric Bayesian mean to the state-space diagram, fig 1&lt;/li&gt;
&lt;li&gt;Compare with uniform priors on inverse standard deviations (precision)&lt;/li&gt;
&lt;li&gt;Sensitivity analysis&lt;/li&gt;
&lt;li&gt;mcmc convergence analysis for both Bayesian approaches&lt;/li&gt;
&lt;li&gt;See allen.md example scripts in BUGS/, adapted to post soon&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;code-tricks&quot;&gt;Code tricks&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Plotting tricks&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Selecting the order in the simulation legend requires declaring the model types as an ordered factor instead of a character,&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;dt$method = &lt;span class=&quot;kw&quot;&gt;factor&lt;/span&gt;(dt$method, &lt;span class=&quot;dt&quot;&gt;ordered=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;levels=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(OPT))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and then set custom colors and match colors to the desired factor labels with &lt;code&gt;scale_colour_manual&lt;/code&gt;, and override &lt;code&gt;alpha&lt;/code&gt; for legends,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dt) + 
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, fishstock, &lt;span class=&quot;dt&quot;&gt;group=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;interaction&lt;/span&gt;(reps,method), &lt;span class=&quot;dt&quot;&gt;color=&lt;/span&gt;method), &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;.&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) +
    &lt;span class=&quot;kw&quot;&gt;scale_colour_manual&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;values=&lt;/span&gt;colorkey, &lt;span class=&quot;dt&quot;&gt;guide =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;guide_legend&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;override.aes =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;alpha =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)))&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Avoid having density plots appear as crude polygons using &lt;code&gt;stat_density&lt;/code&gt; instead of &lt;code&gt;geom_density&lt;/code&gt; and set &lt;code&gt;geom&lt;/code&gt; to path. Need a ymax (not clear why?) or set &lt;code&gt;position=&amp;quot;identity&amp;quot;&lt;/code&gt; as shown,:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(posteriors, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value)) + &lt;span class=&quot;kw&quot;&gt;stat_density&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;geom=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;path&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;position=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;identity&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.7&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://gist.github.com/bluegraybox/1998129&quot;&gt;initialize ssh-agent in .bashrc&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Or for single session: &lt;code&gt;ssh-agent bash&lt;/code&gt;, &lt;code&gt;ssh-add ~/.ssh/id_rda&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;misc&quot;&gt;Misc&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;whoops, got into discussion of a fictional world of data publishing in the &lt;a href=&quot;http://dynamicecology.wordpress.com/2013/04/08/selective-journals-vs-social-networks-alternative-ways-of-filtering-the-literature-or-po-tay-to-po-tah-to/#comment-15439&quot;&gt;comments at dynamicecology&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Speaking of &lt;a href=&quot;http://dynamicecology.wordpress.com/2013/04/16/prioritizing-manuscripts-and-having-data-go-unpublished-for-lack-of-time&quot;&gt;data publishing issues on dynamicecology&lt;/a&gt;…&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Empirical Demonstration Of That Clever Derivation</title>
   <link href="/2013/04/24/empirical-demonstration-of-that-clever-derivation.html"/>
   <updated>2013-04-24T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/24/empirical-demonstration-of-that-clever-derivation</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Another unexpected gem from keeping an online notebook: Empirical evidence for the expected escape time problem! Getting to that in a moment….&lt;/p&gt;
&lt;p&gt;After Marc pointed out to me that there is a clever analytic demonstration to back my claims about realized exit times being fast (posted earlier in my notebook under the title, &lt;a href=&quot;http://carlboettiger.info/2013/04/05/a-clever-derivation-on-realized-escape-times.html&quot;&gt;a clever derivation of realized escape times&lt;/a&gt;, I’ve enjoyed a bit of a tangent in understanding this result that has long since been worked out by mathematicians but appears to be periodically rediscovered in ecological and evolutionary work in the most delightful ways.&lt;/p&gt;
&lt;p&gt;For instance, &lt;span class=&quot;showtooltip&quot; data-html=&quot;true&quot; title=&quot;Lande R (1985). &amp;ldquo;Expected time for random genetic drift of a population between stable phenotypic states.&amp;rdquo; .&quot;&gt;&lt;a href=&quot;http://www.pnas.org/content/82/22/7641.short&quot; rel=&quot;http://purl.org/spar/cito/citesAsEvidence&quot; &gt;Lande (1985)&lt;/a&gt;&lt;/span&gt; shows how this result can explain a pattern of punctuated equilibrium, such as sudden rapid jumps such as illustrated below in a simulation example from &lt;a href=&quot;http://www.amazon.com/Perturbations-Dynamical-Grundlehren-mathematischen-Wissenschaften/dp/0387983627&quot; rel=&quot;http://purl.org/spar/cito/citesAsAuthority&quot; &gt;Freidlin &lt;em&gt;et. al.&lt;/em&gt; (1998)&lt;/a&gt;, need not result from some external process but are in fact the most likely trajectories to be seen in a purely stochastic transition.&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8258/8684251521_124e51b5d3_o.png&quot; alt=&quot;from Mangel 2006, Theoretical Biologist’s toolbox&quot; /&gt;&lt;figcaption&gt;from Mangel 2006, Theoretical Biologist’s toolbox&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Ludwig (1975) considered this result in a more ecological context, addressing a variety of questions about persistence and coexistence that are naturally represented as hitting time problems as well. Note that the this result is interesting precisely in its contrast from the more familiar hitting time problems in that we focus on the time the realized trajectory actually takes to exit, rather than the waiting time until that exit occurs (e.g. the frequency of the transtions shown in the figure above).&lt;/p&gt;
&lt;p&gt;These examples appear to be rediscoveries of particular cases that result more generally from the large deviation theory of Fiedlin and Wentzell, which states that the most likely path can be found by minimizing a variation equation (Hamiltonian, analgous to the minimizing action along paths in classical mechanics or the optimization under constraint of Jacobi-Bellman). For a system of discrete steps (e.g. births and deaths) in one dimension this is particularly trivial: the most likely path is the monotonic one (this should be easy to see by considering the likelihood of &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?N\inline&quot;/&gt;&lt;/span&gt; death events occuring in sequence vs that of &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?N-1\inline&quot;/&gt;&lt;/span&gt; death events interrupted by 1 birth and followed by 2 deaths.)&lt;/p&gt;
&lt;h2 id=&quot;empirical-demonstrations&quot;&gt;Empirical demonstrations?&lt;/h2&gt;
&lt;p&gt;Then an email to me earlier this week pointed out that perhaps an example of the phenomenon I discussed there had been demonstrated in &lt;span class=&quot;showtooltip&quot; data-html=&quot;true&quot; title=&quot;Drake J and Griffen B (2009). &amp;ldquo;Speed of Expansion And Extinction in Experimental Populations.&amp;rdquo; Ecology Letters, 12, pp. 772&amp;ndash;778. ISSN 1461023X.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1111/j.1461-0248.2009.01325.x&quot; rel=&quot;http://purl.org/spar/cito/citesAsEvidence&quot; &gt;Drake &amp;amp; Griffen (2009)&lt;/a&gt;&lt;/span&gt; :&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A testable, counter-intuitive prediction of stochastic population theory is that, on average, for any interior interval of the domain of biologically attainable population sizes, the expected duration of increase equals the expected duration of decline. Here we report the first empirical tests of this hypothesis.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I do feel that this is an overstatement of the stochastic theory as I understand it – these times should only scale in a similar way, but can differ by an arbitrary coefficient. Indeed it is often the goal of the deviation theory analysis to determine this coefficent, see &lt;span class=&quot;showtooltip&quot; data-html=&quot;true&quot; title=&quot;Faure M and Schreiber SJ (2011). &amp;ldquo;Quasi-Stationary distributions for Randomly perturbed dynamical systems.&amp;rdquo; .&quot;&gt;&lt;a href=&quot;http://arxiv.org/abs/1101.3420&quot; rel=&quot;http://purl.org/spar/cito/citesAsAuthority&quot; &gt;Faure &amp;amp; Schreiber (2011)&lt;/a&gt;&lt;/span&gt; . The authors seem quite concerned that theory they refer to applies to continuously valued diffusion processes alone, whereas I’m quite certain the more general results of the deviation theory hold just as well in discrete systems. (Perhaps this explains why they do not confirm this prediction in some subset of the data). Nevertheless, the context is the same as we consider – comparing the return time to a stable point from some small population size with the time required to decline from that point to a small size, as clearly indicated in Figure 1 of the manuscript.&lt;/p&gt;
&lt;p&gt;Commendably, the authors make the data and code available (as an R script and .Rdata file). (According to the manuscript, this data is at &lt;a href=&quot;http://dragonfly.ecology.uga.edu/drakelab/data.html&quot;&gt;http://dragonfly.ecology.uga.edu/drakelab/data.html&lt;/a&gt;, but in an example of link rot and the risk of independent archiving the lab prefers daphnia to dragonfly, and the data can now be found: &lt;a href=&quot;http://daphnia.ecology.uga.edu/drakelab/datapage.html&quot;&gt;http://daphnia.ecology.uga.edu/drakelab/datapage.html&lt;/a&gt;). These data draw on work from earlier experiments that provide some of the nicest sources of time series leading up to stochastic extinctions. Unfortunately it appears that only the duration of growth and extinction times for the replicates are shown in the data provided for this paper, I don’t see the actual timeseries themselves (which would be interesting to look at more closely).&lt;/p&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;John M. Drake, Blaine D. Griffen, (2009) Speed of Expansion And Extinction in Experimental Populations. &lt;em&gt;Ecology Letters&lt;/em&gt; &lt;strong&gt;12&lt;/strong&gt; 772-778 &lt;a href=&quot;http://dx.doi.org/10.1111/j.1461-0248.2009.01325.x&quot;&gt;10.1111/j.1461-0248.2009.01325.x&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Mark Freidlin, Alexander Wentzell, (1998) {Random Perturbations of Dynamical Systems (Grundlehren der mathematischen Wissenschaften)}. 429-NA &lt;a href=&quot;http://www.amazon.com/Perturbations-Dynamical-Grundlehren-mathematischen-Wissenschaften/dp/0387983627&quot;&gt;http://www.amazon.com/Perturbations-Dynamical-Grundlehren-mathematischen-Wissenschaften/dp/0387983627&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;R Lande, (1985) Expected time for random genetic drift of a population between stable phenotypic states. &lt;em&gt;Proceedings of the National Academy of Sciences&lt;/em&gt; &lt;a href=&quot;http://www.pnas.org/content/82/22/7641.short&quot;&gt;http://www.pnas.org/content/82/22/7641.short&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Mathieu Faure, Sebastian Schreiber, (2011) Quasi-Stationary distributions for Randomly perturbed dynamical systems. &lt;em&gt;arXiv.org&lt;/em&gt; &lt;a href=&quot;http://arxiv.org/abs/1101.3420&quot;&gt;http://arxiv.org/abs/1101.3420&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>We Need More Object Oriented Design In Comparative Methods</title>
   <link href="/2013/04/23/we-need-more-object-oriented-design-in-comparative-methods.html"/>
   <updated>2013-04-23T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/23/we-need-more-object-oriented-design-in-comparative-methods</id>
    
   <category term="//categories.html#evolution" label="evolution"/>
   
   <content type="html">&lt;p&gt;The bad news is that the latest &lt;a href=&quot;http://cran.r-project.org/web/packages/geiger/index.html&quot;&gt;Geiger&lt;/a&gt; version (which is much improved in all respects) breaks my little &lt;a href=&quot;http://cran.r-project.org/web/packages/pmc/index.html&quot;&gt;pmc&lt;/a&gt; package, owing to changes in how &lt;code&gt;fitContinuous&lt;/code&gt; output is structured. The good news is that the new geiger is much better than the old one, and that the pmc package is pretty trivial. So this should not be read as a complaint, but I think as a scientific developer community as a whole we could learn a few simple lessons here, which can help our code more reproducible and extensible.&lt;/p&gt;
&lt;p&gt;Functions define the API, or &lt;a href=&quot;http://en.wikipedia.org/wiki/Application_programming_interface&quot;&gt;application programming interface&lt;/a&gt;, of a package. Once a package has been released, developers are usually hesitant to change how a function call is made – what arguments it takes or what order they come in, since this would break any existing code. For the most part, the update is a good example of that, with minor exceptions – (for instance, a data.frame used to be a valid input to the &lt;code&gt;fitContinuous&lt;/code&gt; &lt;code&gt;dat&lt;/code&gt; argument, but now it must be a matrix). More problematic is the lack of an API in the original version of package for handling output objects. If you wanted to access the estimated value of the parameter &lt;code&gt;lambda&lt;/code&gt; after running &lt;code&gt;fit &amp;lt;- fitContinuous(phy, dat, model=&amp;quot;lambda&amp;quot;, ...)&lt;/code&gt;, you would have needed to use &lt;code&gt;fit[[1]]$lambda&lt;/code&gt;. Under the newer version of this function, such a call won’t work. Any code written to use the output of that function will not work either.&lt;/p&gt;
&lt;p&gt;To avoid this kind of problem in the future, Jon has written the function &lt;code&gt;coef&lt;/code&gt; which will extract the coefficients from the fit. For anyone starting to write packages, writing and using such extraction functions seems like an unnecessary hassle – after all it is often no faster to call the additional function than to just pull the data out of the return object yourself. But there is good reason to implement and use such methods. By drawing the data out using a function, it is possible to change the internal structure of the output without breaking the package API; without breaking code that depends on the package. In future, the &lt;code&gt;coef&lt;/code&gt; function can just be similarly updated to point to the correct location for the model coefficients.&lt;/p&gt;
&lt;p&gt;Better than providing just any function, the new &lt;code&gt;coef&lt;/code&gt; and &lt;code&gt;logLik&lt;/code&gt; functions are generic methods that can act on a wide range of model fits in R that return coefficients or log likelihoods. Just type &lt;code&gt;methods(&amp;quot;coef&amp;quot;)&lt;/code&gt; in your R terminal after loading your commonly used libraries to see how many of them define such a function. Following the basic principle of object-oriented design, these generic function calls identify the class of object they are given, and figure out what method to use on that class. For instance, the list of stuff returned by &lt;code&gt;fitContinous&lt;/code&gt; now has class &lt;code&gt;gcfit&lt;/code&gt;, and a function &lt;code&gt;coef.gcfit&lt;/code&gt; which the generic function &lt;code&gt;coef&lt;/code&gt; uses to know where to find the coefficients in a &lt;code&gt;gcfit&lt;/code&gt; object. Generic functions are particularly nice, since they allow us to write code that can deal with a wide variety of statistical fits without needing to know just how to perform those tasks. The pmc algorithm is a good example of this. Using the generics &lt;code&gt;simulate&lt;/code&gt;, &lt;code&gt;update&lt;/code&gt;, and &lt;code&gt;logLik&lt;/code&gt;, we can write the algorithm as:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;## Fit the original data using a function that returns an intelligent object &amp;quot;fit&amp;quot; which has methods &amp;quot;simulate&amp;quot;, &amp;quot;update&amp;quot;, and &amp;quot;logLik&amp;quot;
fit_A &amp;lt;- &lt;span class=&quot;kw&quot;&gt;my_fitting_function&lt;/span&gt;(data, phy, model_pars_A, fitting_pars ...)
fit_B &amp;lt;- &lt;span class=&quot;kw&quot;&gt;another_fitting_function&lt;/span&gt;(data, phy, model_pars_B, fitting_pars ...)

orig_LL &amp;lt;- &lt;span class=&quot;kw&quot;&gt;logLik&lt;/span&gt;(fit_B) - &lt;span class=&quot;kw&quot;&gt;logLik&lt;/span&gt;(fit_A)

## 1000 Simulations under each model
A_sims &amp;lt;- &lt;span class=&quot;kw&quot;&gt;simulate&lt;/span&gt;(fit_A, &lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;)
B_sims &amp;lt;- &lt;span class=&quot;kw&quot;&gt;simulate&lt;/span&gt;(fit_B, &lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;)

## here are the four fits
AA &amp;lt;- &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(A_sims, fit_A, update)
AB &amp;lt;- &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(A_sims, fit_B, update)
BA &amp;lt;- &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(B_sims, fit_A, update)
BB &amp;lt;- &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(B_sims, fit_B, update)

## which create 2 distributions
null_dist = &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(AB, logLik) - &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(AA, logLik)
test_dist = &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(BB, logLik) - &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(BA, logLik)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;in which the exact same code could be used regardless of whether &lt;code&gt;my_fitting_function&lt;/code&gt; was &lt;code&gt;brownie.lite&lt;/code&gt;, &lt;code&gt;fitContinuous&lt;/code&gt;, &lt;code&gt;fitDiscrete&lt;/code&gt;, &lt;code&gt;hansen&lt;/code&gt;, &lt;code&gt;OUwie&lt;/code&gt;, any of the laser fns, etc etc, and &lt;code&gt;another_fitting_function&lt;/code&gt; could be the same call with different parameters (e.g. call to &lt;code&gt;hansen&lt;/code&gt; with a different painting) or a call to some other function entirely (e.g. &lt;code&gt;brownie.lite&lt;/code&gt;). Instead, &lt;code&gt;OUCH&lt;/code&gt; is the only one that does this, and it insists on using a different format for “data” and “phy” which makes it annoying to have it play nicely with other fitting routines.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;pmc&lt;/code&gt; package simply writes wrappers that will provide these generic methods to some of these functions. Because different packages (e.g. ouch, geiger) handle data differently, the wrappers must also be able to convert back and forth between these formats if we want to compare methods across different packages in this way. Though straight forward, it is not good practice to have the methods such as &lt;code&gt;simulate&lt;/code&gt; and &lt;code&gt;update&lt;/code&gt; provided in a different package than the actual fitting routines, but the number of package fitting methods continues to grow and I haven’t persuaded anyone to consider including such routines. With my postdoctoral work outside the area of phylogenetics, updating pmc each time is impractical. If packages provided such generic routines, code such as the above would work out of the box without the need for a specialized &lt;code&gt;pmc&lt;/code&gt; package, which appears to make this very intuitive technique more opaque then necessary.&lt;/p&gt;
&lt;p&gt;There are many other good statistical tests that could benefit from such methods (particularly simulation methods which could assist in many ways). I hope one day they may be more popular in our phylogenetics community.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Bayesian Parametric Uncertainty Sdp</title>
   <link href="/2013/04/19/bayesian-parametric-uncertainty-sdp.html"/>
   <updated>2013-04-19T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/19/bayesian-parametric-uncertainty-sdp</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Adapting the parametric uncertainty represented by the posterior distributions of the Bayesian estimate (see &lt;a href=&quot;http://carlboettiger.info/2013/04/12/parametric-bayesian-example.html&quot;&gt;earlier notes&lt;/a&gt;) to the stochastic dynamic programming solution for the optimal policy. Simply requires evaluating the expectation over the distribution, but is computationally intensive given the spread and the three parameters.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;f_transition_matrix &amp;lt;- function(f, p, x_grid, h_grid, sigma_g, pardist){
  &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(h_grid, par_F, f, p, x_grid, sigma_g, pardist)
}


par_F &amp;lt;- function(h, f, p, x_grid, sigma_g, pardist, &lt;span class=&quot;dt&quot;&gt;n_mc =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;){
  
  &lt;span class=&quot;co&quot;&gt;# Set up monte carlo sampling &lt;/span&gt;
  d &amp;lt;- &lt;span class=&quot;kw&quot;&gt;dim&lt;/span&gt;(pardist)
  indices &amp;lt;- &lt;span class=&quot;kw&quot;&gt;round&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;runif&lt;/span&gt;(n_mc,&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, d[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]))
  
  &lt;span class=&quot;co&quot;&gt;# Compute the matrix&lt;/span&gt;
  F_true &amp;lt;- 
    &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(x_grid, function(x_t){           &lt;span class=&quot;co&quot;&gt;# For each x_t  &lt;/span&gt;

      bypar &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(indices, function(i){ &lt;span class=&quot;co&quot;&gt;# For each parameter value&lt;/span&gt;
        p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;unname&lt;/span&gt;(pardist[i,&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;)])    &lt;span class=&quot;co&quot;&gt;# parameters for the mean, at current sample &lt;/span&gt;
        mu &amp;lt;- &lt;span class=&quot;kw&quot;&gt;f&lt;/span&gt;(x_t,h,p)
        est_sigma_g &amp;lt;- pardist[i,&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]         &lt;span class=&quot;co&quot;&gt;# Variance parameter &lt;/span&gt;

        if(&lt;span class=&quot;kw&quot;&gt;snap_to_grid&lt;/span&gt;(mu,x_grid) &amp;lt; x_grid[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]){ &lt;span class=&quot;co&quot;&gt;# handle the degenerate case &lt;/span&gt;
          out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;numeric&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(x_grid))
          out[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;
          out
        } else {
          out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;dlnorm&lt;/span&gt;(x_grid/mu, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, est_sigma_g) 
        }
      })  
      ave_over_pars &amp;lt;- &lt;span class=&quot;kw&quot;&gt;apply&lt;/span&gt;(bypar, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, sum) &lt;span class=&quot;co&quot;&gt;# collapse by weighted average over possible parameters    &lt;/span&gt;
      ave_over_pars / &lt;span class=&quot;kw&quot;&gt;sum&lt;/span&gt;(ave_over_pars)
      })
  F_true &amp;lt;- &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(F_true)
        
}


snap_to_grid &amp;lt;- function(x, grid) &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(x, function(x) grid[&lt;span class=&quot;kw&quot;&gt;which.min&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;abs&lt;/span&gt;(grid - x))])   


&lt;span class=&quot;co&quot;&gt;# internal helper function&lt;/span&gt;
rownorm &amp;lt;- function(M) 
  &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;apply&lt;/span&gt;(M, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, function(x){ 
    if(&lt;span class=&quot;kw&quot;&gt;sum&lt;/span&gt;(x)&amp;gt;&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;){
      x/&lt;span class=&quot;kw&quot;&gt;sum&lt;/span&gt;(x)
    } else {
      out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;numeric&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(x))
      out[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;
      out
    }
  }))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run the Bayesian analysis to obtain posterior distributions for parameters.&lt;/p&gt;
&lt;h2 id=&quot;test-case-using-perturbed-parameters&quot;&gt;Test case using perturbed parameters&lt;/h2&gt;
&lt;p&gt;First, sanity test. Use the correct parameter values (slightly perturbed).&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;pardist &amp;lt;- mcmcall
pardist[,&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] = p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;] + &lt;span class=&quot;kw&quot;&gt;rnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.000001&lt;/span&gt;)
pardist[,&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;] = p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] + &lt;span class=&quot;kw&quot;&gt;rnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.000001&lt;/span&gt;)
pardist[,&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;] = sigma_g + &lt;span class=&quot;kw&quot;&gt;rnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.000001&lt;/span&gt;)
pardist[,&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;] = p[&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;] + &lt;span class=&quot;kw&quot;&gt;rnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.000001&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Compute optimal policy&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;sdp = &lt;span class=&quot;kw&quot;&gt;f_transition_matrix&lt;/span&gt;(f, p, x_grid, h_grid, sigma_g, pardist)
s_opt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;value_iteration&lt;/span&gt;(sdp, x_grid, h_grid, &lt;span class=&quot;dt&quot;&gt;OptTime=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;, xT, profit, delta)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Compare to the case without parameter uncertainty (growth noise only)&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;SDP_Mat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;determine_SDP_matrix&lt;/span&gt;(f, p, x_grid, h_grid, sigma_g)
pars_fixed &amp;lt;- &lt;span class=&quot;kw&quot;&gt;value_iteration&lt;/span&gt;(SDP_Mat, x_grid, h_grid, &lt;span class=&quot;dt&quot;&gt;OptTime=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;, xT, profit, delta)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Plot results&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(reshape2)
policies &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;stock=&lt;/span&gt;x_grid, &lt;span class=&quot;dt&quot;&gt;pars.uncert =&lt;/span&gt; x_grid[s_opt$D], &lt;span class=&quot;dt&quot;&gt;pars.fixed =&lt;/span&gt; x_grid[pars_fixed$D]), &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;stock&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(policies, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(stock, stock - value, &lt;span class=&quot;dt&quot;&gt;color=&lt;/span&gt;variable)) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;xlab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;stock size&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;ylab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;escapement&amp;quot;&lt;/span&gt;) &lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8247/8664808783_af5240ec6e_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-6&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-6&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;using-actual-estimates&quot;&gt;Using actual estimates&lt;/h2&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;pardist &amp;lt;- mcmcall&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Transform parameters back&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;pardist[,&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;] = &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(pardist[,&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;])
pardist[,&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;] = &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(pardist[,&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;])&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Compute optimal policy&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;sdp = &lt;span class=&quot;kw&quot;&gt;f_transition_matrix&lt;/span&gt;(f, p, x_grid, h_grid, sigma_g, pardist)
s_opt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;value_iteration&lt;/span&gt;(sdp, x_grid, h_grid, &lt;span class=&quot;dt&quot;&gt;OptTime=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;, xT, profit, delta)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Compare to the case without parameter uncertainty (growth noise only)&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;SDP_Mat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;determine_SDP_matrix&lt;/span&gt;(f, p, x_grid, h_grid, sigma_g)
pars_fixed &amp;lt;- &lt;span class=&quot;kw&quot;&gt;value_iteration&lt;/span&gt;(SDP_Mat, x_grid, h_grid, &lt;span class=&quot;dt&quot;&gt;OptTime=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;, xT, profit, delta)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Plot results&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(reshape2)
policies &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;stock=&lt;/span&gt;x_grid, &lt;span class=&quot;dt&quot;&gt;pars.uncert =&lt;/span&gt; x_grid[s_opt$D], &lt;span class=&quot;dt&quot;&gt;pars.fixed =&lt;/span&gt; x_grid[pars_fixed$D]), &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;stock&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(policies, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(stock, stock - value, &lt;span class=&quot;dt&quot;&gt;color=&lt;/span&gt;variable)) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;xlab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;stock size&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;ylab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;escapement&amp;quot;&lt;/span&gt;) &lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8264/8664820975_f29cc8d3be_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-11&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-11&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;to-do&quot;&gt;To Do&lt;/h2&gt;
&lt;p&gt;So far this is just a proof of principle example.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Needs to be adjusted to account for uncertainty in the estimates of the noise processes as well.&lt;/li&gt;
&lt;li&gt;Needs to be written as generic and documented functions, add to nonparametric-bayes package routines.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/04/18/notes.html"/>
   <updated>2013-04-18T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/18/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;misc-coding&quot;&gt;Misc coding&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;knitcitations handling of html formatting in tooltip: html inside the tag must needs be escaped. &lt;a href=&quot;https://github.com/cboettig/knitcitations/issues/37&quot;&gt;knitcitations/#37&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;pmc functions&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;hmm.. how do we easily wrap a function such that it returns its arguments (given and default) in a named list (appropriate for &lt;code&gt;do.call(function_name, args_list)&lt;/code&gt;)? &lt;code&gt;match.call()&lt;/code&gt; inside the function will give the literal string of how the function was called, which, if evaluated in the same environment with same variables in working space, will return the same results, but doesn’t lend itself to updating any one of those arguments. Hoped to extract variable values with some combination of &lt;code&gt;formals&lt;/code&gt; and &lt;code&gt;match.arg()&lt;/code&gt; but no luck.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Mendeley API authentication solved using &lt;a href=&quot;https://github.com/michalboo/mendeley-oapi/blob/master/authorise.rb&quot;&gt;Michal’s clever implementation for OAuth&lt;/a&gt;, see my original query on &lt;a href=&quot;http://stackoverflow.com/questions/15887366/obtaining-an-oauth-token-in-ruby-for-the-mendeley-api&quot;&gt;SO&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;nonparametric-bayes&quot;&gt;nonparametric-bayes&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Implement the SDP calculation for the posterior distributions returned in the parametric comparison case &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/795bf96ed92a708b44978610da7db3b49ebb4dce/inst/examples/BUGS/allen.Rmd&quot;&gt;nonparametric-bayes/allen.Rmd&lt;/a&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Working out the integration over uncertainty for the parameter distribution. Brute force approach clearly doesn’t scale, even on coarse grid, to many parameters. After discussion with Marc, implementing as Monte Carlo instead. As we get samples from the posterior out of the BUGs fit in the first place, this is much more efficient. Should of tried that the first time. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/34922e969e984b5d695a5b53aee01aac1ea3b38e/inst/examples/BUGS/par_uncertainty_sdp.md&quot;&gt;nonparametric-bayes/par_uncertainty_sdp.Rmd&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;warning-signals&quot;&gt;warning-signals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Analytic calculation of eigenvalues for managed vs unmanaged system&lt;/li&gt;
&lt;li&gt;finish fallacy reply&lt;/li&gt;
&lt;li&gt;finish ews-review reply&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;geospatial-coordinates-from-plain-text&quot;&gt;Geospatial coordinates from plain text&lt;/h2&gt;
&lt;p&gt;Discussed the problem of geolocation from plain text discriptions with Simon a few days ago. I’ve written a simple i&lt;a href=&quot;https://github.com/cboettig/sandbox/blob/29ab32342e9c07272b4796778cd86d518368b3b2/R-tricks/fishphotos.R&quot;&gt;R function to query place names against the Google Map API&lt;/a&gt;, but as Simon has demonstrated, this will often return the coordinates of a cafe in San Fransisco rather than the lake in Italy you meant to get. At DataCite 2011 I had met some folks who mentioned developing a machine learning algorithm for this, though stupidly it looks like I did not record this in my &lt;a href=&quot;http://carlboettiger.info/2011/08/24/datacite-day-1.html&quot;&gt;notes&lt;/a&gt;. Oh well, Google turned up the following interface: &lt;a href=&quot;http://geoparser.digmap.eu/advanced.jsp&quot;&gt;http://geoparser.digmap.eu/advanced.jsp&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Click the geoparse example and scroll down in the XML; they assign probabilities of possible spatial matches. For instance, Hiroshima as the name of a “railroad station” gets 0.05 probability, whereas the majority of the weight falls on “populated place” in Japan.&lt;/p&gt;
&lt;p&gt;It looks like you could query against the service directly, haven’t really explored.&lt;/p&gt;
&lt;p&gt;They have a paper out on this too, &lt;a href=&quot;http://oa.upm.es/4367/1/INVE_MEM_2008_60075.pdf&quot;&gt;http://oa.upm.es/4367/1/INVE_MEM_2008_60075.pdf&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&quot;showtooltip&quot; data-html=&quot;true&quot; title=&quot;&lt;p&gt;Shelton A, Satterthwaite W, Beakes M, Munch S, Sogard S and Mangel M (2013). “Separating Intrinsic And Environmental Contributions to Growth And Their Population Consequences.” The American Naturalist, pp. 000–000. ISSN 00030147.&amp;quot;&amp;gt;&lt;a href=&quot;http://dx.doi.org/10.1086/670198&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Shelton &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt; provide a rather elegant example of how accounting for individual variation improves modeling efforts in growth dynamics.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Measurement error is important but difficult to deal with; a proper state-space model should use all the replicates to estimate the measurement error process. &lt;span class=&quot;showtooltip&quot; data-html=&quot;true&quot; title=&quot;&lt;p&gt;Knape J, Besbeas P and de Valpine P (2013). “Using Uncertainty Estimates in Analyses of Population Time Series.” Ecology, pp. 130417174952006–. ISSN 0012-9658.&amp;quot;&amp;gt;&lt;a href=&quot;http://dx.doi.org/10.1890/12-0712.1&quot; rel=&quot;http://purl.org/spar/cito/critiques&quot; &gt;Knape &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt; argue that you can do pretty well with just the standard errors from the replicates. – Um, but don’t we know this? We expect the central limit theorem to be pretty good a lot of the time. The demonstration that it can work is not quite as useful as a demonstration of when we might expect it not to; but my quick read may be missing something. Certainly an interesting point to wrestle with before going off the deep end with the state-space modeling each time…&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Looking over an early draft of Duncan and Deborah’s “XML and Web Technologies for Data Sciences with R”. Looks fantastic – where was this 3 years ago?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Just launched: http://bison.usgs.ornl.gov (US only). Individual sample occurances, but no morphological measurements available.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Jonas Knape, Panagiotis Besbeas, Perry de Valpine, (2013) Using Uncertainty Estimates in Analyses of Population Time Series. &lt;em&gt;Ecology&lt;/em&gt; 130417174952006-NA &lt;a href=&quot;http://dx.doi.org/10.1890/12-0712.1&quot;&gt;10.1890/12-0712.1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Andrew O. Shelton, William H. Satterthwaite, Michael P. Beakes, Stephan B. Munch, Susan M. Sogard, Marc Mangel, (2013) Separating Intrinsic And Environmental Contributions to Growth And Their Population Consequences. &lt;em&gt;The American Naturalist&lt;/em&gt; 000-000 &lt;a href=&quot;http://dx.doi.org/10.1086/670198&quot;&gt;10.1086/670198&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/04/17/notes.html"/>
   <updated>2013-04-17T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/17/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;warning-signals&quot;&gt;warning-signals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Finishing up edits.&lt;/li&gt;
&lt;li&gt;Writing PRSB reply&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;logistics&quot;&gt;Logistics&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;In tomorrow’s Marc meeting, check in about what to include for the CSTAR report&lt;/li&gt;
&lt;li&gt;manuscript / analysis updates&lt;/li&gt;
&lt;li&gt;Comments on recent lit?&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;ropensci&quot;&gt;ropensci&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/ropensci/treeBASE/issues/4&quot;&gt;treebase/#4&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&quot;showtooltip&quot; title=&quot;Dai L, Korolev K and Gore J (2013). &amp;ldquo;Slower Recovery in Space Before Collapse of Connected Populations.&amp;rdquo; Nature. ISSN 0028-0836, http://dx.doi.org/10.1038/nature12071.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1038/nature12071&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Dai &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt; , with introductory piece by &lt;span class=&quot;showtooltip&quot;  title=&quot;Carpenter S (2013).
&amp;ldquo;Complex Systems: Spatial Signatures of Resilience.&amp;rdquo; Nature. ISSN 0028-0836&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1038/nature12092&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Carpenter (2013)&lt;/a&gt;&lt;/span&gt; . In this they look only at the spatial extent of a perturbation. Presumbably one might attempt to compare the spatial extent over time to establish a baseline, or otherwise identify a control system. Very difficult to see how this can be applied without appropriate references.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Also provides an elegant and clear, if rather intuitive, demonstration that spatially connected / mixing populations will dampen out the signal. Perhaps the interpretation of this misplaces the emphasis – for the connectedness is allowing the insult (dilution of nutrients) to diffuse among neighbors may be strengthening the resilience relative to an isolated population, and therefore it is only appropriate that the signal would weaken.&lt;/p&gt;
&lt;p&gt;Hehe. Nice to see our Prosecutor’s Fallacy paper (&lt;span class=&quot;showtooltip&quot;  title=&quot;Boettiger C and Hastings A (2012).
&amp;ldquo;Early Warning Signals And The Prosecutor'S Fallacy.&amp;rdquo;
Proceedings of The Royal Society B: Biological Sciences, 279, pp. 4734&amp;ndash;4739.
ISSN 0962-8452&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1098/rspb.2012.2085&quot; rel=&quot;http://purl.org/spar/cito/citesAsEvidence&quot; &gt;Boettiger &amp;amp; Hastings, 2012&lt;/a&gt;&lt;/span&gt; ) being used as further evidence for the value of experimental confirmation: “tests of these indicators in replicated experiments, which avoid the bias intro- duced by selective sampling (23) are lacking.”&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&quot;showtooltip&quot;  title=&quot;Glaser S, Fogarty M, Liu H, Altman I, Hsieh C, Kaufman L, MacCall A, Rosenberg A, Ye H and Sugihara G (2013).
&amp;ldquo;Complex Dynamics May Limit Prediction in Marine Fisheries.&amp;rdquo; Fish And Fisheries, pp. n/a&amp;ndash;n/a.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1111/faf.12037&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Glaser &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt; . Nonlinear forecasting doesn’t perform well across the board on these various fisheries data. Authors conclude that this suggests these systems are inherently unpredictable, though seems one could do more to rule out methodological weaknesses and make a more precise statement (perhaps a mutual information claim). Their approach having a large suite of data sets against which to test the performance of a method is nevertheless an interesting idea that’s had some popularity in the machine learning world. Hopefully more researchers will attempt a parallel analysis of these data.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;C. Boettiger, A. Hastings, (2012) Early Warning Signals And The Prosecutor’S Fallacy. &lt;em&gt;Proceedings of The Royal Society B: Biological Sciences&lt;/em&gt; &lt;strong&gt;279&lt;/strong&gt; 4734-4739 &lt;a href=&quot;http://dx.doi.org/10.1098/rspb.2012.2085&quot;&gt;10.1098/rspb.2012.2085&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Stephen R. Carpenter, (2013) Complex Systems: Spatial Signatures of Resilience. &lt;em&gt;Nature&lt;/em&gt; &lt;a href=&quot;http://dx.doi.org/10.1038/nature12092&quot;&gt;10.1038/nature12092&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Lei Dai, Kirill S. Korolev, Jeff Gore, (2013) Slower Recovery in Space Before Collapse of Connected Populations. &lt;em&gt;Nature&lt;/em&gt; &lt;a href=&quot;http://dx.doi.org/10.1038/nature12071&quot;&gt;10.1038/nature12071&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Sarah M Glaser, Michael J Fogarty, Hui Liu, Irit Altman, Chih-Hao Hsieh, Les Kaufman, Alec D MacCall, Andrew A Rosenberg, Hao Ye, George Sugihara, (2013) Complex Dynamics May Limit Prediction in Marine Fisheries. &lt;em&gt;Fish And Fisheries&lt;/em&gt; n/a-n/a &lt;a href=&quot;http://dx.doi.org/10.1111/faf.12037&quot;&gt;10.1111/faf.12037&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>a few notes on various projects</title>
   <link href="/2013/04/16/notes.html"/>
   <updated>2013-04-16T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/16/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
    
   <category term="//categories.html#evolution" label="evolution"/>
   
   <content type="html">&lt;h2 id=&quot;warning-signals&quot;&gt;warning-signals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Working on revisions for &lt;a href=&quot;https://github.com/cboettig/ews-review/&quot;&gt;ews-review&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Grr, the challenges of open science – can’t stick confidential reviews in ews-review repo where they belong, or track them on the issues tracker, without disclosing their contents. What are the terms of use for these things anyhow&amp;gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;phylogentics-pmc&quot;&gt;phylogentics / pmc&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Apparently pmc does have users – at least one recognized that my Vignette is broken following the latest Gieger update. Need to add simulate and update methods for the new fitContinuous, and then integrate these. &lt;a href=&quot;https://github.com/cboettig/pmc/issues/3&quot;&gt;pmc/#3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Another pmc request. Sounds like I should also add support for OUwie fits. See if I can get Jeremy to add &lt;code&gt;simulate&lt;/code&gt; and &lt;code&gt;update&lt;/code&gt; methods. &lt;a href=&quot;https://github.com/cboettig/pmc/issues/4&quot;&gt;pmc/#4&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Dear phylogeneticists&lt;/strong&gt;: please define a methods API for your functions. Accessing coefficients using something like &lt;code&gt;output[[1]][[2]]$somevar$name[4]&lt;/code&gt; is not only cumbersome, but bound to break when you modify your function, so provide a &lt;code&gt;coef&lt;/code&gt; method. Likewise provide &lt;code&gt;simulate&lt;/code&gt; and &lt;code&gt;update&lt;/code&gt; methods so we can all raise the bar on our statistics a little bit.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Alternatively put the code on Github, where sensible folks can fork it, add some common-sense classes and give you a pull request.&lt;/p&gt;
&lt;h2 id=&quot;code-tricks&quot;&gt;Code tricks&lt;/h2&gt;
&lt;p&gt;Because I’m always wondering how to do this one: let’s see what methods are defined for Geiger’s new &lt;code&gt;gfit&lt;/code&gt; class:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;methods&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;gfit&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Returns:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] coef.gfit*   logLik.gfit*

   Non-visible functions are asterisked&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;ht Michael Hannon for that one, and a good way to confuse some folks on &lt;a href=&quot;http://stackoverflow.com/questions/16048949&quot;&gt;SO&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;knitcitations&quot;&gt;knitcitations&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Fixed a minor issue in tooltip formatting, &lt;a href=&quot;https://github.com/cboettig/knitcitations/issues/37&quot;&gt;knitcitations/#37&lt;/a&gt;. Unfortunately not updated in earlier notebook entires, but should be fixed from here on).&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Interesting ideas from some folks about adding CSL support, and thinking about being able to pull data into knitcitations from personal zotero libraries, &lt;a href=&quot;https://github.com/cboettig/knitcitations/issues/38&quot;&gt;knitcitations/#38&lt;/a&gt;. Zotero API seems to have some nice features for listing entries of a collection in a variety of file formats, including CSL styling for the returns.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Nearly a month since last push (0.4-4). Should update CRAN to current development version (0.4-6) sometime this week…&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The debates continue: &lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1301759110&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Szuwalski (2013)&lt;/a&gt; , and the reply &lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1302181110&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Vert-pre &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt; , reflecting confusion over the article earlier this year, &lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1214879110&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Vert-pre &lt;em&gt;et. al.&lt;/em&gt; (2013b)&lt;/a&gt; .&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Disupting the claim of &lt;a href=&quot;http://dx.doi.org/10.1029/2010GL044486&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Ditlevsen &amp;amp; Johnsen (2010)&lt;/a&gt; and others, &lt;a href=&quot;http://dx.doi.org/10.5194/cp-9-323-2013&quot; rel=&quot;http://purl.org/spar/cito/citesAsEvidence&quot; &gt;Cimatoribus &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt; argue that DO events do show warning signals. But are they chance transitions then?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Looking over &lt;a href=&quot;http://dx.doi.org/10.1038/nclimate1143&quot; rel=&quot;http://purl.org/spar/cito/citesAsAuthority&quot; &gt;Lenton (2011)&lt;/a&gt; , which has a review of some of the evidence against warning signals for noise-induced transitions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An even earlier result from Ludwig, in &lt;a href=&quot;http://dx.doi.org/10.1137/1017070&quot; rel=&quot;http://purl.org/spar/cito/citesAsEvidence&quot; &gt;Ludwig (1975)&lt;/a&gt; .&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;A. A. Cimatoribus, S. S. Drijfhout, V. Livina, G. van der Schrier, (2013) Dansgaard–Oeschger Events: Bifurcation Points in The Climate System. &lt;em&gt;Climate of The Past&lt;/em&gt; &lt;strong&gt;9&lt;/strong&gt; 323-333 &lt;a href=&quot;http://dx.doi.org/10.5194/cp-9-323-2013&quot;&gt;10.5194/cp-9-323-2013&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Peter D. Ditlevsen, Sigfus J. Johnsen, (2010) Tipping Points: Early Warning And Wishful Thinking. &lt;em&gt;Geophysical Research Letters&lt;/em&gt; &lt;strong&gt;37&lt;/strong&gt; n/a-n/a &lt;a href=&quot;http://dx.doi.org/10.1029/2010GL044486&quot;&gt;10.1029/2010GL044486&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Timothy M. Lenton, (2011) Early Warning of Climate Tipping Points. &lt;em&gt;Nature Climate Change&lt;/em&gt; &lt;strong&gt;1&lt;/strong&gt; 201-209 &lt;a href=&quot;http://dx.doi.org/10.1038/nclimate1143&quot;&gt;10.1038/nclimate1143&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Donald Ludwig, (1975) Persistence of Dynamical Systems Under Random Perturbations. &lt;em&gt;Siam Review&lt;/em&gt; &lt;strong&gt;17&lt;/strong&gt; 605-640 &lt;a href=&quot;http://dx.doi.org/10.1137/1017070&quot;&gt;10.1137/1017070&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;C. Szuwalski, (2013) Production is A Poor Metric For Identifying Regime-Like Behavior in Marine Stocks. &lt;em&gt;Proceedings of The National Academy of Sciences&lt;/em&gt; &lt;strong&gt;110&lt;/strong&gt; E1436-E1436 &lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1301759110&quot;&gt;10.1073/pnas.1301759110&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;K. A. Vert-pre, R. O. Amoroso, O. P. Jensen, R. Hilborn, (2013) Reply to Szuwalski: Policies Robust to Uncertainty in Causes of Productivity Changes Are Needed. &lt;em&gt;Proceedings of The National Academy of Sciences&lt;/em&gt; &lt;strong&gt;110&lt;/strong&gt; E1437-E1437 &lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1302181110&quot;&gt;10.1073/pnas.1302181110&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;K. A. Vert-pre, R. O. Amoroso, O. P. Jensen, R. Hilborn, (2013) Frequency And Intensity of Productivity Regime Shifts in Marine Fish Stocks. &lt;em&gt;Proceedings of The National Academy of Sciences&lt;/em&gt; &lt;strong&gt;110&lt;/strong&gt; 1779-1784 &lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1214879110&quot;&gt;10.1073/pnas.1214879110&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Parametric Bayesian Example</title>
   <link href="/2013/04/12/parametric-bayesian-example.html"/>
   <updated>2013-04-12T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/12/parametric-bayesian-example</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;As discussed with Marc in yesterday’s meeting, it would be useful to compare the Gaussian process, as a nonparametric Bayesian estimate, to the optimal management solution under a &lt;em&gt;parametric&lt;/em&gt; Bayesian case, e.g. with the correct underlying model. This is implemented in BUGS (jags) through the R interface as described in &lt;span class=&quot;showtooltip&quot; data-html=&quot;true&quot; title=&quot;&lt;p&gt;Bolker B, Gardner B, Maunder M, Berg C, Brooks M, Comita L, Crone E, Cubaynes S, Davies T, de Valpine P, Ford J, Gimenez O, Kery M, Kim E, Lennert-Cody C, Magnusson A, Martell S, Nash J, Nielsen A, Regetz J, Skaug H and Zipkin E (2013). “Strategies For Fitting Nonlinear Ecological Models in R, ad Model Builder, And Bugs.” Methods in Ecology And Evolution, pp. n/a–n/a. .“&amp;gt;&lt;a href=&quot;http://dx.doi.org/10.1111/2041-210X.12044&quot; rel=&quot;http://purl.org/spar/cito/usesMethodIn&quot; &gt;Bolker &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt; , and follows the state-space model analysis along the lines outlined in &lt;span class=&quot;showtooltip&quot; data-html=&quot;true&quot; title=&quot;&lt;p&gt;Pedersen M, Berg C, Thygesen U, Nielsen A and Madsen H (2011). “Estimation Methods For Nonlinear State-Space Models in Ecology.” Ecological Modelling, 222, pp. 1394–1400. ISSN 03043800.&amp;quot;&amp;gt;&lt;a href=&quot;http://dx.doi.org/10.1016/j.ecolmodel.2011.01.007&quot; rel=&quot;http://purl.org/spar/cito/usesMethodIn&quot; &gt;Pedersen &lt;em&gt;et. al.&lt;/em&gt; (2011)&lt;/a&gt;&lt;/span&gt; .&lt;/p&gt;
&lt;p&gt;We base the estimate on the same simulated data as for the GP and MLE approaches,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;f &amp;lt;- RickerAllee
p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;)
K &amp;lt;- &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;
allee &amp;lt;- &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;with the same parameters (many of which we won’t need until the SDP value iteration),&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;sigma_g &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.05&lt;/span&gt;
sigma_m &amp;lt;- &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;
z_g &amp;lt;- function() &lt;span class=&quot;kw&quot;&gt;rlnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, sigma_g)
z_m &amp;lt;- function() &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt; + (&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;runif&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) - &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) * sigma_m
x_grid &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;1.5&lt;/span&gt; * K, &lt;span class=&quot;dt&quot;&gt;length =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;101&lt;/span&gt;)
h_grid &amp;lt;- x_grid
profit &amp;lt;- function(x, h) &lt;span class=&quot;kw&quot;&gt;pmin&lt;/span&gt;(x, h)
delta &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.01&lt;/span&gt;
OptTime &amp;lt;- &lt;span class=&quot;dv&quot;&gt;20&lt;/span&gt;  &lt;span class=&quot;co&quot;&gt;# stationarity with unstable models is tricky thing&lt;/span&gt;
reward &amp;lt;- &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;
xT &amp;lt;- &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;
seed_i &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;
Xo &amp;lt;- K  &lt;span class=&quot;co&quot;&gt;# observations start from&lt;/span&gt;
x0 &amp;lt;- Xo  &lt;span class=&quot;co&quot;&gt;# simulation under policy starts from&lt;/span&gt;
Tobs &amp;lt;- &lt;span class=&quot;dv&quot;&gt;35&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Generate the simulated data&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;obs &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sim_obs&lt;/span&gt;(Xo, z_g, f, p, &lt;span class=&quot;dt&quot;&gt;Tobs =&lt;/span&gt; Tobs, &lt;span class=&quot;dt&quot;&gt;nz =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;harvest =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;sort&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;rep&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, 
    &lt;span class=&quot;fl&quot;&gt;0.5&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;length =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;7&lt;/span&gt;), &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;)), &lt;span class=&quot;dt&quot;&gt;seed =&lt;/span&gt; seed_i)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And fit the MLE models as before&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;alt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;par_est&lt;/span&gt;(obs, &lt;span class=&quot;dt&quot;&gt;init =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;r =&lt;/span&gt; p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;K =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;mean&lt;/span&gt;(obs$x[obs$x &amp;gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;]), 
    &lt;span class=&quot;dt&quot;&gt;s =&lt;/span&gt; sigma_g))
est &amp;lt;- &lt;span class=&quot;kw&quot;&gt;par_est_allee&lt;/span&gt;(obs, f, p, &lt;span class=&quot;dt&quot;&gt;init =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;r =&lt;/span&gt; p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] + &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;K =&lt;/span&gt; p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;] + 
    &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;C =&lt;/span&gt; p[&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;] + &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;s =&lt;/span&gt; sigma_g))&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;parametric-bayesian-model-fit&quot;&gt;Parametric Bayesian model fit&lt;/h2&gt;
&lt;p&gt;We will use the jags interface from R,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(R2jags)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;initialize parameters. The parametric equation (in this case, matching the true dynamics) and priors are defined &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/795bf96ed92a708b44978610da7db3b49ebb4dce/inst/examples/BUGS/bugmodel-GammaPrior.txt&quot;&gt;in BUGS notation in text file&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;init_p = est$p
&lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(init_p) = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;r0&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;K&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;theta&amp;quot;&lt;/span&gt;)
y &amp;lt;- obs$y[-&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]
N = &lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(y)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;jags.data &amp;lt;- &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;N&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;y&amp;quot;&lt;/span&gt;)
n.chains = &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;
n.iter = &lt;span class=&quot;dv&quot;&gt;20000&lt;/span&gt;
n.burnin = &lt;span class=&quot;kw&quot;&gt;floor&lt;/span&gt;(n.iter/&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)
n.thin = &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;floor&lt;/span&gt;(n.chains * (n.iter - n.burnin)/&lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;))&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;jags-using-gamma-priors-on-precision&quot;&gt;JAGS using gamma priors on precision&lt;/h2&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;jags.params=&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;K&amp;quot;&lt;/span&gt;,&lt;span class=&quot;st&quot;&gt;&amp;quot;logr0&amp;quot;&lt;/span&gt;,&lt;span class=&quot;st&quot;&gt;&amp;quot;logtheta&amp;quot;&lt;/span&gt;,&lt;span class=&quot;st&quot;&gt;&amp;quot;iR&amp;quot;&lt;/span&gt;,&lt;span class=&quot;st&quot;&gt;&amp;quot;iQ&amp;quot;&lt;/span&gt;); &lt;span class=&quot;co&quot;&gt;# Don&amp;#39;t need to save &amp;quot;x&amp;quot;&lt;/span&gt;
jags.inits &amp;lt;- function(){
  &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;K&amp;quot;&lt;/span&gt;=init_p[&lt;span class=&quot;st&quot;&gt;&amp;quot;K&amp;quot;&lt;/span&gt;],&lt;span class=&quot;st&quot;&gt;&amp;quot;logr0&amp;quot;&lt;/span&gt;=&lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(init_p[&lt;span class=&quot;st&quot;&gt;&amp;quot;r0&amp;quot;&lt;/span&gt;]),&lt;span class=&quot;st&quot;&gt;&amp;quot;logtheta&amp;quot;&lt;/span&gt;=&lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(init_p[&lt;span class=&quot;st&quot;&gt;&amp;quot;theta&amp;quot;&lt;/span&gt;]),&lt;span class=&quot;st&quot;&gt;&amp;quot;iQ&amp;quot;&lt;/span&gt;=&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.05&lt;/span&gt;,&lt;span class=&quot;st&quot;&gt;&amp;quot;iR&amp;quot;&lt;/span&gt;=&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;,&lt;span class=&quot;st&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;=y,&lt;span class=&quot;dt&quot;&gt;.RNG.name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;base::Wichmann-Hill&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;.RNG.seed=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;123&lt;/span&gt;)
}
&lt;span class=&quot;kw&quot;&gt;set.seed&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;12345&lt;/span&gt;)
time&amp;lt;-&lt;span class=&quot;kw&quot;&gt;system.time&lt;/span&gt;(       
  jagsfit &amp;lt;- &lt;span class=&quot;kw&quot;&gt;jags&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;jags.data, &lt;span class=&quot;dt&quot;&gt;inits=&lt;/span&gt;jags.inits, jags.params, &lt;span class=&quot;dt&quot;&gt;n.chains=&lt;/span&gt;n.chains, 
                  &lt;span class=&quot;dt&quot;&gt;n.iter=&lt;/span&gt;n.iter, &lt;span class=&quot;dt&quot;&gt;n.thin=&lt;/span&gt;n.thin, &lt;span class=&quot;dt&quot;&gt;n.burnin=&lt;/span&gt;n.burnin,&lt;span class=&quot;dt&quot;&gt;model.file=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;bugmodel-GammaPrior.txt&amp;quot;&lt;/span&gt;)
)         &lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;time &amp;lt;- &lt;span class=&quot;kw&quot;&gt;unname&lt;/span&gt;(time[&lt;span class=&quot;st&quot;&gt;&amp;quot;elapsed&amp;quot;&lt;/span&gt;]);&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;summarize-the-results&quot;&gt;Summarize the results&lt;/h2&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(emdbook)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(coda)
tfit_jags_m &amp;lt;- &lt;span class=&quot;kw&quot;&gt;as.mcmc.bugs&lt;/span&gt;(jagsfit$BUGSoutput)
&lt;span class=&quot;kw&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;xyplot&lt;/span&gt;(tfit_jags_m))&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8258/8662939943_0e5faa9dc0_o.png&quot; alt=&quot;Parameter traces provide a visual tool to assess performance and convergence of the MCMC routine&quot; /&gt;&lt;figcaption&gt;Parameter traces provide a visual tool to assess performance and convergence of the MCMC routine&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;densityplot&lt;/span&gt;(tfit_jags_m))&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8261/8662940039_3f5dbeee9d_o.png&quot; alt=&quot;The resulting posterior distributions for the model parameters inferred&quot; /&gt;&lt;figcaption&gt;The resulting posterior distributions for the model parameters inferred&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;We collect model parameters over the replicate runs,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;mcmc &amp;lt;- &lt;span class=&quot;kw&quot;&gt;as.mcmc&lt;/span&gt;(jagsfit)
mcmcall &amp;lt;- mcmc[, -&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]
who &amp;lt;- &lt;span class=&quot;kw&quot;&gt;colnames&lt;/span&gt;(mcmcall)
mcmcall &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cbind&lt;/span&gt;(mcmcall[, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], mcmcall[, &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;], mcmcall[, &lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;], mcmcall[, 
    &lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;], mcmcall[, &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;])
&lt;span class=&quot;kw&quot;&gt;colnames&lt;/span&gt;(mcmcall) &amp;lt;- who&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;further-parameter-exploration&quot;&gt;Further parameter exploration&lt;/h2&gt;
&lt;p&gt;We will need to integrate over parameter uncertainty. Can consider the discritized binning&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;theta &amp;lt;- &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(mcmcall[, &lt;span class=&quot;st&quot;&gt;&amp;quot;logtheta&amp;quot;&lt;/span&gt;])
theta_dist &amp;lt;- &lt;span class=&quot;kw&quot;&gt;hist&lt;/span&gt;(theta, &lt;span class=&quot;dt&quot;&gt;freq =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8255/8662940161_6cfebf6a91_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;theta_dist$mids&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##  [1] 0.25 0.75 1.25 1.75 2.25 2.75 3.25 3.75 4.25 4.75 5.25 5.75 6.25 6.75
## [15] 7.25&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;theta_dist$density&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##  [1] 1.154 0.256 0.130 0.092 0.068 0.058 0.044 0.042 0.042 0.018 0.022
## [12] 0.026 0.022 0.014 0.012&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;delta &amp;lt;- theta_dist$mids[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;] - theta_dist$mids[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Evaluating the value function given &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?f\inline&quot;/&gt;&lt;/span&gt; fixed at each of &lt;code&gt;theta_dist$mids&lt;/code&gt; multiplied by &lt;code&gt;theta_dist$density * delta&lt;/code&gt; and summed over each &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\theta\inline&quot;/&gt;&lt;/span&gt; is going to be slow for a single parameter but simply unrealistic for higher dimensions.&lt;/p&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Benjamin M. Bolker, Beth Gardner, Mark Maunder, Casper W. Berg, Mollie Brooks, Liza Comita, Elizabeth Crone, Sarah Cubaynes, Trevor Davies, Perry de Valpine, Jessica Ford, Olivier Gimenez, Marc Kery, Eun Jung Kim, Cleridy Lennert-Cody, Arni Magnusson, Steve Martell, John Nash, Anders Nielsen, Jim Regetz, Hans Skaug, Elise Zipkin, (2013) Strategies For Fitting Nonlinear Ecological Models in R, ad Model Builder, And Bugs. &lt;em&gt;Methods in Ecology And Evolution&lt;/em&gt; n/a-n/a &lt;a href=&quot;http://dx.doi.org/10.1111/2041-210X.12044&quot;&gt;10.1111/2041-210X.12044&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;M.W. Pedersen, C.W. Berg, U.H. Thygesen, A. Nielsen, H. Madsen, (2011) Estimation Methods For Nonlinear State-Space Models in Ecology. &lt;em&gt;Ecological Modelling&lt;/em&gt; &lt;strong&gt;222&lt;/strong&gt; 1394-1400 &lt;a href=&quot;http://dx.doi.org/10.1016/j.ecolmodel.2011.01.007&quot;&gt;10.1016/j.ecolmodel.2011.01.007&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Tutorial On Likelihood And Roc Methods For Early Warning Signals</title>
   <link href="/2013/04/11/tutorial-on-likelihood-and-roc-methods-for-early-warning-signals.html"/>
   <updated>2013-04-11T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/11/tutorial-on-likelihood-and-roc-methods-for-early-warning-signals</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;In this tutorial we walk through how to use the likelihood-based approach of &lt;span class=&quot;showtooltip&quot; title=&quot;Boettiger C and Hastings A (2012). Quantifying Limits to
Detection of Early Warning For Critical Transitions. _Journal of
The Royal Society Interface_, *9*, pp. 2527-2539. ISSN 1742-5689,
 http://dx.doi.org/10.1098/rsif.2012.0125.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1098/rsif.2012.0125&quot; rel=&quot;http://purl.org/spar/cito/usesMethodFrom&quot; &gt;Boettiger &amp;amp; Hastings (2012)&lt;/a&gt;&lt;/span&gt; to provide an early warning signal for a critical transition, and how to generate ROC curves discussed in the same paper for comparing different early warning signals. Context and details about the methodology are presented in the paper; here we focus on using the methodology provided in the accompanying R package. All of the examples shown here can be reproduced by pasting the code provided into an R terminal. We will need the following libraries to run this example. If you don’t have them, they can be installed from CRAN using the &lt;code&gt;install.packages&lt;/code&gt; function.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(ggplot2)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(reshape2)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(multicore)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(devtools)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We will be using custom functions provided in the R package Boettiger, (2012) that accompanies Boettiger &amp;amp; Hastings, (2012), which can be installed directly from the development repository on GitHub:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;install_github&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;earlywarning&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;cboettig&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(earlywarning)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We begin by loading the &lt;code&gt;ibm_critical&lt;/code&gt; data provided in the package (from an individual-based model simulation of a critical transition). We plot the raw data to take a look at it.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;data&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;ibms&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;plot&lt;/span&gt;(ibm_critical, &lt;span class=&quot;dt&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;b&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8261/8641108753_956f179a1d_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;Fit both models to the original data, record the observed likelihood ratio of the original data&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;A &amp;lt;- &lt;span class=&quot;kw&quot;&gt;stability_model&lt;/span&gt;(ibm_critical, &lt;span class=&quot;st&quot;&gt;&amp;quot;OU&amp;quot;&lt;/span&gt;)
B &amp;lt;- &lt;span class=&quot;kw&quot;&gt;stability_model&lt;/span&gt;(ibm_critical, &lt;span class=&quot;st&quot;&gt;&amp;quot;LSN&amp;quot;&lt;/span&gt;)
observed &amp;lt;- -&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * (&lt;span class=&quot;kw&quot;&gt;logLik&lt;/span&gt;(A) - &lt;span class=&quot;kw&quot;&gt;logLik&lt;/span&gt;(B))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Perform the bootstrapped model comparison on the parallel cluster.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;runtime &amp;lt;- &lt;span class=&quot;kw&quot;&gt;system.time&lt;/span&gt;(
reps &amp;lt;- &lt;span class=&quot;kw&quot;&gt;mclapply&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;dv&quot;&gt;200&lt;/span&gt;, function(i) &lt;span class=&quot;kw&quot;&gt;compare&lt;/span&gt;(A, B)))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Which took 4176.78 seconds to run for the example shown here.&lt;/p&gt;
&lt;p&gt;A helper function extracts the likelihood ratios under each of the pairwise comparisons (The null distribution: -2 times the log likelihood of data fit under A that had been simulated under A, minus the log likelihood of fits under A simulated under B; and the test distribution: fit under B when simulated under A, minus the loglikehood of being fit under B, simulated under B) as a data frame. we show the top of the data frame as output below.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;lr &amp;lt;- &lt;span class=&quot;kw&quot;&gt;lik_ratios&lt;/span&gt;(reps)
&lt;span class=&quot;kw&quot;&gt;head&lt;/span&gt;(lr)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##   simulation rep     value
## 1       null   1  0.001659
## 2       test   1  2.255139
## 3       null   2  1.892615
## 4       test   2  9.804084
## 5       null   3  4.795269
## 6       test   3 22.696982&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We use this data to generate the overlapping distributions shown in Boettiger &amp;amp; Hastings, (2012),&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(lr) + &lt;span class=&quot;kw&quot;&gt;geom_density&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value, &lt;span class=&quot;dt&quot;&gt;fill=&lt;/span&gt;simulation), &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.6&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;geom_vline&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;xintercept=&lt;/span&gt;observed))&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8245/8642325058_d70eaee962_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;A second helper function generates the ROC curve from the likelihood ratio data, providing an alternative way to visualize this overlap:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;roc &amp;lt;- &lt;span class=&quot;kw&quot;&gt;roc_data&lt;/span&gt;(lr)
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(roc) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(False.positives, True.positives))&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8402/8641224925_83a045afbb_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;ROC curves are particularly useful in comparing the power of a variety of approaches. For instance, we can compare the performance of the likelihood-based signal shown above to the traditional approach of using a correlation coefficient to detect the increase in some summary statistic such as variance or autocorrelation. To obtain replicates, we will still simulate under the null (OU) and test (LSN) models estimated above, but instead of computing the likelihood of these data, we will estimate the commonly used rank correlation coefficient, Kendall’s tau, to quantify the increase in variance, autcorrelation, and skew observed in a moving window over the data.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;var &amp;lt;- &lt;span class=&quot;kw&quot;&gt;bootstrap_trend&lt;/span&gt;(ibm_critical, window_var, &lt;span class=&quot;dt&quot;&gt;method=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;kendall&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;rep=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;200&lt;/span&gt;)
acor &amp;lt;- &lt;span class=&quot;kw&quot;&gt;bootstrap_trend&lt;/span&gt;(ibm_critical, window_autocorr, &lt;span class=&quot;dt&quot;&gt;method=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;kendall&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;rep=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;200&lt;/span&gt;)
skew &amp;lt;- &lt;span class=&quot;kw&quot;&gt;bootstrap_trend&lt;/span&gt;(ibm_critical, window_skew, &lt;span class=&quot;dt&quot;&gt;method=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;kendall&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;rep=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;200&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These data are formatted like the likeihood ratio data above, only that the statistic is now Kendall’s tau.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(var) + &lt;span class=&quot;kw&quot;&gt;geom_density&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value, &lt;span class=&quot;dt&quot;&gt;fill=&lt;/span&gt;simulation), &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.6&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;geom_vline&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;xintercept=&lt;/span&gt;observed))&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8265/8642341382_1d87080d5c_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;We can combine the data for the ROC curves of each indicator to compare:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;indicators &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;var =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;roc_data&lt;/span&gt;(var), &lt;span class=&quot;dt&quot;&gt;acor =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;roc_data&lt;/span&gt;(acor), &lt;span class=&quot;dt&quot;&gt;skew =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;roc_data&lt;/span&gt;(skew), &lt;span class=&quot;dt&quot;&gt;lr =&lt;/span&gt; roc), &lt;span class=&quot;dt&quot;&gt;id =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;Threshold&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;False.positives&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;True.positives&amp;quot;&lt;/span&gt;))
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(indicators) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(False.positives, True.positives, &lt;span class=&quot;dt&quot;&gt;color=&lt;/span&gt;L1)) &lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8122/8641241253_4c3704523e_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;C. Boettiger, A. Hastings, (2012) Quantifying Limits to Detection of Early Warning For Critical Transitions. &lt;em&gt;Journal of The Royal Society Interface&lt;/em&gt; &lt;strong&gt;9&lt;/strong&gt; 2527-2539 &lt;a href=&quot;http://dx.doi.org/10.1098/rsif.2012.0125&quot;&gt;10.1098/rsif.2012.0125&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>nonparametric-bayes: framing the issues for the manuscript</title>
   <link href="/2013/04/11/nonparametric-bayes-framing-the-issues.html"/>
   <updated>2013-04-11T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/11/nonparametric-bayes-framing-the-issues</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;marc-meeting-nonparametric-bayes-manuscript&quot;&gt;Marc meeting: nonparametric-bayes manuscript&lt;/h2&gt;
&lt;p&gt;Very good meeting today going over some big picture considerations in the presentation of the nonparametric-bayes manuscript with Marc. (Also see new entries in issues log on nonparametric-bayes.) Make it clear that we are making a point rather than providing a tool. Focus on the tipping point context rather than the general management context.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Comparison against a parametric Bayesian model (&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/40&quot;&gt;40&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Comparison against an active learning parametric model facing a tipping point (&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/41&quot;&gt;41&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;parametric-bayesian-model&quot;&gt;Parametric Bayesian model&lt;/h2&gt;
&lt;p&gt;Drafting parametric Bayesian case for comparison, following Marc’s suggestion. So far, &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/795bf96ed92a708b44978610da7db3b49ebb4dce&quot;&gt;code as implemented in BUGS&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;more-on-the-exit-time-problem&quot;&gt;More on the exit time problem&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Alan pointed me to earlier work of &lt;span class=&quot;showtooltip&quot; title=&quot;Schuss Z and Matkowsky B (1979). The Exit Problem: A New Approach
to Diffusion Across Potential Barriers. _Siam Journal on Applied
Mathematics_, *36*, pp. 604-623. ISSN 0036-1399, 
http://dx.doi.org/10.1137/0136043.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1137/0136043&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Schuss &amp;amp; Matkowsky (1979)&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Also, an electronic version of Don Ludwig’s article: &lt;span class=&quot;showtooltip&quot; title=&quot;Donald Ludwig, (1981). Escape from Domains of Attraction for Systems Perturbed by Noise, Nonlinear Phenomena in Physics and Biology.&quot;&gt;&lt;a href=&quot;http://link.springer.com/chapter/10.1007/978-1-4684-4106-2_14&quot; rel=&quot;http://purl.org/spar/cito/usesMethodFrom&quot; &gt;Ludwig (1981)&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;warning-signals-reading&quot;&gt;Warning signals Reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Alan pointed out &lt;span class=&quot;showtooltip&quot; title=&quot;Boerlijst M, Oudman T, de Roos A and Solé R (2013). Catastrophic
Collapse Can Occur Without Early Warning: Examples of Silent
Catastrophes in Structured Ecological Models. _Plos One_, *8*,
pp. e62033-. 
http://dx.doi.org/10.1371/journal.pone.0062033.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1371/journal.pone.0062033&quot; rel=&quot;http://purl.org/spar/cito/reviews&quot; &gt;Boerlijst &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt; on warning signals in PLoS ONE today. A very nice piece! It’s quite useful how it show that the early warning signal can appear in unmonitored variables (e.g. juvenile dynamics) or in variables without adequate noise to provide a signal. Kind of funny that they pitch it as a counterexample to the conjecture that early warning signals are universal, since even Scheffer has avoided that word, and it’s not really a counterexample given the caveat of some process noise and complete observability of the system people have so far assumed (while your work with Derin is a more conclusive counter-example by going beyond fold bifurcations)… Anyway, good examples. We need a better understanding of warning signals in this multi-dimensional context at large.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Recently Noam pointed out &lt;span class=&quot;showtooltip&quot; title=&quot;Streeter R and Dugmore A (2013). Anticipating Land Surface
Change. _Proceedings of The National Academy of Sciences_, *110*,
pp. 5779-5784. ISSN 0027-8424, 
http://dx.doi.org/10.1073/pnas.1220161110.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1220161110&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Streeter &amp;amp; Dugmore (2013)&lt;/a&gt;&lt;/span&gt; , which looks like a nice spatial warning signal example (with the classic patterns, rather than the &lt;span class=&quot;showtooltip&quot; title=&quot;Bel G, Hagberg A and Meron E (2012). Gradual Regime Shifts in
Spatially Extended Ecosystems. _Theoretical Ecology_, *5*, pp.
591-604. ISSN 1874-1738, 
http://dx.doi.org/10.1007/s12080-011-0149-6.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1007/s12080-011-0149-6&quot; rel=&quot;http://purl.org/spar/cito/containsAssertionFrom&quot; &gt;Bel &lt;em&gt;et. al.&lt;/em&gt; (2012)&lt;/a&gt;&lt;/span&gt; pattern), but haven’t had time for a closer read yet.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;other-reading&quot;&gt;Other reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Trying to get a hold of &lt;span class=&quot;showtooltip&quot; title=&quot;Ludwig D and Walters C (1981). Measurement Errors And Uncertainty
in Parameter Estimates For Stock And Recruitment. _Canadian
Journal of Fisheries And Aquatic Sciences_, *38*, pp. 711-720.
ISSN 0706-652X,  http://dx.doi.org/10.1139/f81-094.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1139/f81-094&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Ludwig &amp;amp; Walters (1981)&lt;/a&gt;&lt;/span&gt; as well. A tough day for reading with the UCSC subscription access down due to “power outages”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Interesting preprint on advice for data reuse, &lt;span class=&quot;showtooltip&quot; title=&quot;White EP, Baldridge E, Brym ZT, Locey KJ, McGlinn DJ and Supp SR
(2013). Nine simple ways to make it easier to (re)use your data.
 https://peerj.com/preprints/7 [Online. last-accessed:
2013-04-15 21:19:41].  http://peerj.com/preprints/7.&quot;&gt;&lt;a href=&quot;http://peerj.com/preprints/7&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;White &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;misc-and-code-tricks&quot;&gt;Misc and code-tricks&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;My knitr scripts are not executing in parallel with snow/snowfall packages(?) Parallelizes fine when run chunk by chunk. (e.g. &lt;a href=&quot;https://github.com/cboettig/earlywarning/blob/8bf907c21f8eb0f69f6995a94d21ab0eac6e214a/inst/examples/example.Rmd&quot;&gt;example with snowfall&lt;/a&gt;). Knitr runs parallel fine with &lt;code&gt;multicore&lt;/code&gt;. Weird.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An interesting puzzle on knitr list today: wrangling crazy ascii tables in &lt;code&gt;Hmisc::summary.function&lt;/code&gt;. A good solution would just rewrite the class’s &lt;code&gt;print&lt;/code&gt; method to be a table object (e.g. compatible with &lt;code&gt;xtable&lt;/code&gt; and &lt;code&gt;pander::pandoc_table&lt;/code&gt;), but instead we can hack the ascii, adjusting the options that are passed to &lt;code&gt;print.char.matrix&lt;/code&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Created a &lt;a href=&quot;http://purl.org&quot;&gt;PURL&lt;/a&gt; persistent identifier for the notebook &lt;a href=&quot;http://purl.org/globalecology/lab-notebook&quot;&gt;purl.org/globalecology/lab-notebook&lt;/a&gt;. Existing public top level domain. Waiting for approval for my own top-level domain (cboettig).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(Hmisc)
df = &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;Age =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;round&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;rnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;50&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;15&lt;/span&gt;)), &lt;span class=&quot;dt&quot;&gt;Sex =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;rep&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;M&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;W&amp;quot;&lt;/span&gt;)))
out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;summary.formula&lt;/span&gt;( ~ Age + Sex, &lt;span class=&quot;dt&quot;&gt;data =&lt;/span&gt; df, &lt;span class=&quot;dt&quot;&gt;method =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;reverse&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;print&lt;/span&gt;(out, &lt;span class=&quot;dt&quot;&gt;hsep=&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;#39;|&amp;#39;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;csep=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;#39;|&amp;#39;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;vsep=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;#39;-&amp;#39;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;left.border=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;top.border=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Golan Bel, Aric Hagberg, Ehud Meron, (2012) Gradual Regime Shifts in Spatially Extended Ecosystems. &lt;em&gt;Theoretical Ecology&lt;/em&gt; &lt;strong&gt;5&lt;/strong&gt; 591-604 &lt;a href=&quot;http://dx.doi.org/10.1007/s12080-011-0149-6&quot;&gt;10.1007/s12080-011-0149-6&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Maarten C. Boerlijst, Thomas Oudman, André M. de Roos, Ricard V. Solé, (2013) Catastrophic Collapse Can Occur Without Early Warning: Examples of Silent Catastrophes in Structured Ecological Models. &lt;em&gt;Plos One&lt;/em&gt; &lt;strong&gt;8&lt;/strong&gt; e62033-NA &lt;a href=&quot;http://dx.doi.org/10.1371/journal.pone.0062033&quot;&gt;10.1371/journal.pone.0062033&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Donald Ludwig, Carl J. Walters, (1981) Measurement Errors And Uncertainty in Parameter Estimates For Stock And Recruitment. &lt;em&gt;Canadian Journal of Fisheries And Aquatic Sciences&lt;/em&gt; &lt;strong&gt;38&lt;/strong&gt; 711-720 &lt;a href=&quot;http://dx.doi.org/10.1139/f81-094&quot;&gt;10.1139/f81-094&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Zeev Schuss, Bernard J. Matkowsky, (1979) The Exit Problem: A New Approach to Diffusion Across Potential Barriers. &lt;em&gt;Siam Journal on Applied Mathematics&lt;/em&gt; &lt;strong&gt;36&lt;/strong&gt; 604-623 &lt;a href=&quot;http://dx.doi.org/10.1137/0136043&quot;&gt;10.1137/0136043&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;R. Streeter, A. J. Dugmore, (2013) Anticipating Land Surface Change. &lt;em&gt;Proceedings of The National Academy of Sciences&lt;/em&gt; &lt;strong&gt;110&lt;/strong&gt; 5779-5784 &lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1220161110&quot;&gt;10.1073/pnas.1220161110&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Ethan White, Elita Baldridge, Zachary Brym, Kenneth Locey, Daniel McGlinn, Sarah Supp, (2013) Nine simple ways to make it easier to (re)use your data. &lt;em&gt;PeerJ PrePrints&lt;/em&gt; &lt;a href=&quot;http://peerj.com/preprints/7&quot;&gt;http://peerj.com/preprints/7&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Donald Ludwig, (1981). Escape from Domains of Attraction for Systems Perturbed by Noise, Nonlinear Phenomena in Physics and Biology.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>A Clever Derivation On Realized Escape Times</title>
   <link href="/2013/04/05/a-clever-derivation-on-realized-escape-times.html"/>
   <updated>2013-04-05T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/05/a-clever-derivation-on-realized-escape-times</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;I have often observed (e.g. &lt;span class=&quot;showtooltip&quot; title=&quot;Boettiger C and Hastings A (2012). Early Warning Signals And The
Prosecutor'S Fallacy. _Proceedings of The Royal Society B:
Biological Sciences_, *279*, pp. 4734-4739. ISSN 0962-8452, 
http://dx.doi.org/10.1098/rspb.2012.2085.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1098/rspb.2012.2085&quot; rel=&quot;http://purl.org/spar/cito/citesAsEvidence&quot; &gt;Boettiger &amp;amp; Hastings (2012)&lt;/a&gt;&lt;/span&gt; ) that if purely stochastic transitions out of a potential well happen, then they happen fast (dispite the fact that waiting time for them to happen is very long). Yesterday Marc mentioned an interesting proof of this from Don Ludwig, who was able to show that the waiting time to reach a large deviation in a time &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?t\inline&quot;/&gt;&lt;/span&gt;, given that it reaches it at all, is of the same order as the return time from the large deviation to the equilibrium, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\log(L/\sigma)\inline&quot;/&gt;&lt;/span&gt;. That’s an absolutely fascinating conclusion, indeed a bit stronger than even I had expected (the waiting time until an escape is observed rather different! – of order &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\exp(L^2/\sigma^2)\inline&quot;/&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Don’s derivation is repeated in pages 302-311 Marc’s “Theoretical Biologist’s Toolbox,” rather delightfully too (e.g. the “Kumura Maneuver”, or sidenotes such as “it is also kind of fun to do a web search with key words ‘Dawson’s Integral’”). &lt;span class=&quot;showtooltip&quot; title=&quot;Lande R (1985). Expected time for random genetic drift of a
population between stable phenotypic states. 
http://www.pnas.org/content/82/22/7641.abstract [Online.
last-accessed: 2013-04-08 19:58:49]. 
http://www.pnas.org/content/82/22/7641.abstract.&quot;&gt;&lt;a href=&quot;http://www.pnas.org/content/82/22/7641.abstract&quot; rel=&quot;http://purl.org/spar/cito/citesForInformation&quot; &gt;Lande (1985)&lt;/a&gt;&lt;/span&gt; provides a somewhat different derivation of the same result.&lt;/p&gt;
&lt;h2 id=&quot;return-time&quot;&gt;Return time&lt;/h2&gt;
&lt;p&gt;The return time calculation is straight forward. Consider our OU model&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?dX = - X dt + \sigma dB_t&quot; alt=&quot;dX = - X dt + \sigma dB_t&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;We ask for the return time into a neighborhood &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\sigma\inline&quot;/&gt;&lt;/span&gt; of the origin, starting at &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?X_0 = L\inline&quot;/&gt;&lt;/span&gt; distant from the origin. The deterministic solution&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\tfrac{dx}{dt} = - x&quot; alt=&quot;\tfrac{dx}{dt} = - x&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;implies &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_t = L (1 - e^{-t})\inline&quot;/&gt;&lt;/span&gt;, so setting &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_t = \sigma_t\inline&quot;/&gt;&lt;/span&gt; and solving for &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?t\inline&quot;/&gt;&lt;/span&gt;, we find that &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_t\inline&quot;/&gt;&lt;/span&gt; is within &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\sigma\inline&quot;/&gt;&lt;/span&gt; of &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?t\inline&quot;/&gt;&lt;/span&gt; in time &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\log{L} - \log{\sigma}\inline&quot;/&gt;&lt;/span&gt;, or &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\log{L/\sigma}\inline&quot;/&gt;&lt;/span&gt;, as claimed.&lt;/p&gt;
&lt;h2 id=&quot;waiting-time&quot;&gt;Waiting time&lt;/h2&gt;
&lt;p&gt;The time we must wait before any trajectory can reach a given boundary is a classic hitting-time problem for the OU process that can be solved in several ways. Any of these basically start from PDE that must be satisfied for the hitting time (e.g. see Crispin Gardner, Stochastic Methods) for the OU process at stationary state (&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?T_t = 0\inline&quot;/&gt;&lt;/span&gt;),&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\tfrac{\sigma^2}{2} T_{xx} - x T_x = -1&quot; alt=&quot;\tfrac{\sigma^2}{2} T_{xx} - x T_x = -1&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;With the appropriate boundary conditions &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?T(L) = T(-L) = 0\inline&quot;/&gt;&lt;/span&gt;. A little integration (see Dynkin’s formula) shows this scales as &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\exp(L^2/\sigma^2)\inline&quot;/&gt;&lt;/span&gt; (Compare to the Brownian walk that doesn’t have to escape any pull, which escapes at rate &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?L^2/\sigma^2\inline&quot;/&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;h2 id=&quot;exit-time&quot;&gt;Exit time&lt;/h2&gt;
&lt;p&gt;Most trajectories will thus return many times to the origin (stable point) before finally escaping. But if we focus just on the part of the trajectory from some value near the origin, that eventually escapes without ever crossing the origin again,&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?u_t(x,t) dt = Pr\left(\textrm{exit from }(0; L]\textrm{in the interval } (t, t + dt) \textrm{without having crossed} 0 | X(0) = x\right)&quot; alt=&quot;u_t(x,t) dt = Pr\left(\textrm{exit from }(0; L]\textrm{in the interval } (t, t + dt) \textrm{without having crossed} 0 | X(0) = x\right)&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;We are interested in comparing the average time taken by trajectories exiting by time &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?t\inline&quot;/&gt;&lt;/span&gt; relative to the probability of exiting at all (i.e. as &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?t \to \infty\inline&quot;/&gt;&lt;/span&gt;),&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?T_c(x) = \frac{\int^{\infty}_0 t u_t(x,t) dt }{\lim_{t \to \infty} u(x,t) }&quot; alt=&quot;T_c(x) = \frac{\int^{\infty}_0 t u_t(x,t) dt }{\lim_{t \to \infty} u(x,t) }&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;From here we set up the classic hitting time solution for the OU for the &lt;em&gt;time-dependent&lt;/em&gt; PDE,&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?u_t = \frac{\sigma^2}{2} u_{xx} = x u_x&quot; alt=&quot;u_t = \frac{\sigma^2}{2} u_{xx} = x u_x&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;and with initial condition &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?u(x,t=0) = 0\inline&quot;/&gt;&lt;/span&gt;, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?u(0,t) = 0\inline&quot;/&gt;&lt;/span&gt;, and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?u(L, t) = 1\inline&quot;/&gt;&lt;/span&gt;. A bit of effort and an approximation to Dawson’s integral for &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?L \gg x\inline&quot;/&gt;&lt;/span&gt; leads Don to bound the mean time to exit,&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?T_c(x) &amp;lt; \frac{1}{\sigma} \log\left(\frac{L}{\sigma}\right)&quot; alt=&quot;T_c(x) &amp;lt; \frac{1}{\sigma} \log\left(\frac{L}{\sigma}\right)&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;as claimed.&lt;/p&gt;
&lt;h2 id=&quot;results-from-marcs-other-suggestion&quot;&gt;Results from Marc’s other suggestion&lt;/h2&gt;
&lt;p&gt;Marc also suggested exploring this by directly comparing steps left and right. A related way to measure the relative number of steps in the positive direction relative to the negative direction is Kendall’s tau rank correlation coefficient, which also looks at the number of increases relative to the number of decreases.&lt;/p&gt;
&lt;p&gt;I’ve computed this statistic for my sample trajectories and plotted as a histogram here. The negative skew shows the tendancy to decrease (which is the direction of the deviation I selected – smaller population sizes)&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8263/8621413072_3597b335fe_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;I’ve also computed the ratio of steps up to steps down and histogrammed that: like the above, it shows more steps down than up, though not as dramatic as I might think by any means. Have to think about the role of the step size between observations in formulating this perhaps.&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8113/8621413020_5d779e8b1f_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;For the sake of completeness:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/earlywarning/blob/8418a20cabf24786b54acc51eb508e9dbf3d1b37/inst/examples/trajectories.csv&quot;&gt;data for the trajectories is here&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/earlywarning/blob/8418a20cabf24786b54acc51eb508e9dbf3d1b37/inst/examples/beer.md&quot;&gt;code for the analysis is here&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I may try and add a demonstration of Ludwig’s result above when I get some more free time to fiddle; will just need to add some additional simulations of return trajectories.&lt;/p&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;C. Boettiger, A. Hastings, (2012) Early Warning Signals And The Prosecutor’S Fallacy. &lt;em&gt;Proceedings of The Royal Society B: Biological Sciences&lt;/em&gt; &lt;strong&gt;279&lt;/strong&gt; 4734-4739 &lt;a href=&quot;http://dx.doi.org/10.1098/rspb.2012.2085&quot;&gt;10.1098/rspb.2012.2085&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;R Lande, (1985) Expected time for random genetic drift of a population between stable phenotypic states. &lt;em&gt;Proceedings of the National Academy of Sciences&lt;/em&gt; &lt;a href=&quot;http://www.pnas.org/content/82/22/7641.abstract&quot;&gt;http://www.pnas.org/content/82/22/7641.abstract&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notebook Features: parsing linked data in the semantic notebook</title>
   <link href="/2013/04/04/notebook-parsing.html"/>
   <updated>2013-04-04T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/04/notebook-parsing</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;In a &lt;a href=&quot;/2011/05/08/building-a-semantic-notebook.html&quot;&gt;post a while back&lt;/a&gt; I originally put forward the idea of a semantic lab notebook. Semantics, or linked data, are among the most powerful concepts to emerge in online science for scholarly data organization and communication. I have slowly been adding and exploring new ways to introduce semantic concepts into the notebook, which I have documented along the way under my &lt;a href=&quot;http://www.carlboettiger.info/tags.html#semantics&quot;&gt;#semantics&lt;/a&gt; tag. In this post, rather than discuss how to generate the semantic data, I try to focus on some of the things we can &lt;em&gt;do&lt;/em&gt; with it. This really just scratches the surface of possibilities, but should at least illustrate the general idea.&lt;/p&gt;
&lt;p&gt;We will start with some very simple examples exploiting the semantics inherent in HTML5. We can then work up to richer examples that rely on XML-based parsing. The richest potential of the semantic notebook lies in leveraging the RDFa content, whose terms are defined as ontologies over which a machine can apply reasoning and formal logic against other web content (see, e.g. &lt;span class=&quot;showtooltip&quot; title=&quot;Shadbolt N, Berners-Lee T and Hall W (2006). The Semantic Web
Revisited. _Ieee Intelligent Systems_, *21*, pp. 96-101. ISSN
1541-1672,  http://dx.doi.org/10.1109/MIS.2006.62.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1109/MIS.2006.62&quot; rel=&quot;http://purl.org/spar/cito/obtainsBackgroundFrom&quot; &gt;Shadbolt &lt;em&gt;et. al.&lt;/em&gt; (2006)&lt;/a&gt;&lt;/span&gt; for further unformation). Though we show how to extract the and parse the RDF here, exploiting the RDF in the last example must wait to a later post.&lt;/p&gt;
&lt;h2 id=&quot;parsing-semantic-html&quot;&gt;Parsing semantic HTML&lt;/h2&gt;
&lt;p&gt;Our first set of examples will address parsing the semantic HTML directly. For background on how these elements are added to the notebook, see &lt;a href=&quot;/2012/10/14/semantic-lab-notebook.html&quot;&gt;this entry&lt;/a&gt;. We will use R with it’s excellent collection of web, XML parsing, and text-mining tools to take advantage of the semantic structure. First we load the required packages,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(RCurl)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(XML)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(tm)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(wordcloud)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(RColorBrewer)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can get a list of pages to download from the sitemap&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;pagelist &amp;lt;- &lt;span class=&quot;kw&quot;&gt;readLines&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;http://carlboettiger.info/sitemap.txt&amp;quot;&lt;/span&gt;)
pagelist &amp;lt;- pagelist[&lt;span class=&quot;kw&quot;&gt;grep&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;/201&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;d/&amp;quot;&lt;/span&gt;, pagelist)]  &lt;span class=&quot;co&quot;&gt;# drop non-posts)&lt;/span&gt;
pages &amp;lt;- &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(pagelist, getURLContent, &lt;span class=&quot;dt&quot;&gt;followlocation =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or, if an archive is available locally, (e.g. from figshare cache), we can read the files in directly.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;pages &amp;lt;- &lt;span class=&quot;kw&quot;&gt;system&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;ls ~/Documents/labnotebook/_site/2***/*/*/*.html&amp;quot;&lt;/span&gt;, 
    &lt;span class=&quot;dt&quot;&gt;intern =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We parse each of the pages as HTML so that we can manipulate them with XML tools&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;html &amp;lt;- &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(pages, htmlParse)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For instance, we can easily get the content of all entries:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;text &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(html, xpathSApply, &lt;span class=&quot;st&quot;&gt;&amp;quot;//article&amp;quot;&lt;/span&gt;, xmlValue)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can also extract metadata based on the semantic markup.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;titles &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(html, xpathSApply, &lt;span class=&quot;st&quot;&gt;&amp;quot;//title&amp;quot;&lt;/span&gt;, xmlValue)
categories &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(html, xpathSApply, &lt;span class=&quot;st&quot;&gt;&amp;quot;//node()[@class=&amp;#39;category&amp;#39;]&amp;quot;&lt;/span&gt;, 
    xmlValue)
tags &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(html, xpathSApply, &lt;span class=&quot;st&quot;&gt;&amp;quot;//node()[@class=&amp;#39;tag&amp;#39;]&amp;quot;&lt;/span&gt;, xmlValue)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;R makes it easy to summarize this data, e.g. by generating a table of the number of entries in each category, or a wordcloud of the tags.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;table&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;unlist&lt;/span&gt;(categories))&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;
 computation      ecology    evolution open-science     teaching 
          40          376          287           85           17 &lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;wordcloud&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;Corpus&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;VectorSource&lt;/span&gt;(tags)))&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8258/8620398951_0c2fd56e26_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;h3 id=&quot;extracting-citations&quot;&gt;Extracting citations&lt;/h3&gt;
&lt;p&gt;Citation information can be encoded&lt;/p&gt;
&lt;p&gt;We can perform more direct text mining as well. For instance, we extract all DOIs found in the text:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;doi_pattern = &lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;b(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?![&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;amp;&amp;#39;&amp;lt;&amp;gt;])&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;S)+)&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;b&amp;quot;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(gsubfn)
dois &amp;lt;- &lt;span class=&quot;kw&quot;&gt;strapply&lt;/span&gt;(text, doi_pattern, &lt;span class=&quot;dt&quot;&gt;perl =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;)  &lt;span class=&quot;co&quot;&gt;#text[-462]&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;head&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;sort&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;table&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;unlist&lt;/span&gt;(dois))))&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;
10.1002/(SICI)1520-6602(1998)1:1                 10.1002/bjs.6880 
                               1                                1 
                10.1002/etc.2140           10.1006/jtbi.1998.0660 
                               1                                1 
          10.1006/jtbi.2000.1080           10.1006/jtbi.2001.2299 
                               1                                1 &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or generate a wordcloud of the full text&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;
carl &amp;lt;- &lt;span class=&quot;kw&quot;&gt;Corpus&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;VectorSource&lt;/span&gt;(text))
carl &amp;lt;- &lt;span class=&quot;kw&quot;&gt;tm_map&lt;/span&gt;(carl, removePunctuation)
carl &amp;lt;- &lt;span class=&quot;kw&quot;&gt;tm_map&lt;/span&gt;(carl, tolower)
carl &amp;lt;- &lt;span class=&quot;kw&quot;&gt;tm_map&lt;/span&gt;(carl, function(x) &lt;span class=&quot;kw&quot;&gt;removeWords&lt;/span&gt;(x, &lt;span class=&quot;kw&quot;&gt;stopwords&lt;/span&gt;()))

carl.tdm &amp;lt;- &lt;span class=&quot;kw&quot;&gt;TermDocumentMatrix&lt;/span&gt;(carl)
carl.m &amp;lt;- &lt;span class=&quot;kw&quot;&gt;as.matrix&lt;/span&gt;(carl.tdm)
carl.v &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sort&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;rowSums&lt;/span&gt;(carl.m), &lt;span class=&quot;dt&quot;&gt;decreasing =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;)
carl.d &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;word =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(carl.v), &lt;span class=&quot;dt&quot;&gt;freq =&lt;/span&gt; carl.v)


&lt;span class=&quot;kw&quot;&gt;wordcloud&lt;/span&gt;(carl.d$word, carl.d$freq, &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;8&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.4&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;min.freq =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;, 
    &lt;span class=&quot;dt&quot;&gt;max.words =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;random.order =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;rot.per =&lt;/span&gt; &lt;span class=&quot;fl&quot;&gt;0.15&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;colors =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;brewer.pal&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;8&lt;/span&gt;, 
        &lt;span class=&quot;st&quot;&gt;&amp;quot;Dark2&amp;quot;&lt;/span&gt;))&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8385/8621498714_2fe3e04226_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;rdfa-parsing&quot;&gt;RDFa parsing&lt;/h2&gt;
&lt;p&gt;RDF triples are the mainstay of semantic, linked data. Unlike the more text-mining oriented examples above, data in this format follows a strict and universal standard which allows a machine to identify meaning rather precisely. Critically, this allows one to automatically link data appearing in the notebook to data elsewhere on the web without the ambiguities of natural language that for instance, might confuse the animal jaguar with the car.&lt;/p&gt;
&lt;p&gt;RDFa is a way of adding these precise statements to HTML, again see the &lt;a href=&quot;/2012/10/14/semantic-lab-notebook.html&quot;&gt;earlier entry&lt;/a&gt; on how this is done. The technically inclined will note that the namespaces of the RDFa itself are not accessible in the XML parsing we used above, since they do not correspond to nodes or attributes, but appear only in the values of attributes. Fortunately, there are many excellent tools to extract this RDFa data, turning it into the XML formatted RDF triples we need. e can perform this using the &lt;a href=&quot;http://any23.org&quot;&gt;Any23&lt;/a&gt; API&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;download.file&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;paste&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;http://any23.org/rdfxml&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;http://carlboettiger.info&amp;quot;&lt;/span&gt;, 
    &lt;span class=&quot;dt&quot;&gt;sep =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;/&amp;quot;&lt;/span&gt;), &lt;span class=&quot;st&quot;&gt;&amp;quot;temp.xml&amp;quot;&lt;/span&gt;)
doc &amp;lt;- &lt;span class=&quot;kw&quot;&gt;xmlParse&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;temp.xml&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Which creates a beautiful RDF XML file of all linked data found in the entry.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;doc&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&amp;lt;rdf:RDF xmlns:xhtml=&amp;quot;http://www.w3.org/1999/xhtml/vocab#&amp;quot; xmlns:dcterms=&amp;quot;http://purl.org/dc/terms/&amp;quot; xmlns:rdf=&amp;quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#&amp;quot;&amp;gt;
  &amp;lt;rdf:Description rdf:about=&amp;quot;http://www.carlboettiger.info/&amp;quot;&amp;gt;
    &amp;lt;dcterms:title xml:lang=&amp;quot;en&amp;quot;&amp;gt;Carl Boettiger&amp;lt;/dcterms:title&amp;gt;
    &amp;lt;xhtml:license rdf:resource=&amp;quot;http://creativecommons.org/publicdomain/zero/1.0/&amp;quot;/&amp;gt;
    &amp;lt;dcterms:title xml:lang=&amp;quot;en&amp;quot;&amp;gt;Carl Boettiger&amp;lt;/dcterms:title&amp;gt;
    &amp;lt;dcterms:creator xml:lang=&amp;quot;en&amp;quot;&amp;gt;Carl Boettiger&amp;lt;/dcterms:creator&amp;gt;
    &amp;lt;dcterms:date xml:lang=&amp;quot;en&amp;quot;&amp;gt;2013-04-04T11:07:14-07:00&amp;lt;/dcterms:date&amp;gt;
    &amp;lt;dcterms:format xml:lang=&amp;quot;en&amp;quot;&amp;gt;text/html&amp;lt;/dcterms:format&amp;gt;
    &amp;lt;dcterms:language xml:lang=&amp;quot;en&amp;quot;&amp;gt;en&amp;lt;/dcterms:language&amp;gt;
    &amp;lt;dcterms:identifier xml:lang=&amp;quot;en&amp;quot;&amp;gt;/index.html&amp;lt;/dcterms:identifier&amp;gt;
    &amp;lt;dcterms:rights xml:lang=&amp;quot;en&amp;quot;&amp;gt;CC0&amp;lt;/dcterms:rights&amp;gt;
    &amp;lt;dcterms:source xml:lang=&amp;quot;en&amp;quot;&amp;gt;Lab Notebook&amp;lt;/dcterms:source&amp;gt;
    &amp;lt;dcterms:subject xml:lang=&amp;quot;en&amp;quot;&amp;gt;Ecology&amp;lt;/dcterms:subject&amp;gt;
    &amp;lt;dcterms:type xml:lang=&amp;quot;en&amp;quot;&amp;gt;website&amp;lt;/dcterms:type&amp;gt;
    &amp;lt;title xmlns=&amp;quot;http://ogp.me/ns#&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;Carl Boettiger&amp;lt;/title&amp;gt;
    &amp;lt;author xmlns=&amp;quot;http://ogp.me/ns#&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;http://www.carlboettiger.info/index.html#me&amp;lt;/author&amp;gt;
    &amp;lt;first_name xmlns=&amp;quot;http://ogp.me/ns/profile#&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;Carl&amp;lt;/first_name&amp;gt;
    &amp;lt;last_name xmlns=&amp;quot;http://ogp.me/ns/profile#&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;Boettiger&amp;lt;/last_name&amp;gt;
    &amp;lt;published_time xmlns=&amp;quot;http://ogp.me/ns/article#&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;2013-04-04T11:07:14-07:00&amp;lt;/published_time&amp;gt;
    &amp;lt;site_name xmlns=&amp;quot;http://ogp.me/ns#&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;Lab Notebook&amp;lt;/site_name&amp;gt;
    &amp;lt;url xmlns=&amp;quot;http://ogp.me/ns#&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;http://www.carlboettiger.info/index.html&amp;lt;/url&amp;gt;
    &amp;lt;type xmlns=&amp;quot;http://ogp.me/ns#&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;website&amp;lt;/type&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:about=&amp;quot;http://carlboettiger.info#me&amp;quot;&amp;gt;
    &amp;lt;rdf:type rdf:resource=&amp;quot;http://xmlns.com/foaf/0.1/Person&amp;quot;/&amp;gt;
    &amp;lt;rdf:type rdf:resource=&amp;quot;http://schema.org/Person#Person&amp;quot;/&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:about=&amp;quot;http://www.carlboettiger.info/assets/img/carlboettiger.png&amp;quot;&amp;gt;
    &amp;lt;depiction xmlns=&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot; xml:lang=&amp;quot;en&amp;quot;/&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:about=&amp;quot;http://carlboettiger.info&amp;quot;&amp;gt;
    &amp;lt;homepage xmlns=&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot; rdf:resource=&amp;quot;http://carlboettiger.info&amp;quot;/&amp;gt;
    &amp;lt;url xmlns=&amp;quot;http://schema.org/Person#&amp;quot; rdf:resource=&amp;quot;http://carlboettiger.info&amp;quot;/&amp;gt;
    &amp;lt;name xmlns=&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;Carl Boettiger&amp;lt;/name&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:about=&amp;quot;http://carlboettiger.info#me&amp;quot;&amp;gt;
    &amp;lt;jobTitle xmlns=&amp;quot;http://schema.org/Person#&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;a post-doctoral researcher&amp;lt;/jobTitle&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:nodeID=&amp;quot;node17eprp1n4x899515&amp;quot;&amp;gt;
    &amp;lt;rdf:type rdf:resource=&amp;quot;http://xmlns.com/foaf/0.1/Person&amp;quot;/&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:about=&amp;quot;http://carlboettiger.info#me&amp;quot;&amp;gt;
    &amp;lt;knows xmlns=&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot; rdf:nodeID=&amp;quot;node17eprp1n4x899515&amp;quot;/&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:nodeID=&amp;quot;node17eprp1n4x899515&amp;quot;&amp;gt;
    &amp;lt;homepage xmlns=&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot; rdf:resource=&amp;quot;http://users.soe.ucsc.edu/~msmangel/&amp;quot;/&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:about=&amp;quot;http://carlboettiger.info#me&amp;quot;&amp;gt;
    &amp;lt;knows xmlns=&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot; rdf:nodeID=&amp;quot;node17eprp1n4x899515&amp;quot;/&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:about=&amp;quot;http://users.soe.ucsc.edu/~msmangel/&amp;quot;&amp;gt;
    &amp;lt;name xmlns=&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;Marc Mangel&amp;lt;/name&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:nodeID=&amp;quot;node17eprp1n4x899516&amp;quot;&amp;gt;
    &amp;lt;rdf:type rdf:resource=&amp;quot;http://xmlns.com/foaf/0.1/Person&amp;quot;/&amp;gt;
    &amp;lt;homepage xmlns=&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot; rdf:resource=&amp;quot;http://swfsc.noaa.gov/staff.aspx?&amp;amp;amp;id=17294&amp;quot;/&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:about=&amp;quot;http://swfsc.noaa.gov/staff.aspx?&amp;amp;amp;id=17294&amp;quot;&amp;gt;
    &amp;lt;name xmlns=&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;Steve Munch&amp;lt;/name&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:about=&amp;quot;http://carlboettiger.info#me&amp;quot;&amp;gt;
    &amp;lt;affiliation xmlns=&amp;quot;http://schema.org/Person#&amp;quot; rdf:resource=&amp;quot;http://boe.ucsc.edu/~msmangel/CSTAR.html&amp;quot;/&amp;gt;
    &amp;lt;workplaceHomepage xmlns=&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot; rdf:resource=&amp;quot;http://www.ucsc.edu/&amp;quot;/&amp;gt;
    &amp;lt;weblog xmlns=&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot; rdf:resource=&amp;quot;http://www.carlboettiger.info/lab-notebook.html&amp;quot;/&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:nodeID=&amp;quot;node17eprp1n4x899517&amp;quot;&amp;gt;
    &amp;lt;rdf:type rdf:resource=&amp;quot;http://schema.org/PostalAddress&amp;quot;/&amp;gt;
    &amp;lt;address xmlns=&amp;quot;http://schema.org/Person#&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;Center for Stock Assessment Research, 110 Shaffer Rd, Santa Cruz, CA 95050, USA&amp;lt;/address&amp;gt;
    &amp;lt;streetAddress xmlns=&amp;quot;http://schema.org/PostalAddress/&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;Center for Stock Assessment Research, 110 Shaffer Rd&amp;lt;/streetAddress&amp;gt;
    &amp;lt;addressLocality xmlns=&amp;quot;http://schema.org/PostalAddress/&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;Santa Cruz&amp;lt;/addressLocality&amp;gt;
    &amp;lt;addressRegion xmlns=&amp;quot;http://schema.org/PostalAddress/&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;CA&amp;lt;/addressRegion&amp;gt;
    &amp;lt;postalCode xmlns=&amp;quot;http://schema.org/PostalAddress/&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;95050&amp;lt;/postalCode&amp;gt;
    &amp;lt;addressCountry xmlns=&amp;quot;http://schema.org/PostalAddress/&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;USA&amp;lt;/addressCountry&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:about=&amp;quot;https://orcid.org/0000-0002-1642-628X&amp;quot;&amp;gt;
    &amp;lt;orcid xmlns=&amp;quot;http://purl.org/spar/datacite/&amp;quot; rdf:resource=&amp;quot;https://orcid.org/0000-0002-1642-628X&amp;quot;/&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:about=&amp;quot;http://www.carlboettiger.info#me&amp;quot;&amp;gt;
    &amp;lt;rdf:type rdf:resource=&amp;quot;http://xmlns.com/foaf/0.1/Person&amp;quot;/&amp;gt;
    &amp;lt;account xmlns=&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot; rdf:resource=&amp;quot;http://www.cloudflare.com/email-protection#f497969b9180809d93b49399959d98da979b99&amp;quot;/&amp;gt;
    &amp;lt;account xmlns=&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot; rdf:resource=&amp;quot;https://twitter.com/cboettig&amp;quot;/&amp;gt;
    &amp;lt;account xmlns=&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot; rdf:resource=&amp;quot;https://github.com/cboettig&amp;quot;/&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
  &amp;lt;rdf:Description rdf:about=&amp;quot;http://www.carlboettiger.info/&amp;quot;&amp;gt;
    &amp;lt;license xmlns=&amp;quot;http://www.carlboettiger.info/&amp;quot; rdf:resource=&amp;quot;http://creativecommons.org/publicdomain/zero/1.0/&amp;quot;/&amp;gt;
    &amp;lt;license xmlns=&amp;quot;http://creativecommons.org/ns#&amp;quot; rdf:resource=&amp;quot;http://creativecommons.org/publicdomain/zero/1.0/&amp;quot;/&amp;gt;
  &amp;lt;/rdf:Description&amp;gt;
&amp;lt;/rdf:RDF&amp;gt;
 &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can now explore this data using the XML tools illustrated above. The rigidity of the XML rather than HTML parsing and the use of namespaces gives us greater precision.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Further Examples Managing Tipping Points With Gp</title>
   <link href="/2013/04/03/further-examples-managing-tipping-points-with-gp.html"/>
   <updated>2013-04-03T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/03/further-examples-managing-tipping-points-with-gp</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;See also:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;http://www.carlboettiger.info/2012/12/20/results-comparing-gp-to-parametric.html&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example with fixed priors on hyperparameters, fixed model type.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;co&quot;&gt;#inv gamma has mean b / (a - 1) (assuming a&amp;gt;1) and variance b ^ 2 / ((a - 2) * (a - 1) ^ 2) (assuming a&amp;gt;2)&lt;/span&gt;
s2.p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;)  
tau2.p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)
d.p = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;)
nug.p = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;) &lt;span class=&quot;co&quot;&gt;# gamma mean&lt;/span&gt;
s2_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dinvgamma&lt;/span&gt;(x, s2.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], s2.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;])
tau2_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dinvgamma&lt;/span&gt;(x, tau2.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], tau2.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;])
d_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, d.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; d.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]) + &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, d.p[&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; d.p[&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;])
nug_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, nug.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; nug.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]) + &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, nug.p[&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; nug.p[&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;])
beta0_prior &amp;lt;- function(x, tau) &lt;span class=&quot;kw&quot;&gt;dnorm&lt;/span&gt;(x, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, tau)
beta = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)
priors &amp;lt;- &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;s2 =&lt;/span&gt; s2_prior, &lt;span class=&quot;dt&quot;&gt;tau2 =&lt;/span&gt; tau2_prior, &lt;span class=&quot;dt&quot;&gt;beta0 =&lt;/span&gt; dnorm, &lt;span class=&quot;dt&quot;&gt;nug =&lt;/span&gt; nug_prior, &lt;span class=&quot;dt&quot;&gt;d =&lt;/span&gt; d_prior, &lt;span class=&quot;dt&quot;&gt;ldetK =&lt;/span&gt; function(x) &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;profit = function(x,h) &lt;span class=&quot;kw&quot;&gt;pmin&lt;/span&gt;(x, h)
delta &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.01&lt;/span&gt;
OptTime = &lt;span class=&quot;dv&quot;&gt;20&lt;/span&gt;  &lt;span class=&quot;co&quot;&gt;# stationarity with unstable models is tricky thing&lt;/span&gt;
reward = &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;
xT &amp;lt;- &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;f &amp;lt;- RickerAllee
&lt;span class=&quot;co&quot;&gt;# c(5, 10, 5) is 2-cycle, c(5.5, 10, 5) is 6 cycle, 5.3 is about 4&lt;/span&gt;
p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;) 
K &amp;lt;- &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;
allee &amp;lt;- &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;sigma_g &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.05&lt;/span&gt;
sigma_m &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.0&lt;/span&gt;
z_g = function() &lt;span class=&quot;kw&quot;&gt;rlnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, sigma_g)
z_m = function() &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;+(&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;runif&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)-&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) * sigma_m
x_grid &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;1.5&lt;/span&gt; * K, &lt;span class=&quot;dt&quot;&gt;length=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;101&lt;/span&gt;)
h_grid &amp;lt;- x_grid&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With parameters 2, 10, 5.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;seed_i &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;
  Xo &amp;lt;- K &lt;span class=&quot;co&quot;&gt;# observations start from&lt;/span&gt;
  x0 &amp;lt;- Xo &lt;span class=&quot;co&quot;&gt;# simulation under policy starts from&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;  obs &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sim_obs&lt;/span&gt;(Xo, z_g, f, p, &lt;span class=&quot;dt&quot;&gt;Tobs=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;35&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;nz=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;15&lt;/span&gt;, 
                 &lt;span class=&quot;dt&quot;&gt;harvest =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;sort&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;rep&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, .&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;length=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;7&lt;/span&gt;), &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;)), &lt;span class=&quot;dt&quot;&gt;seed =&lt;/span&gt; seed_i)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;  alt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;par_est&lt;/span&gt;(obs,  &lt;span class=&quot;dt&quot;&gt;init =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;r=&lt;/span&gt;p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;K=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;mean&lt;/span&gt;(obs$x), &lt;span class=&quot;dt&quot;&gt;s=&lt;/span&gt;sigma_g))
  est &amp;lt;- &lt;span class=&quot;kw&quot;&gt;par_est_allee&lt;/span&gt;(obs, f, p,  &lt;span class=&quot;dt&quot;&gt;init =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;mean&lt;/span&gt;(obs$x), &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;s =&lt;/span&gt; sigma_g))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Which estimates a Ricker model with &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?r =\inline&quot;/&gt;&lt;/span&gt; 2, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?K =\inline&quot;/&gt;&lt;/span&gt; 6.77, and the Allen allee model with &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?r =\inline&quot;/&gt;&lt;/span&gt; 2, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?K =\inline&quot;/&gt;&lt;/span&gt; 6.77 and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?C =\inline&quot;/&gt;&lt;/span&gt; 2.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;  gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;bgp&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;X=&lt;/span&gt;obs$x, &lt;span class=&quot;dt&quot;&gt;XX=&lt;/span&gt;x_grid, &lt;span class=&quot;dt&quot;&gt;Z=&lt;/span&gt;obs$y, &lt;span class=&quot;dt&quot;&gt;verb=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,
          &lt;span class=&quot;dt&quot;&gt;meanfn=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;constant&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;bprior=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;b0&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;BTE=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;2000&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;16000&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;),
          &lt;span class=&quot;dt&quot;&gt;m0r1=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;corr=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;exp&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;trace=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;, 
          &lt;span class=&quot;dt&quot;&gt;beta =&lt;/span&gt; beta, &lt;span class=&quot;dt&quot;&gt;s2.p =&lt;/span&gt; s2.p, &lt;span class=&quot;dt&quot;&gt;d.p =&lt;/span&gt; d.p, &lt;span class=&quot;dt&quot;&gt;nug.p =&lt;/span&gt; nug.p, &lt;span class=&quot;dt&quot;&gt;tau2.p =&lt;/span&gt; tau2.p,
          &lt;span class=&quot;dt&quot;&gt;s2.lam =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;d.lam =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;nug.lam =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;tau2.lam =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;)      
  &lt;span class=&quot;kw&quot;&gt;gp_plot&lt;/span&gt;(gp, f, p, est$f, est$p, alt$f, alt$p, x_grid, obs, seed_i)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8535/8617059578_b528a1e51c_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;  &lt;span class=&quot;kw&quot;&gt;posteriors_plot&lt;/span&gt;(gp, priors) &lt;span class=&quot;co&quot;&gt;# needs trace=TRUE!&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8540/8617059782_197bdf7edd_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;  OPT &amp;lt;- &lt;span class=&quot;kw&quot;&gt;optimal_policy&lt;/span&gt;(gp, f, est$f, alt$f,
                        p, est$p, alt$p,
                        x_grid, h_grid, sigma_g, 
                        sigma_g, sigma_g, &lt;span class=&quot;co&quot;&gt;# est$sigma_g, alt$sigma_g, but those ests are poor&lt;/span&gt;
                        delta, xT, profit, reward, OptTime)
  &lt;span class=&quot;kw&quot;&gt;plot_policies&lt;/span&gt;(x_grid, OPT$gp_D, OPT$est_D, OPT$true_D, OPT$alt_D)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8265/8617060456_71afc3e4eb_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;dt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;simulate_opt&lt;/span&gt;(OPT, f, p, x_grid, h_grid, x0, z_g, profit)
&lt;span class=&quot;kw&quot;&gt;sim_plots&lt;/span&gt;(dt, &lt;span class=&quot;dt&quot;&gt;seed=&lt;/span&gt;seed_i)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8113/8617060842_7c088c12d1_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;profits_stats&lt;/span&gt;(dt)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;       method     V1     sd
1:         GP 19.337 1.6314
2: Parametric  6.446 0.3384
3:       True 20.701 1.8012
4: Structural  7.650 0.0000&lt;/code&gt;&lt;/pre&gt;
</content>
 </entry>
 
 <entry>
   <title>Monday   Tuesday</title>
   <link href="/2013/04/02/Monday---Tuesday.html"/>
   <updated>2013-04-02T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/04/02/Monday---Tuesday</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;writing&quot;&gt;Writing&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;still working on non-parametric bayes draft today..&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reviewing&quot;&gt;Reviewing&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;review sent to PRSB&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Came across this rather nice summary of big data in Ecology through some buzz in the twittersphere&lt;span class=&quot;showtooltip&quot; title=&quot;Hampton S, Strasser C, Tewksbury J, Gram W, Budden A, Batcheller
A, Duke C and Porter J (2013). Big Data And The Future of
Ecology. _Frontiers in Ecology And The Environment_, *11*, pp.
156-162. ISSN 1540-9295,  http://dx.doi.org/10.1890/120103.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1890/120103&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Hampton &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt; .&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;More fishery managment controversy with &lt;span class=&quot;showtooltip&quot; title=&quot;Halpern B, Gaines S, Kleisner K, Longo C, Pauly D, Rosenberg A,
Samhouri J and Zeller D (2013). Halpern et al. Reply. _Nature_,
*495*, pp. E7-E7. ISSN 0028-0836, 
http://dx.doi.org/10.1038/nature11975.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1038/nature11975&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Halpern &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt; critiquing the ‘ocean food provision index’ from Nature last year, and a subset of that team replying &lt;span class=&quot;showtooltip&quot; title=&quot;Halpern B, Gaines S, Kleisner K, Longo C, Pauly D, Rosenberg A,
Samhouri J and Zeller D (2013). Halpern et al. Reply. _Nature_,
*495*, pp. E7-E7. ISSN 0028-0836, 
http://dx.doi.org/10.1038/nature11975.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1038/nature11975&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Halpern &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt; . Seems to fall along the usual divisions of whether to use or ignore imperfect data; no doubt the truth lies somewhere in between.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Looks like &lt;span class=&quot;showtooltip&quot; title=&quot;Cavanaugh K, Kendall B, Siegel D, Reed D, Alberto F and Assis J
(2013). Synchrony in Dynamics of Giant Kelp Forests is Driven by
Both Local Recruitment And Regional Environmental Controls.
_Ecology_, *94*, pp. 499-509. ISSN 0012-9658, 
http://dx.doi.org/10.1890/12-0268.1.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1890/12-0268.1&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Cavanaugh &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt; have a nice synchrony paper in kelp forests which I’m looking forward to reading.&lt;/li&gt;
&lt;li&gt;Nonlinear forecasting strikes again in PNAS, &lt;span class=&quot;showtooltip&quot; title=&quot;Deyle E, Fogarty M, Hsieh C, Kaufman L, MacCall A, Munch S,
Perretti C, Ye H and Sugihara G (2013). Predicting Climate
Effects on Pacific Sardine. _Proceedings of The National Academy
of Sciences_. ISSN 0027-8424, 
http://dx.doi.org/10.1073/pnas.1215506110.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1215506110&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Deyle &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt; Predicting climate effects on sardine with the usual suspects. May disentangle physical forcing from ecological dynamics.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;showtooltip&quot; title=&quot;Halpern B, Klein C, Brown C, Beger M, Grantham H, Mangubhai S,
Ruckelshaus M, Tulloch V, Watts M, White C and Possingham H
(2013). Achieving The Triple Bottom Line in The Face of Inherent
Trade-Offs Among Social Equity, Economic Return, And
Conservation. _Proceedings of The National Academy of Sciences_.
ISSN 0027-8424,  http://dx.doi.org/10.1073/pnas.1217689110.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1217689110&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Halpern &lt;em&gt;et. al.&lt;/em&gt; (2013b)&lt;/a&gt;&lt;/span&gt; discuss the classic problem of optimization in conservation: balancing social equity, economic return and conservation needs.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ROpenSci is mentioned in a letter to the editor published in Ecotoxicology, (&lt;span class=&quot;showtooltip&quot; title=&quot;Schäfer R, Bundschuh M, Focks A and von der Ohe P (2013). to The
Editor. _Environmental Toxicology And Chemistry_, *32*, pp.
734-735.  http://dx.doi.org/10.1002/etc.2140.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1002/etc.2140&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Schäfer &lt;em&gt;et. al.&lt;/em&gt; 2013&lt;/a&gt;&lt;/span&gt; ).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;Kyle C. Cavanaugh, Bruce E. Kendall, David A. Siegel, Daniel C. Reed, Filipe Alberto, Jorge Assis, (2013) Synchrony in Dynamics of Giant Kelp Forests is Driven by Both Local Recruitment And Regional Environmental Controls. &lt;em&gt;Ecology&lt;/em&gt; &lt;strong&gt;94&lt;/strong&gt; 499-509 &lt;a href=&quot;http://dx.doi.org/10.1890/12-0268.1&quot;&gt;10.1890/12-0268.1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;E. R. Deyle, M. Fogarty, C.-h. Hsieh, L. Kaufman, A. D. MacCall, S. B. Munch, C. T. Perretti, H. Ye, G. Sugihara, (2013) Predicting Climate Effects on Pacific Sardine. &lt;em&gt;Proceedings of The National Academy of Sciences&lt;/em&gt; &lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1215506110&quot;&gt;10.1073/pnas.1215506110&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Benjamin S. Halpern, Steven D. Gaines, Kristin Kleisner, Catherine Longo, Daniel Pauly, Andrew A. Rosenberg, Jameal F. Samhouri, Dirk Zeller, (2013) Halpern et al. Reply. &lt;em&gt;Nature&lt;/em&gt; &lt;strong&gt;495&lt;/strong&gt; E7-E7 &lt;a href=&quot;http://dx.doi.org/10.1038/nature11975&quot;&gt;10.1038/nature11975&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;B. S. Halpern, C. J. Klein, C. J. Brown, M. Beger, H. S. Grantham, S. Mangubhai, M. Ruckelshaus, V. J. Tulloch, M. Watts, C. White, H. P. Possingham, (2013) Achieving The Triple Bottom Line in The Face of Inherent Trade-Offs Among Social Equity, Economic Return, And Conservation. &lt;em&gt;Proceedings of The National Academy of Sciences&lt;/em&gt; &lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1217689110&quot;&gt;10.1073/pnas.1217689110&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Stephanie E Hampton, Carly A Strasser, Joshua J Tewksbury, Wendy K Gram, Amber E Budden, Archer L Batcheller, Clifford S Duke, John H Porter, (2013) Big Data And The Future of Ecology. &lt;em&gt;Frontiers in Ecology And The Environment&lt;/em&gt; &lt;strong&gt;11&lt;/strong&gt; 156-162 &lt;a href=&quot;http://dx.doi.org/10.1890/120103&quot;&gt;10.1890/120103&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ralf B. Schäfer, Mirco Bundschuh, Andreas Focks, Peter C. von der Ohe, (2013) to The Editor. &lt;em&gt;Environmental Toxicology And Chemistry&lt;/em&gt; &lt;strong&gt;32&lt;/strong&gt; 734-735 &lt;a href=&quot;http://dx.doi.org/10.1002/etc.2140&quot;&gt;10.1002/etc.2140&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Research</title>
   <link href="/2013/03/26/research.html"/>
   <updated>2013-03-26T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/03/26/research</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;nonparametric-bayes&quot;&gt;nonparametric-bayes&lt;/h2&gt;
&lt;p&gt;writing writing …&lt;/p&gt;
&lt;h2 id=&quot;multiple-uncertainty&quot;&gt;multiple-uncertainty&lt;/h2&gt;
&lt;p&gt;Fixed matlab implementation. (Some fun with matrix transposes in translating from R. &lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty/issues/4&quot;&gt;#4&lt;/a&gt;) See:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty/blob/0706ffd2a32e12087a6160fa250e4f3446c6b882/inst/matlab/multiple_uncertainty.m&quot;&gt;multiple-uncertainty.m&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty/blob/6f772fb4309bfb24b29a5559551733743a23b738/inst/matlab/testing.m&quot;&gt;example&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Compare to&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty/blob/e3506f392ddbee8e33fb97bbe1d6699aee4eadea/R/multiple_uncertainty.R&quot;&gt;R algorithm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty/blob/e3506f392ddbee8e33fb97bbe1d6699aee4eadea/inst/tests/matrices.R&quot;&gt;example&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Matlab code shows the same pattern in which growth noise results in constant escapement, but either implementation or measurement noise cause deviations from this rule (most dramatic in the case of implementation uncertainty).&lt;/p&gt;
&lt;h2 id=&quot;notebook&quot;&gt;Notebook&lt;/h2&gt;
&lt;p&gt;Some feedback and ideas from Noam, such as landing pages &lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/78&quot;&gt;#77&lt;/a&gt; and inline intro &lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/78&quot;&gt;#78&lt;/a&gt;. Also fixed history links and SHA links are now unique to their pages &lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/67&quot;&gt;#67&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Research</title>
   <link href="/2013/03/25/research.html"/>
   <updated>2013-03-25T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/03/25/research</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;(&lt;span class=&quot;showtooltip&quot; title=&quot;Schreiber S and Killingback T (2013). Spatial Heterogeneity
Promotes Coexistence of Rock–Paper–Scissors Metacommunities.
_Theoretical Population Biology_. ISSN 00405809, 
http://dx.doi.org/10.1016/j.tpb.2013.02.004.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1016/j.tpb.2013.02.004&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Schreiber &amp;amp; Killingback, 2013&lt;/a&gt;&lt;/span&gt; )&lt;/li&gt;
&lt;li&gt;(&lt;span class=&quot;showtooltip&quot; title=&quot;Warren D (2013). ‘Niche Modeling’: That Uncomfortable Sensation
Means it'S Working. A Reply to Mcinerny And Etienne. _Trends in
Ecology &amp; Evolution_, *28*. ISSN 01695347, 
http://dx.doi.org/10.1016/j.tree.2013.02.003.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2013.02.003&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Warren, 2013&lt;/a&gt;&lt;/span&gt; )&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;notebook&quot;&gt;Notebook&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Added SHA hashes. See notebook Issues &lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/67&quot;&gt;#67&lt;/a&gt; for details.&lt;/li&gt;
&lt;li&gt;modification date. &lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/74&quot;&gt;#74&lt;/a&gt;, also involved resolving page path robustly, &lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/73&quot;&gt;#73&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;analytics on history button, layout &lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/72&quot;&gt;#72&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;push dreamhost-based images to flickr See &lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/75&quot;&gt;#75&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;prosecutor&quot;&gt;prosecutor&lt;/h2&gt;
&lt;p&gt;Run with OU based data. Draw from sde package.&lt;/p&gt;
&lt;h2 id=&quot;packages&quot;&gt;Packages&lt;/h2&gt;
&lt;h3 id=&quot;knitcitations&quot;&gt;Knitcitations&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Feature request for additional markup for page ranges &lt;a href=&quot;https://github.com/cboettig/knitcitations/issues/32&quot;&gt;#32&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;rfigshare&quot;&gt;rfigshare&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Handle pull request for rfigshare&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;code-tricks-notes-on-merging-select-files-from-pull-request&quot;&gt;code-tricks: notes on merging select files from pull request&lt;/h4&gt;
&lt;p&gt;Pull request included changes to files we don’t want to change. To address this, we separate fetch and merge with &lt;code&gt;--no-commit&lt;/code&gt;. First, fetch the remote repository:&lt;/p&gt;
&lt;pre class=&quot;sourceCode bash&quot;&gt;&lt;code class=&quot;sourceCode bash&quot;&gt;git fetch https://github.com/jcolomb/rfigshare master&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The fetch is at &lt;code&gt;FETCH_HEAD&lt;/code&gt; as it tells us in the console.&lt;/p&gt;
&lt;p&gt;Now we merge the changes without committing them,&lt;/p&gt;
&lt;pre class=&quot;sourceCode bash&quot;&gt;&lt;code class=&quot;sourceCode bash&quot;&gt;git merge --no-commit FETCH_HEAD&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So the changes are all made, but not committed. We can simply unstage the changes we do not want. Since we only want one file, lets start by unstaging all commits&lt;/p&gt;
&lt;pre class=&quot;sourceCode bash&quot;&gt;&lt;code class=&quot;sourceCode bash&quot;&gt;git reset --&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So all changes are in our working directory as if we had just made them, but not told git to do anything yet. We can now drop any of the files we did not want to change back to their state at last commit (HEAD), for instance,&lt;/p&gt;
&lt;pre class=&quot;sourceCode bash&quot;&gt;&lt;code class=&quot;sourceCode bash&quot;&gt;git checkout HEAD inst/examples/tutorial.Rmd&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;while staging the changes to the file we want changed:&lt;/p&gt;
&lt;pre class=&quot;sourceCode bash&quot;&gt;&lt;code class=&quot;sourceCode bash&quot;&gt;git add R/fs_update.R&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and finally commit and push the changes.&lt;/p&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Sebastian J. Schreiber, Timothy P. Killingback, (2013) Spatial Heterogeneity Promotes Coexistence of Rock–Paper–Scissors Metacommunities. &lt;em&gt;Theoretical Population Biology&lt;/em&gt; &lt;a href=&quot;http://dx.doi.org/10.1016/j.tpb.2013.02.004&quot;&gt;10.1016/j.tpb.2013.02.004&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Dan L. Warren, (2013) ‘Niche Modeling’: That Uncomfortable Sensation Means it’S Working. A Reply to Mcinerny And Etienne. &lt;em&gt;Trends in Ecology &amp;amp; Evolution&lt;/em&gt; &lt;strong&gt;28&lt;/strong&gt; &lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2013.02.003&quot;&gt;10.1016/j.tree.2013.02.003&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Research</title>
   <link href="/2013/03/22/research.html"/>
   <updated>2013-03-22T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/03/22/research</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;multiple-uncertainty&quot;&gt;multiple-uncertainty&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Fixed issues with translation to matlab and &lt;code&gt;applyfun&lt;/code&gt;. Element-wise calls can use meshgrid arguments directly, and one can force functions to use element-wise operations with &lt;code&gt;bxfun&lt;/code&gt;. So the following are equivalent: :&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;sourceCode matlab&quot;&gt;&lt;code class=&quot;sourceCode matlab&quot;&gt;[X, Y] = meshgrid(x,y)
applyfun(@min, X, Y)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;pre class=&quot;sourceCode matlab&quot;&gt;&lt;code class=&quot;sourceCode matlab&quot;&gt;function out = element_min(x,y) bxfun(@min, x, y)
element_min(X, Y)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Meanwhile my challenge with additional arguments to &lt;code&gt;applyfun&lt;/code&gt; can be circumvented with an inline function,&lt;/p&gt;
&lt;pre class=&quot;sourceCode matlab&quot;&gt;&lt;code class=&quot;sourceCode matlab&quot;&gt;applyfun(@(x,y) ssum(x,y, additional_arg), X, Y)&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;In other developments, may have missed a rownormalization on growth noise.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Time to run and compare R and matlab codes and send to Jim.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;prosecutors-fallacy&quot;&gt;prosecutors-fallacy&lt;/h2&gt;
&lt;p&gt;Check status of runs on farm. Appears that a type error blocked calculations of null distribution. Also, may need further threshold, a threshold of 220 for deviation occurs in 75% of (2000) runs (though depends on run length whether that is sufficiently rare). Threshold of 200 is reached in about 2%. re-running now.&lt;/p&gt;
&lt;p&gt;tweaked my original code a bit to run the case with a single stable state and condition on observing large deviations, and see if the observations prior to the deviation show the ‘spurious’ increase in autocorrelation and variance observed in the original paper.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/earlywarning/blob/019d68ee4c6459d9c56f20c84af3a46c98bdbb03/inst/examples/beer.md&quot;&gt;Results/code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://raw.github.com/cboettig/earlywarning/05611419aeb254ed54a0bb0cd2974c5b328e86fe/inst/examples/beer_dat.csv&quot;&gt;Data for the conditional on deviation warning signal tau values (44 of the timeseries)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://raw.github.com/cboettig/earlywarning/05611419aeb254ed54a0bb0cd2974c5b328e86fe/inst/examples/beer_nulldat.csv&quot;&gt;tau values for unconditional set (2000 timeseries)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Looks like there is still a bias to me.&lt;/p&gt;
&lt;h3 id=&quot;ropensci&quot;&gt;ropensci&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;write coversheet&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://rd-alliance.org&quot;&gt;Research Data Alliance&lt;/a&gt; launch. Interesting &lt;a href=&quot;http://rd-alliance.org/working-groups/current-candidate-groups/&quot;&gt;working groups&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Research</title>
   <link href="/2013/03/20/research.html"/>
   <updated>2013-03-20T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/03/20/research</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;pomp&quot;&gt;pomp&lt;/h2&gt;
&lt;p&gt;Exploring pomp for examples tomorrow. See &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/tree/master/inst/examples/pomp-example.md&quot;&gt;pomp-example&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;To access help on S4 methods&lt;/li&gt;
&lt;li&gt;print method source code: &lt;code&gt;getMethod(&amp;quot;simulate&amp;quot;, &amp;quot;pomp&amp;quot;)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;access help file on available methods: &lt;code&gt;method?show(&amp;quot;pomp&amp;quot;)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;pomp &lt;code&gt;simulate&lt;/code&gt; method returns object of class pomp with data in &lt;code&gt;object@data&lt;/code&gt;, unless user sets either/both of &lt;code&gt;obs=TRUE&lt;/code&gt; and &lt;code&gt;state=TRUE&lt;/code&gt; to return the observed and true state data (in list objects). Seems to be the only way to get the true state data out of the simulate routine (other than shortcutting the observation method &lt;code&gt;rmeasure&lt;/code&gt;). Poor form to change return type based on input options, but oh well.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;prosecutors-fallacy&quot;&gt;prosecutor’s fallacy&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;troubleshooting comment runs setup. Some replicates realize their extrema within the first 200 points, causing negative indexing (if not handled) and mismatched length of data objects (if not handled). Improve exception handling and restart runs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;nonparametric-bayes&quot;&gt;nonparametric-bayes&lt;/h2&gt;
&lt;p&gt;Writing writing writing. see repo.&lt;/p&gt;
&lt;h2 id=&quot;multiple-uncertainty&quot;&gt;multiple-uncertainty&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Troubleshooting the matlab translation&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Cannot seem to pass an array in place of a variable to matlab’s (okay, actually octave’s) &lt;code&gt;applyfun&lt;/code&gt; function:&lt;/p&gt;
&lt;pre class=&quot;sourceCode matlab&quot;&gt;&lt;code class=&quot;sourceCode matlab&quot;&gt;function out = ssum(x,y, a)
  out = (x + y);
end
[X, Y] = meshgrid([&lt;span class=&quot;fl&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;fl&quot;&gt;5&lt;/span&gt;], [&lt;span class=&quot;fl&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;fl&quot;&gt;5&lt;/span&gt;])
b = arrayfun(@ssum, X, Y, &lt;span class=&quot;fl&quot;&gt;1&lt;/span&gt;)  &lt;span class=&quot;co&quot;&gt;%Works fine&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But if the extra argument is a vector this fails.&lt;/p&gt;
&lt;pre class=&quot;sourceCode matlab&quot;&gt;&lt;code class=&quot;sourceCode matlab&quot;&gt;b = arrayfun(@ssum, X, Y, [&lt;span class=&quot;fl&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;fl&quot;&gt;6&lt;/span&gt;])&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Need a convenient way to generate probability densities from continuous distributions in which parameter values and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt; values are restricted to a grid. Matlab translation of this didn’t work.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I want to get the probability density of value &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?P\inline&quot;/&gt;&lt;/span&gt; from uniform distribution between &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mu - \mu S\inline&quot;/&gt;&lt;/span&gt; and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mu + \mu S\inline&quot;/&gt;&lt;/span&gt;.  If &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?S\inline&quot;/&gt;&lt;/span&gt; is zero, I want to return unity if &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?P\inline&quot;/&gt;&lt;/span&gt; is equal to &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mu\inline&quot;/&gt;&lt;/span&gt;.  The trick is that I want all values discretized to a grid, so P == mu really means if &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?P\inline&quot;/&gt;&lt;/span&gt; and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mu\inline&quot;/&gt;&lt;/span&gt; fall in the same bin of the discrete grid.  &lt;/p&gt;
&lt;p&gt;I thought this function would do it:  &lt;/p&gt;
&lt;pre class=&quot;sourceCode matlab&quot;&gt;&lt;code class=&quot;sourceCode matlab&quot;&gt;    function out = snap_to_grid(x, grid)
      [v,i] = min(abs(grid-x));
      out = grid(i);  
    end
     
    &lt;span class=&quot;co&quot;&gt;%% generate various sources of noise, or delta fns if noise is zero&lt;/span&gt;
    function out = pdfn(P, mu, s)
      grid = [&lt;span class=&quot;fl&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;fl&quot;&gt;5&lt;/span&gt;]; &lt;span class=&quot;co&quot;&gt;% dumb grid, ideally an argument to pdfn but doesn&amp;#39;t work&lt;/span&gt;
      if mu == &lt;span class=&quot;fl&quot;&gt;0&lt;/span&gt;
        out = (P == &lt;span class=&quot;fl&quot;&gt;0&lt;/span&gt;);
      elseif s &amp;gt; &lt;span class=&quot;fl&quot;&gt;0&lt;/span&gt;
        if mu &amp;gt; &lt;span class=&quot;fl&quot;&gt;0&lt;/span&gt;
          out = unifpdf(P, mu * (&lt;span class=&quot;fl&quot;&gt;1&lt;/span&gt; - s), mu * (&lt;span class=&quot;fl&quot;&gt;1&lt;/span&gt; + s));
        end
      else  &lt;span class=&quot;co&quot;&gt;% delta spike&lt;/span&gt;
        P = snap_to_grid(P, grid);
        mu = snap_to_grid(mu, grid);
        out = (P == mu);
      end
    end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But clearly I’ve gone wrong somewhere.&lt;/p&gt;
&lt;h2 id=&quot;ropensci&quot;&gt;ropensci&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;final revisions, reread draft, close outstanding issues.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;troubleshooting SSOAP example. Added &lt;code&gt;checkCircular&lt;/code&gt; enables successful parsing, but now no luck generating functions:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(SSOAP)
wsdl = &lt;span class=&quot;kw&quot;&gt;processWSDL&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;http://www.nbnws.net/ws_3_5/GatewayWebService?wsdl&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;checkCircular=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;)
iface = &lt;span class=&quot;kw&quot;&gt;genSOAPClientInterface&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;def =&lt;/span&gt; wsdl)&lt;/code&gt;&lt;/pre&gt;
</content>
 </entry>
 
 <entry>
   <title>Prosecutor Fallacy As Large Deviations</title>
   <link href="/2013/03/19/prosecutor-fallacy-as-large-deviations.html"/>
   <updated>2013-03-19T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/03/19/prosecutor-fallacy-as-large-deviations</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;(Corresponds to commit &lt;a href=&quot;https://github.com/cboettig/earlywarning/blob/4bd84221078df738034e1611b23d7c5aca48de3f/inst/examples/comment.md&quot;&gt;4bd8422107&lt;/a&gt; in &lt;a href=&quot;https://github.com/cboettig/earlywarning/blob/prosecutor&quot;&gt;earlywarning&lt;/a&gt; repo)&lt;/p&gt;
&lt;p&gt;For the individual-based simulation, the population dynamics are given by&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;\[\begin{align}
  \frac{dP(n,t)}{dt} &amp;amp;= b_{n-1} P(n-1,t) + d_{n+1}P(n+1,t) - (b_n+d_n) P(n,t),  \\
    b_n &amp;amp;= \frac{e K n^2}{n^2 + h^2}, \\
    d_n &amp;amp;= e n + a,
\end{align}\]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;which is provided by the &lt;code&gt;saddle_node_ibm&lt;/code&gt; model in &lt;code&gt;populationdynamics&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For each of the warning signal statistics in question, we need to generate the distibution over all replicates and then over replicates which have been selected conditional on having experienced a crash.&lt;/p&gt;
&lt;p&gt;We begin by running the simulation of the process for all replicates.&lt;/p&gt;
&lt;p&gt;Load the required libraries&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(populationdynamics)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(earlywarning)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(reshape2)   &lt;span class=&quot;co&quot;&gt;# data manipulation&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(data.table) &lt;span class=&quot;co&quot;&gt;# data manipulation&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(ggplot2)    &lt;span class=&quot;co&quot;&gt;# graphics&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(snowfall)   &lt;span class=&quot;co&quot;&gt;# parallel&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;theme_publish &amp;lt;- &lt;span class=&quot;kw&quot;&gt;theme_set&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;theme_bw&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;12&lt;/span&gt;))
theme_publish &amp;lt;- 
  &lt;span class=&quot;kw&quot;&gt;theme_update&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;legend.key=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;theme_blank&lt;/span&gt;(),
        &lt;span class=&quot;dt&quot;&gt;panel.grid.major=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;theme_blank&lt;/span&gt;(),&lt;span class=&quot;dt&quot;&gt;panel.grid.minor=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;theme_blank&lt;/span&gt;(),
        &lt;span class=&quot;dt&quot;&gt;plot.background=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;theme_blank&lt;/span&gt;(), &lt;span class=&quot;dt&quot;&gt;legend.title=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;theme_blank&lt;/span&gt;())&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;conditional-distribution&quot;&gt;Conditional distribution&lt;/h3&gt;
&lt;p&gt;Then we fix a set of paramaters we will use for the simulation function. Since we will simulate 20,000 replicates with 50,000 pts a piece, we can save memory by performing the conditional selection on the ones that cross a threshold we go along and disgard the others. (We will create a null distribution in which we ignore this conditional selection later).&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;threshold &amp;lt;- &lt;span class=&quot;dv&quot;&gt;250&lt;/span&gt;
select_crashes &amp;lt;- function(n){
  T&amp;lt;- &lt;span class=&quot;dv&quot;&gt;5000&lt;/span&gt;
  n_pts &amp;lt;- n
  pars = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;Xo =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;500&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;e =&lt;/span&gt; &lt;span class=&quot;fl&quot;&gt;0.5&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;a =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;180&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;K =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;h =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;200&lt;/span&gt;,
    &lt;span class=&quot;dt&quot;&gt;i =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;Da =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;Dt =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;p =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)
  sn &amp;lt;- &lt;span class=&quot;kw&quot;&gt;saddle_node_ibm&lt;/span&gt;(pars, &lt;span class=&quot;dt&quot;&gt;times=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,T, &lt;span class=&quot;dt&quot;&gt;length=&lt;/span&gt;n_pts), &lt;span class=&quot;dt&quot;&gt;reps=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;)
  d &amp;lt;- &lt;span class=&quot;kw&quot;&gt;dim&lt;/span&gt;(sn$x1)
  crashed &amp;lt;- &lt;span class=&quot;kw&quot;&gt;which&lt;/span&gt;(sn$x1[d[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;],] &amp;lt;= threshold)
&lt;span class=&quot;co&quot;&gt;# crashed &amp;lt;- which(sn$x1[d[1],]==0)&lt;/span&gt;
  sn$x1[,crashed] 
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A few extra commands format the data into a table with columns of times, replicate id number, and population value at the given time.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;sfInit&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;parallel=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;sfLibrary&lt;/span&gt;(populationdynamics)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;sfExportAll&lt;/span&gt;()
examples &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sfLapply&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;dv&quot;&gt;20&lt;/span&gt;, function(i) &lt;span class=&quot;kw&quot;&gt;select_crashes&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;50000&lt;/span&gt;))
dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;as.matrix&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;as.data.frame&lt;/span&gt;(examples, &lt;span class=&quot;dt&quot;&gt;check.names=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;)))
&lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(dat) = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;time&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;reps&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;value&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;levels&lt;/span&gt;(dat$reps) &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;levels&lt;/span&gt;(dat$reps)) &lt;span class=&quot;co&quot;&gt;# use numbers for reps&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;subset&lt;/span&gt;(dat, reps %in% &lt;span class=&quot;kw&quot;&gt;levels&lt;/span&gt;(dat$reps)[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;dv&quot;&gt;9&lt;/span&gt;])) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, value)) + &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~reps, &lt;span class=&quot;dt&quot;&gt;scales=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8100/8572282877_815dc4341d_o.png&quot; alt=&quot;plot of chunk testing&quot; /&gt;&lt;figcaption&gt;plot of chunk testing&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Zoom in on the relevant area of data near the crash&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(plyr)
zoom &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ddply&lt;/span&gt;(dat, &lt;span class=&quot;st&quot;&gt;&amp;quot;reps&amp;quot;&lt;/span&gt;, function(X){
    tip &amp;lt;- &lt;span class=&quot;kw&quot;&gt;min&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;which&lt;/span&gt;(X$value&amp;lt;threshold))
    index &amp;lt;- &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(tip&lt;span class=&quot;dv&quot;&gt;-200&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;):tip
    &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time=&lt;/span&gt;X$time[index], &lt;span class=&quot;dt&quot;&gt;value=&lt;/span&gt;X$value[index])
    })&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;subset&lt;/span&gt;(zoom, reps %in% &lt;span class=&quot;kw&quot;&gt;levels&lt;/span&gt;(zoom$reps)[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;dv&quot;&gt;9&lt;/span&gt;])) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, value)) + &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~reps, &lt;span class=&quot;dt&quot;&gt;scales=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8243/8573375714_956b2721cf_o.png&quot; alt=&quot;plot of chunk example-trajectories&quot; /&gt;&lt;figcaption&gt;plot of chunk example-trajectories&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Compute model-based warning signals on all each of these.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;dt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.table&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;subset&lt;/span&gt;(zoom, value&amp;gt;threshold))
var &amp;lt;- dt[, &lt;span class=&quot;kw&quot;&gt;warningtrend&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time=&lt;/span&gt;time, &lt;span class=&quot;dt&quot;&gt;value=&lt;/span&gt;value), window_var), by=reps]$V1
acor &amp;lt;- dt[, &lt;span class=&quot;kw&quot;&gt;warningtrend&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time=&lt;/span&gt;time, &lt;span class=&quot;dt&quot;&gt;value=&lt;/span&gt;value), window_autocorr), by=reps]$V1
dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;Variance=&lt;/span&gt;var, &lt;span class=&quot;dt&quot;&gt;Autocorrelation=&lt;/span&gt;acor))&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;null-distribution&quot;&gt;Null distribution&lt;/h3&gt;
&lt;p&gt;To compare against the expected distribution of these statistics, we create another set of simulations without conditioning on having experienced a chance transition, on which we perform the identical analysis.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;threshold &amp;lt;- &lt;span class=&quot;dv&quot;&gt;250&lt;/span&gt;
select_crashes &amp;lt;- function(n){
  T&amp;lt;- &lt;span class=&quot;dv&quot;&gt;5000&lt;/span&gt;
  n_pts &amp;lt;- n
  pars = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;Xo =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;500&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;e =&lt;/span&gt; &lt;span class=&quot;fl&quot;&gt;0.5&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;a =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;180&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;K =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;h =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;200&lt;/span&gt;,
    &lt;span class=&quot;dt&quot;&gt;i =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;Da =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;Dt =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;p =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)
  sn &amp;lt;- &lt;span class=&quot;kw&quot;&gt;saddle_node_ibm&lt;/span&gt;(pars, &lt;span class=&quot;dt&quot;&gt;times=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,T, &lt;span class=&quot;dt&quot;&gt;length=&lt;/span&gt;n_pts), &lt;span class=&quot;dt&quot;&gt;reps=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;500&lt;/span&gt;)
  d &amp;lt;- &lt;span class=&quot;kw&quot;&gt;dim&lt;/span&gt;(sn$x1)
  sn$x1[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;dv&quot;&gt;501&lt;/span&gt;,]
}&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;sfExportAll&lt;/span&gt;()
examples &amp;lt;-  &lt;span class=&quot;kw&quot;&gt;sfLapply&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, function(i) &lt;span class=&quot;kw&quot;&gt;select_crashes&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;50000&lt;/span&gt;))
nulldat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;as.matrix&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;as.data.frame&lt;/span&gt;(examples, &lt;span class=&quot;dt&quot;&gt;check.names=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;)))
nulldat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(examples)
&lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(nulldat) = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;time&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;reps&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;value&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;levels&lt;/span&gt;(nulldat$reps) &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;levels&lt;/span&gt;(dat$reps)) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Zoom in on the relevant area of data near the crash&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(plyr)
nullzoom &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ddply&lt;/span&gt;(nulldat, &lt;span class=&quot;st&quot;&gt;&amp;quot;reps&amp;quot;&lt;/span&gt;, function(X){
    &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time=&lt;/span&gt;X$time, &lt;span class=&quot;dt&quot;&gt;value=&lt;/span&gt;X$value)
    })&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;nulldt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.table&lt;/span&gt;(nullzoom)
nullvar &amp;lt;- nulldt[, &lt;span class=&quot;kw&quot;&gt;warningtrend&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time=&lt;/span&gt;time, &lt;span class=&quot;dt&quot;&gt;value=&lt;/span&gt;value), window_var), by=reps]$V1
nullacor &amp;lt;- nulldt[, &lt;span class=&quot;kw&quot;&gt;warningtrend&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time=&lt;/span&gt;time, &lt;span class=&quot;dt&quot;&gt;value=&lt;/span&gt;value), window_autocorr), by=reps]$V1
nulldat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;Variance=&lt;/span&gt;nullvar, &lt;span class=&quot;dt&quot;&gt;Autocorrelation=&lt;/span&gt;nullacor))&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dat) + &lt;span class=&quot;kw&quot;&gt;geom_histogram&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value, &lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;..density..), &lt;span class=&quot;dt&quot;&gt;binwidth=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.3&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;alpha=&lt;/span&gt;.&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;) +
 &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~variable) + &lt;span class=&quot;kw&quot;&gt;xlim&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)) + 
 &lt;span class=&quot;kw&quot;&gt;geom_density&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;nulldat, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value), &lt;span class=&quot;dt&quot;&gt;adjust=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;xlab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;Kendall&amp;#39;s tau&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;theme_bw&lt;/span&gt;()&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8093/8572283195_496404332d_o.png&quot; alt=&quot;plot of chunk fig&quot; /&gt;&lt;figcaption&gt;plot of chunk fig&lt;/figcaption&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>Collected notes from past few days</title>
   <link href="/2013/03/19/collected-notes.html"/>
   <updated>2013-03-19T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/03/19/collected-notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;friday&quot;&gt;Friday&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;some ropensci coordination&lt;/li&gt;
&lt;li&gt;Adapt basic science abstract and broader impacts statement&lt;/li&gt;
&lt;li&gt;some writing on notebook features draft&lt;/li&gt;
&lt;li&gt;nonparametric writing!&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;monday&quot;&gt;Monday&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;nonparametric-bayes writing. Combining my generic position piece (&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/tree/master/inst/doc/beyond-mechanistic-models.Rmd&quot;&gt;beyond-mechanistic-models.Rmd&lt;/a&gt;) with the technical nonparametric-bayes writeup (&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/tree/master/inst/doc/nonparameteric-bayes.Rmd&quot;&gt;nonparametric-bayes.Rmd&lt;/a&gt;) to get a more general-audience paper.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;ropensci reviewing&lt;/li&gt;
&lt;li&gt;Note: annoying feature of knitr’s &lt;code&gt;purl&lt;/code&gt;: appears to generate valid “external” knitr code, but includes all options in comment headers instead of just the chunk names. This prevents “external” inclusion from identifying these chunks currectly. &lt;code&gt;tangle&lt;/code&gt; (option in &lt;code&gt;knit&lt;/code&gt;) appears not to generate any header at all. Maybe I’m missing something.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;prosecutors-fallacy-comments&quot;&gt;Prosecutor’s Fallacy Comments&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Further exchanges with John over prosecutors fallacy. Some scratch writing for a potential &lt;a href=&quot;&quot;&gt;reply piece&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Our discussion highlighted two potential test cases that would further demonstrate (or refute) that the critical slowing down we observed is an artifact – our ability to detect it in cases that do not transition (e.g. population of all cases reaching a certain excursion) in the original dynamics, and our ability to detect it in scenarios that do not involve transition dynamics at all. Running these two cases as&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/earlywarning/tree/prosecutor/inst/examples&quot;&gt;comment.Rmd&lt;/a&gt; – repeat the analysis using a generic threshold deviation rather than only populations that have crashed.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/earlywarning/tree/prosecutor/inst/examples&quot;&gt;beer.Rmd&lt;/a&gt; – repeat analysis in which there is only a single stable point.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;ugh, looks like libraries on zero haven’t been kept up. Some delays before production code will be running.&lt;/p&gt;
&lt;h2 id=&quot;tuesday&quot;&gt;Tuesday&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;More writing&lt;/li&gt;
&lt;li&gt;Assemble material for applied math club. Going with particle filtering (&lt;span rel=&quot;tooltip&quot; title=&quot;Ionides E, Breto C and King A (2006). Inference For Nonlinear Dynamical Systems. _Proceedings of The National Academy of Sciences_, *103*. ISSN 0027-8424, http://dx.doi.org/10.1073/pnas.0603181103.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1073/pnas.0603181103&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Ionides &lt;em&gt;et. al.&lt;/em&gt; 2006&lt;/a&gt;&lt;/span&gt;) and the &lt;code&gt;pomp&lt;/code&gt; vignette&lt;/li&gt;
&lt;li&gt;ropensci reviewing&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;misc&quot;&gt;Misc&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Sounds like exciting stuff happening a the #btpdf2 conference&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/03/14/notes.html"/>
   <updated>2013-03-14T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/03/14/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;writing&quot;&gt;Writing&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Meeting with Steve over outline&lt;/li&gt;
&lt;li&gt;Writing on nonparametric-bayes manuscript&lt;/li&gt;
&lt;li&gt;A few notes on notebook-features draft&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;EasyABC by &lt;span rel=&quot;tooltip&quot; title=&quot;Jabot F, Faure T and Dumoulin N (2013). Easyabc: Performing
Efficient Approximate Bayesian Computation Sampling Schemes Using
R. _Methods in Ecology And Evolution_. 
http://dx.doi.org/10.1111/2041-210X.12050.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1111/2041-210X.12050&quot; rel=&quot;http://purl.org/spar/cito/critiques&quot; &gt;Jabot &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt;. While it’s great that MEE publishes this stuff, this is unique in that the authors are updating and improving upon an existing package published by MEE the year before, &lt;span rel=&quot;tooltip&quot; title=&quot;Brook B, Ellis E, Perring M, Mackay A and Blomqvist L (2013).
Does The Terrestrial Biosphere Have Planetary Tipping Points?
_Trends in Ecology &amp; Evolution_. ISSN 01695347, 
http://dx.doi.org/10.1016/j.tree.2013.01.016.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2013.01.016&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Brook &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt;. The authors of the recent manuscript have certainly made an important contribution which deserves the traditional recognition provided by a separate publication, but one must wonder why we need another package instead of building on the existing one. Is that necessary for the publication? If only there was a way to fork the original package, make their additions, issue a pull request instead… Could more research follow such a model?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;The rise of MOOCs may be old news, but the Nature column has a pretty excellent write-up on them all the same &lt;span rel=&quot;tooltip&quot; title=&quot;Halpern B, Longo C, Hardy D, McLeod K, Samhouri J, Katona S,
Kleisner K, Lester S, O’Leary J, Ranelletti M, Rosenberg A,
Scarborough C, Selig E, Best B, Brumbaugh D, Chapin F, Crowder L,
Daly K, Doney S, Elfes C, Fogarty M, Gaines S, Jacobsen K, Karrer
L, Leslie H, Neeley E, Pauly D, Polasky S, Ris B, St Martin K,
Stone G, Sumaila U and Zeller D (2012). an Index to Assess The
Health And Benefits of The Global Ocean. _Nature_, *488*. ISSN
0028-0836,  http://dx.doi.org/10.1038/nature11397.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1038/nature11397&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Halpern &lt;em&gt;et. al.&lt;/em&gt; (2012)&lt;/a&gt;&lt;/span&gt;, including a discussion of the challenges they face (e.g. completion rates) and how they might address them. Only passingly addresses the challenges these pose for universities seeking to get on board – such as the substantial upfront costs in providing content in a different medium and structure (see this recent &lt;a href=&quot;http://www.insidehighered.com/blogs/technology-and-learning/why-moocs-may-drive-higher-ed-costs&quot;&gt;Inside HigherEd piece&lt;/a&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Nice column in &lt;em&gt;Nature&lt;/em&gt; on job opportunities in risk management, &lt;span rel=&quot;tooltip&quot; title=&quot;Nelson B (2013). Natural Disasters: A Calculated Risk. _Nature_,
*495*. ISSN 0028-0836, 
http://dx.doi.org/10.1038/nj7440-271a.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1038/nj7440-271a&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Nelson (2013)&lt;/a&gt;&lt;/span&gt; which highlights the interdisciplinary nature of the work. A pity they find the greatest market for jobs of this type in reinsurance companies and the smallest in academia…&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TREE debates the existence and relevance of tipping points in global context and &lt;span rel=&quot;tooltip&quot; title=&quot;Hughes T, Linares C, Dakos V, van de Leemput I and van Nes E
(2013). Living Dangerously on Borrowed Time During Slow,
Unrecognized Regime Shifts. _Trends in Ecology &amp; Evolution_,
*28*. ISSN 01695347, 
http://dx.doi.org/10.1016/j.tree.2012.08.022.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2012.08.022&quot; rel=&quot;http://purl.org/spar/cito/critiques&quot; &gt;Hughes &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt;, seemingly on the grounds that the globe isn’t a very connected place.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the same issue, the usual suspects emphasize the idea that transitions due to saddle-node bifurcations need not be fast relative to the timescale of management &lt;span rel=&quot;tooltip&quot; title=&quot;Brook B, Ellis E, Perring M, Mackay A and Blomqvist L (2013).
Does The Terrestrial Biosphere Have Planetary Tipping Points?
_Trends in Ecology &amp; Evolution_. ISSN 01695347, 
http://dx.doi.org/10.1016/j.tree.2013.01.016.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2013.01.016&quot; rel=&quot;http://purl.org/spar/cito/critiques&quot; &gt;Brook &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt;. The “fast” transition represents a return to equilibrium at the new laternative stable state. The authors remind us that this transient phase can take a long time (and amazingly failing to cite &lt;span rel=&quot;tooltip&quot; title=&quot;Hastings A and Higgins K (1994). Persistence of Transients in
Spatially Structured Ecological Models. _Science_, *263*. ISSN
0036-8075,  http://dx.doi.org/10.1126/science.263.5150.1133.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1126/science.263.5150.1133&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Hastings &amp;amp; Higgins (1994)&lt;/a&gt;&lt;/span&gt;, &lt;span rel=&quot;tooltip&quot; title=&quot;Hastings A (2001). Transient Dynamics And Persistence of
Ecological Systems. _Ecology Letters_, *4*. ISSN 1461-023X, 
http://dx.doi.org/10.1046/j.1461-0248.2001.00220.x.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1046/j.1461-0248.2001.00220.x&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Hastings (2001)&lt;/a&gt;&lt;/span&gt;, or &lt;span rel=&quot;tooltip&quot; title=&quot;Hastings A (2004). Transients: The Key to Long-Term Ecological
Understanding? _Trends in Ecology &amp; Evolution_, *19*. ISSN
01695347,  http://dx.doi.org/10.1016/j.tree.2003.09.007.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2003.09.007&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Hastings (2004)&lt;/a&gt;&lt;/span&gt; in the process).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Barry W. Brook, Erle C. Ellis, Michael P. Perring, Anson W. Mackay, Linus Blomqvist, (2013) Does The Terrestrial Biosphere Have Planetary Tipping Points?. &lt;em&gt;Trends in Ecology &amp;amp; Evolution&lt;/em&gt; &lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2013.01.016&quot;&gt;10.1016/j.tree.2013.01.016&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Benjamin S. Halpern, Catherine Longo, Darren Hardy, Karen L. McLeod, Jameal F. Samhouri, Steven K. Katona, Kristin Kleisner, Sarah E. Lester, Jennifer O’Leary, Marla Ranelletti, Andrew A. Rosenberg, Courtney Scarborough, Elizabeth R. Selig, Benjamin D. Best, Daniel R. Brumbaugh, F. Stuart Chapin, Larry B. Crowder, Kendra L. Daly, Scott C. Doney, Cristiane Elfes, Michael J. Fogarty, Steven D. Gaines, Kelsey I. Jacobsen, Leah Bunce Karrer, Heather M. Leslie, Elizabeth Neeley, Daniel Pauly, Stephen Polasky, Bud Ris, Kevin St Martin, Gregory S. Stone, U. Rashid Sumaila, Dirk Zeller, (2012) an Index to Assess The Health And Benefits of The Global Ocean. &lt;em&gt;Nature&lt;/em&gt; &lt;strong&gt;488&lt;/strong&gt; &lt;a href=&quot;http://dx.doi.org/10.1038/nature11397&quot;&gt;10.1038/nature11397&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;A. Hastings, K. Higgins, (1994) Persistence of Transients in Spatially Structured Ecological Models. &lt;em&gt;Science&lt;/em&gt; &lt;strong&gt;263&lt;/strong&gt; &lt;a href=&quot;http://dx.doi.org/10.1126/science.263.5150.1133&quot;&gt;10.1126/science.263.5150.1133&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Alan Hastings, (2001) Transient Dynamics And Persistence of Ecological Systems. &lt;em&gt;Ecology Letters&lt;/em&gt; &lt;strong&gt;4&lt;/strong&gt; &lt;a href=&quot;http://dx.doi.org/10.1046/j.1461-0248.2001.00220.x&quot;&gt;10.1046/j.1461-0248.2001.00220.x&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Alan Hastings, (2004) Transients: The Key to Long-Term Ecological Understanding?. &lt;em&gt;Trends in Ecology &amp;amp; Evolution&lt;/em&gt; &lt;strong&gt;19&lt;/strong&gt; &lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2003.09.007&quot;&gt;10.1016/j.tree.2003.09.007&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Terry P. Hughes, Cristina Linares, Vasilis Dakos, Ingrid A. van de Leemput, Egbert H. van Nes, (2013) Living Dangerously on Borrowed Time During Slow, Unrecognized Regime Shifts. &lt;em&gt;Trends in Ecology &amp;amp; Evolution&lt;/em&gt; &lt;strong&gt;28&lt;/strong&gt; &lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2012.08.022&quot;&gt;10.1016/j.tree.2012.08.022&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Franck Jabot, Thierry Faure, Nicolas Dumoulin, (2013) Easyabc: Performing Efficient Approximate Bayesian Computation Sampling Schemes Using R. &lt;em&gt;Methods in Ecology And Evolution&lt;/em&gt; &lt;a href=&quot;http://dx.doi.org/10.1111/2041-210X.12050&quot;&gt;10.1111/2041-210X.12050&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Bryn Nelson, (2013) Natural Disasters: A Calculated Risk. &lt;em&gt;Nature&lt;/em&gt; &lt;strong&gt;495&lt;/strong&gt; &lt;a href=&quot;http://dx.doi.org/10.1038/nj7440-271a&quot;&gt;10.1038/nj7440-271a&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/03/13/notes.html"/>
   <updated>2013-03-13T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/03/13/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;multiple-uncertainty&quot;&gt;Multiple-uncertainty&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Created smaller version of table to simplify comparisons&lt;/li&gt;
&lt;li&gt;Switched to stationary policy comparisons only. (Running out over longer time shifts total value a bit but doesn’t amplify scale of the differences much)&lt;/li&gt;
&lt;li&gt;Larger noise amplifies the effects (compare &lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty/commits/05637ec8845097c5059902a0f4f841343a44d9bc/inst/examples/smalltable.md&quot;&gt;0.3 levels&lt;/a&gt; to &lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty/blob/05637ec8845097c5059902a0f4f841343a44d9bc/inst/examples/smalltable.mhttps://github.com/cboettig/multiple_uncertainty/blob/05637ec8845097c5059902a0f4f841343a44d9bc/inst/examples/smalltable.mdd&quot;&gt;0.5 levels&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;note that averaging over replicates gives rather consistent means. The differences between &lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty/blob/05637ec8845097c5059902a0f4f841343a44d9bc/inst/examples/smalltable.md&quot;&gt;successive&lt;/a&gt; &lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty/blob/bea28d918edccd7c7ab8b365cc12632166985e95/inst/examples/smalltable.md&quot;&gt;runs&lt;/a&gt; of the algorithm give results agreeing to the tenths place at least.&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8381/8555792236_227bdbb05b_o.png&quot; alt=&quot;Example escapement, code&quot; /&gt;&lt;figcaption&gt;Example escapement, &lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty/blob/05637ec8845097c5059902a0f4f841343a44d9bc/inst/examples/smalltable.md&quot;&gt;code&lt;/a&gt;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8526/8554683747_02d0cecfa6_o.png&quot; alt=&quot;the distribution of profits by scenario&quot; /&gt;&lt;figcaption&gt;the distribution of profits by scenario&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;tables-of-results&quot;&gt;Tables of results&lt;/h2&gt;
&lt;p&gt;Note that columns represent the decision-maker’s beliefs about uncertainty and rows represent the true uncertainty present in the simulation.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr class=&quot;header&quot;&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;&lt;/th&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;det&lt;/th&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;g&lt;/th&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;m&lt;/th&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;all&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;det&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;19.11&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;19.11&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;18.81&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;18.81&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;g&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;18.92&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;18.63&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;18.74&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;18.56&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;m&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;16.17&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;16.76&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;17.38&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;18.08&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;all&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;15.54&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;14.65&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;16.50&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;17.15&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr class=&quot;header&quot;&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;&lt;/th&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;det&lt;/th&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;g&lt;/th&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;m&lt;/th&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;all&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;det&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;0.00&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;0.00&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;0.00&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;g&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;4.41&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;4.31&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;3.59&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;3.28&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;m&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;3.10&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;2.96&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;1.60&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;1.12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;all&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;5.06&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;4.89&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;4.20&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;4.59&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;logistic-case&quot;&gt;logistic case&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Overcompensatory density dependence is tough on stock. With given discounting (5%) and finite horizon (15 cycles) strategies act &lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty/blob/dc6fa3b8c1913cd771e72673083aa80ee733dc62/inst/examples/logistic_uniform.md&quot;&gt;conservatively&lt;/a&gt;. Hmm, strange that deterministic case is equally effected..&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;running with much weaker &lt;code&gt;r&lt;/code&gt; to reduce overcompensatory impacts…&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;coding&quot;&gt;Coding&lt;/h3&gt;
&lt;p&gt;Attempting to translate algorithm into Jim’s native tongue (matlab) for feedback. &lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty/blob/fa4404e1719111b28aa23e388519db94c6f990db/R/multiple_uncertainty.R&quot;&gt;R version&lt;/a&gt; vs &lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty/blob/fa4404e1719111b28aa23e388519db94c6f990db/inst/matlab/multiple_uncertainty.m&quot;&gt;matlab&lt;/a&gt; not there yet…&lt;/p&gt;
&lt;h2 id=&quot;reviewing&quot;&gt;Reviewing&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Another review request, another review done.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;misc&quot;&gt;Misc&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;With Alistair, playing around with this HMM EM algorithm &lt;a href=&quot;https://github.com/gui11aume/HMMt/&quot;&gt;gui11aume/HMMt&lt;/a&gt;. Also threw in a pull request with documentation. grr, took a bit to understand what was going on with that paper.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/03/12/notes.html"/>
   <updated>2013-03-12T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2013/03/12/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h3 id=&quot;monday&quot;&gt;Monday&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;multiple_uncertainty abstract&lt;/li&gt;
&lt;li&gt;Meeting with Robin Snyder&lt;/li&gt;
&lt;li&gt;application writing&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;tuesday&quot;&gt;Tuesday&lt;/h3&gt;
&lt;h4 id=&quot;morning&quot;&gt;Morning&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;applications&lt;/li&gt;
&lt;li&gt;Coordinating summer conference travel&lt;/li&gt;
&lt;li&gt;ropensci proposals&lt;/li&gt;
&lt;li&gt;EML is not an ontology, not analgous to Dublin Core, etc. Just an XML schema. see &lt;a href=&quot;https://semtools.ecoinformatics.org/oboe&quot;&gt;OBOE&lt;/a&gt; for an ecological ontology. to explore later.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;afternoon&quot;&gt;Afternoon&lt;/h3&gt;
&lt;h4 id=&quot;multiple-uncertainty&quot;&gt;multiple-uncertainty&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Revisiting multiple-uncertainty runs. Running smaller table example. Recoded script to allow arbitrary set of noise configurations to be consistently compared.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Some debugging. Shared-memory parallelization prohibitive at current memory requirements.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;See: small table example (for issue #3) &lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty/commit/a2806b079faf60ac1537e3dc8f129b79aab826f0&quot;&gt;04:48 pm 2013/03/12&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;nonparametric-bayes&quot;&gt;nonparametric-bayes&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Exploring options for approximate dynamic programming. For the moment, working through the basic ADP algorithm presented in Powell (2006).&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;in-progress notes: &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/master/inst/examples/adp-intro.md&quot;&gt;latest version&lt;/a&gt; &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/dc45de162b057a1eb53846e030354a02305c9ea5/inst/examples/adp-intro.md&quot;&gt;version-stable link&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes From The Week</title>
   <link href="/2013/03/08/notes-from-the-week.html"/>
   <updated>2013-03-08T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/03/08/notes-from-the-week</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;(Working from Galveston this week while at Louise’s conference, looking after little one. some progress below.)&lt;/p&gt;
&lt;h2 id=&quot;monday&quot;&gt;Monday&lt;/h2&gt;
&lt;h4 id=&quot;alan-skype-meeting&quot;&gt;Alan Skype meeting&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Comment piece / reply&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/ews-review&quot;&gt;ews-review&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Comments on TE review?&lt;/li&gt;
&lt;li&gt;IARPA Conference, funding options?&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;tasks&quot;&gt;Tasks&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;On Marc’s suggestion, writing comparison of pattern-based and mechanism based approaches to modeling, particularly in decision theory context. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/cb0f7d5f779bb424e5fb02b06463f946c360017d/inst/doc/beyond-mechanistic-models.md&quot;&gt;draft&lt;/a&gt; in nonparametric-bayes&lt;/li&gt;
&lt;li&gt;Review edits and writing on &lt;a href=&quot;https://github.com/cboettig/ews-review&quot;&gt;ews-review&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;tuesday&quot;&gt;Tuesday&lt;/h2&gt;
&lt;h4 id=&quot;kathy-skype&quot;&gt;Kathy Skype&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Decision theory in early warning signals?&lt;/li&gt;
&lt;li&gt;NCEAS / SESYNC working group?&lt;/li&gt;
&lt;li&gt;Long term lake monitoring data, including some sedimentary analysis (see &lt;span rel=&quot;tooltip&quot; title=&quot;Wang R, Dearing J, Langdon P, Zhang E, Yang X, Dakos V and
Scheffer M (2012). Flickering Gives Early Warning Signals of A
Critical Transition to A Eutrophic Lake State. _Nature_, *492*.
ISSN 0028-0836,  http://dx.doi.org/10.1038/nature11655.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1038/nature11655&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Wang &lt;em&gt;et. al.&lt;/em&gt; (2012)&lt;/a&gt;&lt;/span&gt;).&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Send Kathy TREE articles: &lt;span rel=&quot;tooltip&quot; title=&quot;Polasky S, Carpenter S, Folke C and Keeler B (2011).
Decision-Making Under Great Uncertainty: Environmental Management
in an Era of Global Change. _Trends in Ecology &amp; Evolution_,
*26*. ISSN 01695347, 
http://dx.doi.org/10.1016/j.tree.2011.04.007.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2011.04.007&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Polasky &lt;em&gt;et. al.&lt;/em&gt; (2011)&lt;/a&gt;&lt;/span&gt; and &lt;span rel=&quot;tooltip&quot; title=&quot;Fischer J, Peterson G, Gardner T, Gordon L, Fazey I, Elmqvist T,
Felton A, Folke C and Dovers S (2009). Integrating Resilience
Thinking And Optimisation For Conservation. _Trends in Ecology &amp;
Evolution_, *24*. ISSN 01695347, 
http://dx.doi.org/10.1016/j.tree.2009.03.020.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2009.03.020&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Fischer &lt;em&gt;et. al.&lt;/em&gt; (2009)&lt;/a&gt;&lt;/span&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;tasks-1&quot;&gt;Tasks&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Writing comparison of pattern-based and mechanism based approaches to modeling, particularly in decision theory context&lt;/li&gt;
&lt;li&gt;Review edits and writing on &lt;a href=&quot;https://github.com/cboettig/ews-review&quot;&gt;ews-review&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;wednesday&quot;&gt;Wednesday&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;more of the same.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;friday&quot;&gt;Friday&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Finished and submitted &lt;a href=&quot;https://github.com/cboettig/ews-review&quot;&gt;ews-review&lt;/a&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;See commit log and &lt;a href=&quot;https://github.com/cboettig/ews-review/issues&quot;&gt;issues&lt;/a&gt; tracker for details.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;notebook-semantics&quot;&gt;Notebook: Semantics,&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;stemming-based search seems to perform poorly – i.e. cannot find phrases, weight terms in titles, etc, just most frequently occuring terms in a post. Trying lunr, loads full text into memory but should do so only on selecting search bar? See issue &lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/7&quot;&gt;#7&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modified google-analytics plugin to make single call to the API see issue &lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/66&quot;&gt;#66&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tuning RDFa, primarily on vita. &lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/22&quot;&gt;#22&lt;/a&gt; &lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/63&quot;&gt;#63&lt;/a&gt;. Tuned FOAF referencing to common nodes. Note that &lt;code&gt;rel&lt;/code&gt; always applys to links while &lt;code&gt;property&lt;/code&gt; applies to the content of the tag (e.g. anchor text, span context). Use &lt;code&gt;rel&lt;/code&gt; in span and div elements, etc, to apply to multiple links.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Joern Fischer, Garry D. Peterson, Toby A. Gardner, Line J. Gordon, Ioan Fazey, Thomas Elmqvist, Adam Felton, Carl Folke, Stephen Dovers, (2009) Integrating Resilience Thinking And Optimisation For Conservation. &lt;em&gt;Trends in Ecology &amp;amp; Evolution&lt;/em&gt; &lt;strong&gt;24&lt;/strong&gt; &lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2009.03.020&quot;&gt;10.1016/j.tree.2009.03.020&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Stephen Polasky, Stephen R. Carpenter, Carl Folke, Bonnie Keeler, (2011) Decision-Making Under Great Uncertainty: Environmental Management in an Era of Global Change. &lt;em&gt;Trends in Ecology &amp;amp; Evolution&lt;/em&gt; &lt;strong&gt;26&lt;/strong&gt; &lt;a href=&quot;http://dx.doi.org/10.1016/j.tree.2011.04.007&quot;&gt;10.1016/j.tree.2011.04.007&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Rong Wang, John A. Dearing, Peter G. Langdon, Enlou Zhang, Xiangdong Yang, Vasilis Dakos, Marten Scheffer, (2012) Flickering Gives Early Warning Signals of A Critical Transition to A Eutrophic Lake State. &lt;em&gt;Nature&lt;/em&gt; &lt;strong&gt;492&lt;/strong&gt; &lt;a href=&quot;http://dx.doi.org/10.1038/nature11655&quot;&gt;10.1038/nature11655&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Delayed Release Archives</title>
   <link href="/2013/03/02/delayed-release-archives.html"/>
   <updated>2013-03-02T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/03/02/delayed-release-archives</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;Today I dug out a handful (37) posts from the past two years that were published as &lt;a href=&quot;http://carlboettiger.info/tags.html#delayed-release&quot;&gt;#delayed-release&lt;/a&gt; content (and have all been tagged as such to indicate they were not public at their publication date). Many of these were connected to the &lt;a href=&quot;http://carlboettiger.info/tags.html#warning-signals&quot;&gt;#warning-signals&lt;/a&gt; project but involved results that I or Alan weren’t ready to provide ahead of publication, as I discussed in a post when I first began marking some posts for delayed release, &lt;a href=&quot;http://www.carlboettiger.info/2011/03/21/challenges-with-collaboration-in-open-science.html&quot;&gt;challenges with collaboration in open science&lt;/a&gt; These posts were created while on the Wordpress platform and had been marked private, so that they would be invisible to public browsing. Wordpress makes this easy to do, as I discuss in the earlier post. When I switched to a Jekyll platform, these posts all received the yaml header &lt;code&gt;published: false&lt;/code&gt; and were also excluded from the Github repository until I could revisit and decide which to release. Managing these posts for release in the Jekyll framework just requires a little command-line fu, &lt;code&gt;grep -l 'published: false' *.md&lt;/code&gt; grabs the relevant posts for inspection and release.&lt;/p&gt;
&lt;p&gt;The notebook is currently back to an ONS All-content, immediate, as I have been able to okay the practice with all current major collaborations. (Sure, there’s always stuff that doesn’t make it into the notebook or is not appropriate for the notebook – the most common case of the latter being peer reviews I write for various journals. Though I make a practice of signing my reviews, I believe they still represent private communication unless the authors, editors and journals were to agree to publishing them.) All of these posts would have been released sooner but for finding a minute to remember to do so – perhaps a cautionary example for the delayed release practice.&lt;/p&gt;
&lt;p&gt;Looking back on these posts, I probably would not have delayed most of them today, as I have gotten more comfortable not only with the open notebook, but with discussing the practice with collaborators. My own feelings of not wanting to push my adviser in a discussion of the notebook was as much responsible for these delays as other factors that I discuss in the earlier post. One key thing I wondered about in writing delayed-release posts was whether I would (perhaps subconsciously) write in a different or more candid style than I do for my regular notes. I was glad not to notice any glaring examples (though perhaps a diligent or very bored reader might find some!) of expletives and insulting commentary in the delayed posts. I do notice the overall tone and volume of the textual content changes slightly. However, that trend is actually much more dominant in comparing my very early posts (mostly from the OWW days), which were quite discursive, to the current posts which tend to be much more terse.&lt;/p&gt;
&lt;p&gt;So have a look at the &lt;a href=&quot;http://carlboettiger.info/tags.html#delayed-release&quot;&gt;#delayed-release&lt;/a&gt; posts and let me know what you think!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/02/28/notes.html"/>
   <updated>2013-02-28T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/02/28/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;h2 id=&quot;meeting-with-marc&quot;&gt;Meeting with Marc&lt;/h2&gt;
&lt;p&gt;Selection of problem: consider simpler models only. Sep through complexity hierarchy at the beginning:&lt;/p&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;classical approaches are to fix relationship of stock recruitment.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;parameter uncertainty&lt;/li&gt;
&lt;li&gt;Gaussian processes for model uncertainty&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The Discussion section can deal with model uncertainty model choice approaches.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A method where we don’t have to assume the stock recuritment relationship&lt;/li&gt;
&lt;li&gt;How well we can do with that.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;How much data we need.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;discussion of mathematical presentation, clarity&lt;/p&gt;
&lt;h2 id=&quot;misc&quot;&gt;Misc&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Finished review. I should stop signing reviews, then I could write more careless quick impressions.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;discussed potential of a GSOC proposal for an R NEXML parser&lt;/li&gt;
&lt;li&gt;requested to consider presenting at &lt;a href=&quot;http://isiconference2013.org/pgs/specsessions.php&quot;&gt;ISI Conference&lt;/a&gt; session on early warning.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;some-reading-on-semantics&quot;&gt;some reading on semantics&lt;/h2&gt;
&lt;p&gt;David Shotton and Tanya Gray have release a CiTO tool for adding semantic data to many major publication platforms, taking a clever approach to annotation that I’ve never considered – croudsourcing to readers (&lt;span class=&quot;showtooltip&quot; title=&quot;davidshotton (2013). CiTO Reference Annotation Tools. 
http://semanticpublishing.wordpress.com/2013/02/26/cito-tools/
[Online. last-accessed: 2013-02-26 15:32:11]. 
http://semanticpublishing.wordpress.com/2013/02/26/cito-tools/.&quot;&gt;&lt;a href=&quot;http://semanticpublishing.wordpress.com/2013/02/26/cito-tools/&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;davidshotton, 2013&lt;/a&gt;&lt;/span&gt;). The tool isn’t perfect but is very intuitive. The clever part is that all annotations the reader adds are collated in a database and cand be retrieved through their &lt;a href=&quot;http://www.miidi.org/cito/api/&quot;&gt;API&lt;/a&gt;. Not sure if many readers will make use of this, but time will tell. Meanwhile authors or publishers might pay attention.&lt;/p&gt;
&lt;p&gt;In that vein, David has also written a call of Ten Next Steps for publishers, (&lt;span class=&quot;showtooltip&quot; title=&quot;davidshotton (2013). Ten next steps for semantic authors and
publishers. 
http://semanticpublishing.wordpress.com/2013/02/26/ten-next-steps/
[Online. last-accessed: 2013-02-28 22:40:01]. 
http://semanticpublishing.wordpress.com/2013/02/26/ten-next-steps/.&quot;&gt;&lt;a href=&quot;http://semanticpublishing.wordpress.com/2013/02/26/ten-next-steps/&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;davidshotton, 2013b&lt;/a&gt;&lt;/span&gt;). Some may be redundant, but certainly shows how publishers could go a lot further. If only there was more incentive for publishers to innovate like this instead of crafting clever and questionable strategies to boost impact factors.&lt;/p&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;/h2&gt;
&lt;p&gt;Very interesting paper on implementing/teaching nonlinear model inference to ecologists out today (&lt;span class=&quot;showtooltip&quot; title=&quot;Bolker B, Gardner B, Maunder M, Berg C, Brooks M, Comita L, Crone
E, Cubaynes S, Davies T, de Valpine P, Ford J, Gimenez O, Kery M,
Kim E, Lennert-Cody C, Magnusson A, Martell S, Nash J, Nielsen A,
Regetz J, Skaug H and Zipkin E (2013). Strategies For Fitting
Nonlinear Ecological Models in R, ad Model Builder, And Bugs.
_Methods in Ecology And Evolution_. 
http://dx.doi.org/10.1111/2041-210X.12044.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1111/2041-210X.12044&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Bolker &lt;em&gt;et. al.&lt;/em&gt; 2013&lt;/a&gt;&lt;/span&gt;), and the &lt;a href=&quot;https://groups.nceas.ucsb.edu/non-linear-modeling/projects&quot;&gt;code and data for each of the examples they discuss&lt;/a&gt;. Lessons in the mansucript may be familiar to many, but should still be taught more widely in ecology. Should be useful for teaching this stuff in graduate courses too.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Benjamin M. Bolker, Beth Gardner, Mark Maunder, Casper W. Berg, Mollie Brooks, Liza Comita, Elizabeth Crone, Sarah Cubaynes, Trevor Davies, Perry de Valpine, Jessica Ford, Olivier Gimenez, Marc Kery, Eun Jung Kim, Cleridy Lennert-Cody, Arni Magnusson, Steve Martell, John Nash, Anders Nielsen, Jim Regetz, Hans Skaug, Elise Zipkin, (2013) Strategies For Fitting Nonlinear Ecological Models in R, ad Model Builder, And Bugs. &lt;em&gt;Methods in Ecology And Evolution&lt;/em&gt; &lt;a href=&quot;http://dx.doi.org/10.1111/2041-210X.12044&quot;&gt;10.1111/2041-210X.12044&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;davidshotton, (2013) CiTO Reference Annotation Tools. &lt;em&gt;Semantic Publishing&lt;/em&gt; &lt;a href=&quot;http://semanticpublishing.wordpress.com/2013/02/26/cito-tools/&quot;&gt;http://semanticpublishing.wordpress.com/2013/02/26/cito-tools/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;davidshotton, (2013) Ten next steps for semantic authors and publishers. &lt;em&gt;Semantic Publishing&lt;/em&gt; &lt;a href=&quot;http://semanticpublishing.wordpress.com/2013/02/26/ten-next-steps/&quot;&gt;http://semanticpublishing.wordpress.com/2013/02/26/ten-next-steps/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/02/27/notes.html"/>
   <updated>2013-02-27T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/02/27/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h3 id=&quot;reviewing&quot;&gt;Reviewing&lt;/h3&gt;
&lt;p&gt;arg, reviewing. so much time.&lt;/p&gt;
&lt;h3 id=&quot;seminar&quot;&gt;Seminar&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;http://katericherson.wordpress.com/&quot;&gt;Kate Richerson&lt;/a&gt; gave a fanstastic presentation to mega group yesterday showing her integration of behavior and dispersal in krill dynamics. She derives the krill’s behavioral movement patterns through a stochastic dynamic programming solution rather than just dictate it to the dispersal model directly.&lt;/p&gt;
&lt;h3 id=&quot;reading&quot;&gt;Reading&lt;/h3&gt;
&lt;p&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Provicative stuff in PNAS &lt;span class=&quot;showtooltip&quot; title=&quot;Perretti C, Munch S and Sugihara G (2013). Model-Free Forecasting
Outperforms The Correct Mechanistic Model For Simulated And
Experimental Data. _Proceedings of The National Academy of
Sciences_. ISSN 0027-8424, 
http://dx.doi.org/10.1073/pnas.1216076110.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1216076110&quot;&gt;Perretti &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt;. It would be nice to see the comparison against the generating model.  The forecasting errors of the fully Bayesian inference using the correct model shouldn’t necessary be small, but they should be just as big as the Bayesian model expects them to be (e.g. over replicates, the Bayesian forecast error reflects the widths of the posteriors (modulo some statement about priors)).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;My worry with any approach doing better than the expected error is that it does so by generating biased estimation – e.g. something in the forecasting method, rather than in the data, happens to be biased towards the ‘right answer’.  In this example I don’t think that is the case.&lt;/p&gt;
&lt;p&gt;We already know that the modes of the posteriors don’t recover the correct model parameters of the generating model from an MCMC of such a complex model with limited data (though perhaps it is good to remind folks of this!), so it is not surprising that a heuristic approach can outperform this in cases.  &lt;/p&gt;
&lt;p&gt;It certainly is good to wrestle with these examples in any case.  Steve’s one of my post-doc advisors now so no doubt I’m biased.  Noam also pointed out this earlier article in Ecology &lt;span class=&quot;showtooltip&quot; title=&quot;Perretti C, Sugihara G and Munch S (2012). Nonparametric
Forecasting Outperforms Parametric Methods For A Simulated
Multi-Species System. _Ecology_. ISSN 0012-9658, 
http://dx.doi.org/10.1890/12-0904.1.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1890/12-0904.1&quot;&gt;Perretti &lt;em&gt;et. al.&lt;/em&gt; (2012)&lt;/a&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In seminar, Marc mentioned the great paper by &lt;span class=&quot;showtooltip&quot; title=&quot;Wiedenmann J, Cresswell K, Goldbogen J, Potvin J and Mangel M
(2011). Exploring The Effects of Reductions in Krill Biomass in
The Southern Ocean on Blue Whales Using A State-Dependent Foraging
Model. _Ecological Modelling_, *222*. ISSN 03043800, 
http://dx.doi.org/10.1016/j.ecolmodel.2011.07.013.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1016/j.ecolmodel.2011.07.013&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Wiedenmann &lt;em&gt;et. al.&lt;/em&gt; (2011)&lt;/a&gt;&lt;/span&gt; that uses the comparison of the optimal foraging strategy evolved by whales in their evolutionary environment to how that strategy performs today (similar spirit to the kinds of comparisons I am interested in with #multiple-uncertainty project.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Reading an old Schaffer paper &lt;span class=&quot;showtooltip&quot; title=&quot;Schaffer W (1984). Stretching And Folding in Lynx Fur Returns:
Evidence For A Strange Attractor in Nature? _The American
Naturalist_, *124*. ISSN 0003-0147, 
http://dx.doi.org/10.1086/284318.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1086/284318&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Schaffer (1984)&lt;/a&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Though &lt;em&gt;Nature&lt;/em&gt; says the National Academy of Sciences needs an overhaul to stay relevant. Probably true but they still do some excellent reports that could deserve more eyes, like this on model fitting (&lt;span class=&quot;showtooltip&quot; title=&quot;(????). Assessing the Reliability of Complex Models: Mathematical
and Statistical Foundations of Verification, Validation, and
Uncertainty Quantification. 
http://www.nap.edu/catalog.php?record_id=13395 [Online.
last-accessed: 2013-02-28 18:23:05]. 
http://www.nap.edu/catalog.php?record_id=13395.&quot;&gt;&lt;a href=&quot;http://www.nap.edu/catalog.php?record_id=13395&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;&lt;/a&gt;&lt;/span&gt;). We could do more VVUQ in ecology and evolution, and the value of presenting benchmark examples of this in simple (trivial) cases cannot be overstated, e.g. Fig 5.2.1.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;GP methods in Biometrika &lt;span class=&quot;showtooltip&quot; title=&quot;Banerjee A, Dunson D and Tokdar S (2012). Efficient Gaussian
Process Regression For Large Datasets. _Biometrika_, *100*. ISSN
0006-3444,  http://dx.doi.org/10.1093/biomet/ass068.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1093/biomet/ass068&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Banerjee &lt;em&gt;et. al.&lt;/em&gt; (2012)&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Luminaries of evolution forecast the future of the field, with an eye towards data and semantics in &lt;span class=&quot;showtooltip&quot; title=&quot;Losos J, Arnold S, Bejerano G, Brodie E, Hibbett D, Hoekstra H,
Mindell D, Monteiro A, Moritz C, Orr H, Petrov D, Renner S,
Ricklefs R, Soltis P and Turner T (2013). Evolutionary Biology
For The 21st Century. _Plos Biology_, *11*. 
http://dx.doi.org/10.1371/journal.pbio.1001466.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1371/journal.pbio.1001466&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Losos &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;misc&quot;&gt;Misc&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;wrote a quick CSL format for knitcitations. (Generate inline citations using the copy function in Mendeley library. A bit silly since normally that would already generate the entire bibliographic citation.)&lt;/li&gt;
&lt;li&gt;Should really make a CSL format for Mendeley to paste in a HTML citation (with full metadata in tooltip). Might then use an existing format to copy-paste bib info at end.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;bibliography&lt;/span&gt;()&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;A. Banerjee, D. B. Dunson, S. T. Tokdar, (2012) Efficient Gaussian Process Regression For Large Datasets. &lt;em&gt;Biometrika&lt;/em&gt; &lt;strong&gt;100&lt;/strong&gt; &lt;a href=&quot;http://dx.doi.org/10.1093/biomet/ass068&quot;&gt;10.1093/biomet/ass068&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Jonathan B. Losos, Stevan J. Arnold, Gill Bejerano, E. D. Brodie, David Hibbett, Hopi E. Hoekstra, David P. Mindell, Antónia Monteiro, Craig Moritz, H. Allen Orr, Dmitri A. Petrov, Susanne S. Renner, Robert E. Ricklefs, Pamela S. Soltis, Thomas L. Turner, (2013) Evolutionary Biology For The 21st Century. &lt;em&gt;Plos Biology&lt;/em&gt; &lt;strong&gt;11&lt;/strong&gt; &lt;a href=&quot;http://dx.doi.org/10.1371/journal.pbio.1001466&quot;&gt;10.1371/journal.pbio.1001466&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Charles Thomas Perretti, George Sugihara, Stephan B. Munch, (2012) Nonparametric Forecasting Outperforms Parametric Methods For A Simulated Multi-Species System. &lt;em&gt;Ecology&lt;/em&gt; &lt;a href=&quot;http://dx.doi.org/10.1890/12-0904.1&quot;&gt;10.1890/12-0904.1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;C. T. Perretti, S. B. Munch, G. Sugihara, (2013) Model-Free Forecasting Outperforms The Correct Mechanistic Model For Simulated And Experimental Data. &lt;em&gt;Proceedings of The National Academy of Sciences&lt;/em&gt; &lt;a href=&quot;http://dx.doi.org/10.1073/pnas.1216076110&quot;&gt;10.1073/pnas.1216076110&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;William M. Schaffer, (1984) Stretching And Folding in Lynx Fur Returns: Evidence For A Strange Attractor in Nature?. &lt;em&gt;The American Naturalist&lt;/em&gt; &lt;strong&gt;124&lt;/strong&gt; &lt;a href=&quot;http://dx.doi.org/10.1086/284318&quot;&gt;10.1086/284318&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;John Wiedenmann, Katherine A. Cresswell, Jeremy Goldbogen, Jean Potvin, Marc Mangel, (2011) Exploring The Effects of Reductions in Krill Biomass in The Southern Ocean on Blue Whales Using A State-Dependent Foraging Model. &lt;em&gt;Ecological Modelling&lt;/em&gt; &lt;strong&gt;222&lt;/strong&gt; &lt;a href=&quot;http://dx.doi.org/10.1016/j.ecolmodel.2011.07.013&quot;&gt;10.1016/j.ecolmodel.2011.07.013&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Assessing the Reliability of Complex Models: Mathematical and Statistical Foundations of Verification, Validation, and Uncertainty Quantification. &lt;a href=&quot;http://www.nap.edu/catalog.php?record_id=13395&quot;&gt;http://www.nap.edu/catalog.php?record_id=13395&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Semantic Citations For The Notebook And Knitr</title>
   <link href="/2013/02/22/semantic-citations-for-the-notebook-and-knitr.html"/>
   <updated>2013-02-22T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/02/22/semantic-citations-for-the-notebook-and-knitr</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;I have on ocassion been exploring the use of &lt;a href=&quot;/tags.html/#semantics&quot;&gt;semantic&lt;/a&gt; markup in the notebook. In this post I illustrate how I am handling semantic citations. One of the more intriguing ideas is the ability to add semantic meaning to citations through the CITO ontology of &lt;span class=&quot;showtooltip&quot; title=&quot;Shotton D (2010). Cito, The Citation Typing Ontology. _Journal
of Biomedical Semantics_, *1*. ISSN 2041-1480, 
http://dx.doi.org/10.1186/2041-1480-1-S1-S6.&quot;&gt;&lt;a href=&quot;http://dx.doi.org/10.1186/2041-1480-1-S1-S6&quot; rel=&quot;http://purl.org/spar/cito/usesMethodIn&quot; &gt;Shotton (2010)&lt;/a&gt;&lt;/span&gt;. Citation counts form a central part of academic discourse, but contain very little information regarding the reason for the citation. Most notably, ‘negative’ citations refuting a claim carry just the same weight as those confirming or relying upon a claim. Given the scale and expansion of academic literature, it is rarely reasonable to explore this citation graph manually. CITO provides a language for embedding the meaning of the citation, such as “discusses”, “refutes”, or “usesMethodIn”, to the citation. (For instance, my earlier citation to Shotton identifies itself as “usesMethodIn”, as I will explain).&lt;/p&gt;
&lt;p&gt;The main barrier to this approach is a lack of adoption. One of the primary concerns is the burden it places on authors of adding the extra data. On one hand, authors already bother formatting and reformatting layout, spelling, and reference order to the arcane specifications of different journals, which suggests authors can be persuaded to do some pretty tedious tasks if the publishers would require it. After all, the task of adding citations is already much easier than it was in the days of paper journals. Still, it is much simpler to remove a tedious requirement than to add a new one. My hope is that intelligent tools can simplify this process, as they already have with other aspects of managing citations, and encourage the use of CITO. In this spirit, I have recently started trying to consistently use the CITO ontology in my notebook entries as a test case, using some tools of my own design.&lt;/p&gt;
&lt;h3 id=&quot;semantics-in-knitcitations&quot;&gt;Semantics in knitcitations&lt;/h3&gt;
&lt;p&gt;Several months ago I created the R package &lt;a href=&quot;https://github.com/cboettig/knitcitations&quot;&gt;knitcitations&lt;/a&gt; to provide a citation platform for &lt;a href=&quot;http://yihui.name/knitr&quot;&gt;knitr&lt;/a&gt; dynamic documents, which provide executable code and automatic inclusion of results inside plain-text (markdown) descriptions. I write most of my research scripts and many of my notebook entries in this manner. The package can generate citations by DOI, circumventing the need for maintaining bibtex or similar database of citation information, using commands such as&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;citet&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;10.1186/2041-1480-1-S1-S6&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Extending the package to support CITO was rather straight forward. Using the latest version of knitcitations, one can generate in-line citations with CITO semantics simply by passing the reason for the citation as well, such as&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;citet&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;10.1186/2041-1480-1-S1-S6&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;cito=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;usesMethodIn&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which generates the following HTML:&lt;/p&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;&lt;span class=&quot;kw&quot;&gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;#39;http://dx.doi.org/10.1186/2041-1480-1-S1-S6&amp;#39;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;#39;http://purl.org/spar/cito/usesMethodIn&amp;#39;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;Shotton (2010)&lt;span class=&quot;kw&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This provides a convient platform to generate semantic citations in this lab notebook. As before, knitcitations will also generate a complete reference list at the end of the document by calling the &lt;code&gt;bibliography&lt;/code&gt; function at the end.&lt;/p&gt;
&lt;h3 id=&quot;semantic-overkill&quot;&gt;Semantic overkill?&lt;/h3&gt;
&lt;p&gt;It is possible to add far more semantic data to this reference list at the end of an article. Invisible semantic markup can identify to a machine what value corresponds to the volume number or issue number, or journal name, e,g, using the BIBO ontology. I have added support for ths kind of markup to knitcitations as well, and &lt;a href=&quot;/2013/02/12/notes.html&quot;&gt;several&lt;/a&gt; &lt;a href=&quot;/2013/02/21/notes.html&quot;&gt;of&lt;/a&gt; my posts provide examples. The raw markup looks like this:&lt;/p&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;&lt;span class=&quot;kw&quot;&gt;&amp;lt;div&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; prefix=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc: http://purl.org/dc/terms/,&lt;/span&gt;
&lt;span class=&quot;st&quot;&gt;                      bibo: http://purl.org/ontology/bibo/,&lt;/span&gt;
&lt;span class=&quot;st&quot;&gt;                      foaf: http://xmlns.com/foaf/spec/,&lt;/span&gt;
&lt;span class=&quot;st&quot;&gt;                      biro: http://purl.org/spar/biro/&amp;quot;&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;        rel=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://purl.org/spar/biro/ReferenceList&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;ul&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; class=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;#39;bibliography&amp;#39;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt; 
&lt;span class=&quot;kw&quot;&gt;&amp;lt;li&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:title&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;Fisheries: Does Catch Reflect Abundance?.&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:creator&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;foaf:givenName&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;Daniel&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;foaf:familyName&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;Pauly&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:creator&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;foaf:givenName&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;Ray&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;foaf:familyName&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;Hilborn&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:creator&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;foaf:givenName&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;Trevor A.&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;foaf:familyName&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;Branch&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;  (&lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:date&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;2013&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;)  &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; rel=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://purl.org/dc/terms/isPartOf&amp;quot;&lt;/span&gt; 
&lt;span class=&quot;ot&quot;&gt;                            resource=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;[http://purl.org/dc/terms/journal]&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://purl.org/dc/terms/title&amp;quot;&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;                                content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot; Nature &amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
                          &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;bibo:shortTitle&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt; Nature &lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
               &lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;  &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;bibo:volume&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;494&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;    &lt;span class=&quot;kw&quot;&gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;bibo:doi&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://dx.doi.org/10.1038/494303a&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;10.1038/494303a&lt;span class=&quot;kw&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;li&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:title&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;Net Gains.&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:creator&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;foaf:givenName&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;unknown&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;foaf:familyName&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;unknown&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;  (&lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:date&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;2013&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;)  &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; rel=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://purl.org/dc/terms/isPartOf&amp;quot;&lt;/span&gt; 
&lt;span class=&quot;ot&quot;&gt;                            resource=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;[http://purl.org/dc/terms/journal]&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://purl.org/dc/terms/title&amp;quot;&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;                                content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot; Nature &amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
                          &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;bibo:shortTitle&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt; Nature &lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
               &lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;  &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;bibo:volume&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;494&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;    &lt;span class=&quot;kw&quot;&gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;bibo:doi&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://dx.doi.org/10.1038/494282a&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;10.1038/494282a&lt;span class=&quot;kw&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
 &lt;span class=&quot;kw&quot;&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, I have since decided that such markup is largely overkill. The DOI uniquely identifies the publication already, and allows us to programmatically retrieve the rest of the data (title, authors, journal, etc) from semantically identified XML by querying against services such as CrossRef. &lt;em&gt;This is the essential concept of linked data&lt;/em&gt;, by which both source and referer are enriched.&lt;/p&gt;
&lt;p&gt;Moreover, DOIs follows a specific construction that lets us reliably &lt;a href=&quot;http://stackoverflow.com/questions/27910/finding-a-doi-in-a-document-or-page&quot;&gt;identify them in plain text using regular expressions&lt;/a&gt;, making any futher semantics to declare that we are citing the article mostly irrelevant. This is convient for identifying all citations appearing in the notebook without any markup. The CITO example above has the advantage of providing a link and associating the DOI with the reason for the citation, by virtue of being inside the same html anchor element.&lt;/p&gt;
&lt;h3 id=&quot;replacing-the-reference-list&quot;&gt;Replacing the reference list?&lt;/h3&gt;
&lt;p&gt;If we are not going to semantically mark up the reference list, we could consider abolishing the reference list all together. After all, as a tool for the digital reader the concept is rather vestigal – I hate losing my place by scrolling to the end of an article just to see to what reference number 7 refers. With the method shown thus far, the reader can open the link to access this information, but that still interrupts the flow of reading. The digitally native solution is a mouse-over or tooltip effect that displays this information, as many professional publishers already use in their HTML versions.&lt;/p&gt;
&lt;p&gt;Once again, this is straight forward to support using the knitcitations package, at least for sites that include the popular &lt;a href=&quot;http://twitter.github.com/bootstrap&quot;&gt;bootstrap&lt;/a&gt; javascript libraries, such as this notebook. I have added an option to the in-text citation functions to provide such tooltips in a span element, such that calling the command&lt;/p&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;&lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; class=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;#39;showtooltip&amp;#39;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; title=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;#39;Shotton D (2010). &amp;quot;Cito, The Citation Typing Ontology.&amp;quot; _Journal of&lt;/span&gt;
&lt;span class=&quot;st&quot;&gt;Biomedical Semantics_, *1*. ISSN 2041-1480, &lt;/span&gt;&lt;span class=&quot;er&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;URL:&lt;/span&gt;
&lt;span class=&quot;st&quot;&gt;http://dx.doi.org/10.1186/2041-1480-1-S1-S6&amp;gt;.&amp;#39;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;#39;http://dx.doi.org/10.1186/2041-1480-1-S1-S6&amp;#39;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;#39;http://purl.org/spar/cito/usesMethodIn&amp;#39;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;Shotton (2010)&lt;span class=&quot;kw&quot;&gt;&amp;lt;/a&amp;gt;&amp;lt;/span&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This behavior can be toggled on by calling&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;cite_options&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;tooltip=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;after loading the knitcitations library. &lt;strong&gt;EDIT&lt;/strong&gt;: Note that this requires the javascript trigger on the class &lt;code&gt;showtooltip&lt;/code&gt;, which can be done by adding this to your header:&lt;/p&gt;
&lt;pre class=&quot;js&quot;&gt;&lt;code&gt;    &amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;
      $(document).ready(function (){
        $(&amp;quot;.showtooltip&amp;quot;).tooltip();
      });
    &amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;citing-without-dois&quot;&gt;Citing without DOIs&lt;/h3&gt;
&lt;p&gt;Not all the literature we may wish to cite includes DOIs, such as &lt;a href=&quot;http://arxiv.org&quot;&gt;arXiv&lt;/a&gt; preprints, Wikipedia pages, or other academic blogs. Even when a DOI is present it is not always trivial to locate. With version 0.4-0, knitcitations can produce citations given any URL using the &lt;a href=&quot;http://greycite.knowledgeblog.org&quot;&gt;Greycite API&lt;/a&gt; (&lt;span class=&quot;showtooltip&quot; title=&quot;Lord P (2012). Greycite. 
http://knowledgeblog.org/greycite [Online. last-accessed:
2012-10-10 13:36:24].  http://knowledgeblog.org/greycite.&quot;&gt;&lt;a href=&quot;http://knowledgeblog.org/greycite&quot; rel=&quot;http://purl.org/spar/cito/usesMethodIn&quot; &gt;Lord, 2012&lt;/a&gt;&lt;/span&gt;). For instance, this citation is created with the command &lt;code&gt;citep(&amp;quot;http://knowledgeblog.org/greycite&amp;quot;, cito=&amp;quot;usesMethodIn&amp;quot;)&lt;/code&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/02/21/notes.html"/>
   <updated>2013-02-21T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/02/21/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;applied-math-club-meeting&quot;&gt;Applied Math Club meeting&lt;/h2&gt;
&lt;p&gt;(See reading material from &lt;a href=&quot;/2013/02/19/notes.html&quot;&gt;Tuesday&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Start with stable age distribtution (indep of stock-recrutiment)&lt;/li&gt;
&lt;li&gt;Consider the &lt;em&gt;Entropy&lt;/em&gt; of that probability distribution, as function of mortality, by max age&lt;/li&gt;
&lt;li&gt;Now consider the same for fecundity: the fraction/density of the population von Bertalanffy growth (fecundity)&lt;/li&gt;
&lt;li&gt;effective mortality rate - mortality rate in an unfished population, distributed with same entropy as the fished population,&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Kullback-Leibler distance to measure fishing influence?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;Mutual information and the design of surveys?&lt;/li&gt;
&lt;li&gt;(information in catch data?)&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bonsall: Information content of global dynamics from individual patch dynamics?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;misc&quot;&gt;Misc&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.nceas.ucsb.edu/news/nceas-summer-institute-2013&quot;&gt;NCEAS Summer Institute&lt;/a&gt; for data synthesis. Intriguing.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Is there information in catch data: a comment piece highlighting the debate with Pauly on the affermative and Hilborn &amp;amp; Branch on the negative, (&lt;a href=&quot;http://dx.doi.org/10.1038/494303a&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Pauly &lt;em&gt;et. al.&lt;/em&gt; 2013&lt;/a&gt;) and editoral commentary (&lt;a href=&quot;http://dx.doi.org/10.1038/494282a&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;unknown, 2013&lt;/a&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Looking over this approximate dynamic programming (ADP) paper in MEE, &lt;a href=&quot;http://dx.doi.org/10.1111/j.2041-210X.2012.00242.x&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Schapaugh &lt;em&gt;et. al.&lt;/em&gt; (2012)&lt;/a&gt;. Possibly promising. I need to map out the space of ADP approaches and advantages/disadvantages a little more to get a better impression.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://dx.doi.org/10.1111/j.2041-210X.2012.00242.x&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Schapaugh &lt;em&gt;et. al.&lt;/em&gt; (2012)&lt;/a&gt;: A new method for ADP? Or maybe not so new? see: &lt;a href=&quot;http://www.cs.rutgers.edu/~lihong/pub/Li06Towards.pdf&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;&lt;/a&gt;, &lt;em&gt;Towards a unified theory of state abstraction for MDPs&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cute analysis on malaria as branching process in policy forum piece in Science (with Alex’s mentor) &lt;a href=&quot;http://dx.doi.org/10.1126/science.1229509&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Chiyaka &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And following up on today’s chats about information theory, a neat paper from Marc &lt;a href=&quot;http://dx.doi.org/10.1111/jeb.12010&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Frank (2012)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;and making the rounds on the blogosphere bashing MAXENT, &lt;a href=&quot;http://dx.doi.org/10.1111/j.1541-0420.2012.01824.x&quot; rel=&quot;http://purl.org/spar/cito/discusses&quot; &gt;Renner &amp;amp; Warton (2013)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div prefix=&quot;dc: http://purl.org/dc/terms/,
                      bibo: http://purl.org/ontology/bibo/,
                      foaf: http://xmlns.com/foaf/spec/,
                      biro: http://purl.org/spar/biro/&quot;
        rel=&quot;http://purl.org/spar/biro/ReferenceList&quot;&gt; &lt;ul class='bibliography'&gt; 
&lt;li&gt; 
&lt;span property=&quot;dc:title&quot;&gt;The Stability of Malaria Elimination.&lt;/span&gt; &lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;C.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Chiyaka&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;A. J.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Tatem&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;J. M.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Cohen&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;P. W.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Gething&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;G.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Johnston&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;R.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Gosling&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;R.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Laxminarayan&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;S. I.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Hay&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;D. L.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Smith&lt;/span&gt;, &lt;/span&gt; (&lt;span property=&quot;dc:date&quot;&gt;2013&lt;/span&gt;) &lt;span rel=&quot;http://purl.org/dc/terms/isPartOf&quot; 
                            resource=&quot;[http://purl.org/dc/terms/journal]&quot;&gt; &lt;span property=&quot;http://purl.org/dc/terms/title&quot;
                                content=&quot; Science &quot;&gt; &lt;/span&gt; &lt;span property=&quot;bibo:shortTitle&quot;&gt; Science &lt;/span&gt; &lt;/span&gt; &lt;span property=&quot;bibo:volume&quot;&gt;339&lt;/span&gt; &lt;a property=&quot;bibo:doi&quot; href=&quot;http://dx.doi.org/10.1126/science.1229509&quot;&gt;10.1126/science.1229509&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; 
&lt;span property=&quot;dc:title&quot;&gt;Natural Selection. V. How to Read The Fundamental Equations of Evolutionary Change in Terms of Information Theory.&lt;/span&gt; &lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;S. A.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Frank&lt;/span&gt;, &lt;/span&gt; (&lt;span property=&quot;dc:date&quot;&gt;2012&lt;/span&gt;) &lt;span rel=&quot;http://purl.org/dc/terms/isPartOf&quot; 
                            resource=&quot;[http://purl.org/dc/terms/journal]&quot;&gt; &lt;span property=&quot;http://purl.org/dc/terms/title&quot;
                                content=&quot; Journal of Evolutionary Biology &quot;&gt; &lt;/span&gt; &lt;span property=&quot;bibo:shortTitle&quot;&gt; Journal of Evolutionary Biology &lt;/span&gt; &lt;/span&gt; &lt;span property=&quot;bibo:volume&quot;&gt;25&lt;/span&gt; &lt;a property=&quot;bibo:doi&quot; href=&quot;http://dx.doi.org/10.1111/jeb.12010&quot;&gt;10.1111/jeb.12010&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; 
&lt;span property=&quot;dc:title&quot;&gt;Fisheries: Does Catch Reflect Abundance?.&lt;/span&gt; &lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;Daniel&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Pauly&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;Ray&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Hilborn&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;Trevor A.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Branch&lt;/span&gt;, &lt;/span&gt; (&lt;span property=&quot;dc:date&quot;&gt;2013&lt;/span&gt;) &lt;span rel=&quot;http://purl.org/dc/terms/isPartOf&quot; 
                            resource=&quot;[http://purl.org/dc/terms/journal]&quot;&gt; &lt;span property=&quot;http://purl.org/dc/terms/title&quot;
                                content=&quot; Nature &quot;&gt; &lt;/span&gt; &lt;span property=&quot;bibo:shortTitle&quot;&gt; Nature &lt;/span&gt; &lt;/span&gt; &lt;span property=&quot;bibo:volume&quot;&gt;494&lt;/span&gt; &lt;a property=&quot;bibo:doi&quot; href=&quot;http://dx.doi.org/10.1038/494303a&quot;&gt;10.1038/494303a&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; 
&lt;span property=&quot;dc:title&quot;&gt;Equivalence of Maxent And Poisson Point Process Models For Species Distribution Modeling in Ecology.&lt;/span&gt; &lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;Ian W.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Renner&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;David I.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Warton&lt;/span&gt;, &lt;/span&gt; (&lt;span property=&quot;dc:date&quot;&gt;2013&lt;/span&gt;) &lt;span rel=&quot;http://purl.org/dc/terms/isPartOf&quot; 
                            resource=&quot;[http://purl.org/dc/terms/journal]&quot;&gt; &lt;span property=&quot;http://purl.org/dc/terms/title&quot;
                                content=&quot; Biometrics &quot;&gt; &lt;/span&gt; &lt;span property=&quot;bibo:shortTitle&quot;&gt; Biometrics &lt;/span&gt; &lt;/span&gt; &lt;a property=&quot;bibo:doi&quot; href=&quot;http://dx.doi.org/10.1111/j.1541-0420.2012.01824.x&quot;&gt;10.1111/j.1541-0420.2012.01824.x&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; 
&lt;span property=&quot;dc:title&quot;&gt;A Simple Method For Dealing With Large State Spaces.&lt;/span&gt; &lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;Adam W.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Schapaugh&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;Andrew J.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Tyre&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;Robert&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Freckleton&lt;/span&gt;, &lt;/span&gt; (&lt;span property=&quot;dc:date&quot;&gt;2012&lt;/span&gt;) &lt;span rel=&quot;http://purl.org/dc/terms/isPartOf&quot; 
                            resource=&quot;[http://purl.org/dc/terms/journal]&quot;&gt; &lt;span property=&quot;http://purl.org/dc/terms/title&quot;
                                content=&quot; Methods in Ecology And Evolution &quot;&gt; &lt;/span&gt; &lt;span property=&quot;bibo:shortTitle&quot;&gt; Methods in Ecology And Evolution &lt;/span&gt; &lt;/span&gt; &lt;span property=&quot;bibo:volume&quot;&gt;3&lt;/span&gt; &lt;a property=&quot;bibo:doi&quot; href=&quot;http://dx.doi.org/10.1111/j.2041-210X.2012.00242.x&quot;&gt;10.1111/j.2041-210X.2012.00242.x&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; 
&lt;span property=&quot;dc:title&quot;&gt;.&lt;/span&gt; &lt;span property=&quot;dc:creator&quot;&gt; &lt;/span&gt; (&lt;span property=&quot;dc:date&quot;&gt;&lt;/span&gt;) &lt;span rel=&quot;http://purl.org/dc/terms/isPartOf&quot; 
                            resource=&quot;[http://purl.org/dc/terms/journal]&quot;&gt; &lt;span property=&quot;http://purl.org/dc/terms/title&quot;
                                content=&quot;  &quot;&gt; &lt;/span&gt; &lt;span property=&quot;bibo:shortTitle&quot;&gt; &lt;/span&gt; &lt;/span&gt; &lt;a property=&quot;bibo:doi&quot; href=&quot;http://dx.doi.org/&quot;&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; 
&lt;span property=&quot;dc:title&quot;&gt;Net Gains.&lt;/span&gt; &lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;unknown&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;unknown&lt;/span&gt;, &lt;/span&gt; (&lt;span property=&quot;dc:date&quot;&gt;2013&lt;/span&gt;) &lt;span rel=&quot;http://purl.org/dc/terms/isPartOf&quot; 
                            resource=&quot;[http://purl.org/dc/terms/journal]&quot;&gt; &lt;span property=&quot;http://purl.org/dc/terms/title&quot;
                                content=&quot; Nature &quot;&gt; &lt;/span&gt; &lt;span property=&quot;bibo:shortTitle&quot;&gt; Nature &lt;/span&gt; &lt;/span&gt; &lt;span property=&quot;bibo:volume&quot;&gt;494&lt;/span&gt; &lt;a property=&quot;bibo:doi&quot; href=&quot;http://dx.doi.org/10.1038/494282a&quot;&gt;10.1038/494282a&lt;/a&gt;
&lt;/li&gt;
 &lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;NULL&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Seminar Notes</title>
   <link href="/2013/02/20/seminar-notes.html"/>
   <updated>2013-02-20T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/02/20/seminar-notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;leo-polansky-seminar&quot;&gt;Leo Polansky Seminar&lt;/h2&gt;
&lt;p&gt;(all notes cover published results only)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Wavelet analysis does a nice trick of seeing frequency-domain spectra change over time, rather than being entirely in frequency space or entirely in time space.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;higher rank elephants decrease their movement more in dry, resource-poor season than low rank. Guarding the good territory? I wonder if this is a stochastic effect - asset protection, where you take more risk when you have low assets than when you have higher assets, a feature that would dissappear in a deterministic environment.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Nice hidden markov model analysis from the mhsmm package.&lt;/li&gt;
&lt;li&gt;movement time series – high impact public data or closely guarded secret? (top secret)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;michael-bonsall&quot;&gt;Michael Bonsall&lt;/h2&gt;
&lt;p&gt;(Seminar to the Mangel megagroup meeting)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;uncertainty and variability in population dynamics. Mike uses the very words I’ve used to describe my interests: dynamic, nonlinear, and noisy.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;blasocyst-dynamics&quot;&gt;Blasocyst Dynamics&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Development of mammalian blastocyst much more messy/complicated than development in other taxa. heterogeneity in timing&lt;/li&gt;
&lt;li&gt;Begins with ODE model with time lags (to avoid poisson waiting times). Then add a distribution over the time lag.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Invasion analysis of cell types differing in time. Widening distribution of time lags increases fitness. &lt;em&gt;Interesting! But intuition/mechanism unclear&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Now add process noise, observation error and priors on parameters to compare model to data. Variability can be explained entirely by differences in rates. (as estimated from a particle filter). &lt;em&gt;Identifiability?&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;bruchid-dynamics&quot;&gt;Bruchid Dynamics&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Spatial dynamics with beatles and their parasitic wasps.&lt;/li&gt;
&lt;li&gt;Beautiful microcosm setup that follows Nicholson-Bailey dynamics.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Within patch dynamics show regimes.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Consider stochastic birth-death-diffusion model&lt;/li&gt;
&lt;li&gt;Stochastic focusing / demographic heterogeneity observed&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;bipolar-disorder-dynamics&quot;&gt;Bipolar disorder dynamics&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;(Inductive example)&lt;/li&gt;
&lt;li&gt;EM algorithm for missing values in time lag model&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;other-activities-today&quot;&gt;Other activities today&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;working on nominations&lt;/li&gt;
&lt;li&gt;ropensci sustainability plan (see email threads),&lt;/li&gt;
&lt;li&gt;also see the Conceptualizing an Institute for Sustainable Earth and Environmental Software (ISEES), http://isees.nceas.ucsb.edu/&lt;/li&gt;
&lt;li&gt;friendly review phylolm package and preprint&lt;/li&gt;
&lt;li&gt;summarizing reimbursement form&lt;/li&gt;
&lt;li&gt;updated issues lists for notebook&lt;/li&gt;
&lt;li&gt;Bonsall speaker dinner&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;/h2&gt;
&lt;p&gt;Following up on discussions today, seemed like a good time to reread:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Bonsall, M. B. &amp;amp; Hastings, A. 2004 Demographic and environmental stochasticity in predator – prey metapopulation dynamics. , 1043–1055. (doi:10.1111/j.0021-8790.2004.00874.x)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Also taking a look at the ‘stochastic focusing’ literature. Unclear if the term has caught on much beyond Paulsson and co. though.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Paulsson, J., Berg, O. G. &amp;amp; Ehrenberg, M. 2000 Stochastic focusing: fluctuation-enhanced sensitivity of intracellular regulation. Proceedings of the National Academy of Sciences of the United States of America 97, 7148–53. (doi:10.1073/pnas.110057697)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/02/19/notes.html"/>
   <updated>2013-02-19T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/02/19/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;ul&gt;
&lt;li&gt;Fixed notebook compile error, and adjusted timeouts on pageviews / google-analytics API&lt;/li&gt;
&lt;li&gt;Some minor fixes in knitcitations (thanks to another user bug report). &lt;a href=&quot;https://github.com/cboettig/knitcitations/blob/a717b5a3568db7e0f8b1a49cafb1e242bbef2fbe/NEWS&quot;&gt;NEWS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Accepted TE review request; better finish up ENMO review soon.&lt;/li&gt;
&lt;li&gt;Generating data tables for published figures for Dryad (from prosecutor’s fallacy). &lt;a href=&quot;http://dx.doi.org/10.5061/dryad.2k462&quot;&gt;Data in Dryad&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;applied-math-club-reading&quot;&gt;Applied Math club reading&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;with Marc and Mike Bonsall on Thurs, reading:&lt;/li&gt;
&lt;/ul&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;Strevens, C. M. J. &amp;amp; Bonsall, M. B. 2011 Density-dependent population dynamics and dispersal in heterogeneous metapopulations. The Journal of animal ecology 80, 282–93. (doi:10.1111/j.1365-2656.2010.01768.x)&lt;/li&gt;
&lt;li&gt;Cover, T. M. &amp;amp; Thomas, J. A. 2006 Elements of Information Theory. Second. Hoboken, NJ, USA: John Wiley &amp;amp; Sons, Inc.&lt;/li&gt;
&lt;li&gt;Liepe, J., Filippi, S., Komorowski, M. &amp;amp; Stumpf, M. P. H. 2013 Maximizing the Information Content of Experiments in Systems Biology. PLoS Computational Biology 9, e1002888. (doi:10.1371/journal.pcbi.1002888)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Silk, H., Demirel, G., Homer, M. &amp;amp; Gross, T. 2013 Exploring network dynamics with a mathematical triple jump. (Arxiv)&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Lade, S. J., Tavoni, A., Levin, S. A. &amp;amp; No, W. P. 2013 Regime shifts in a social-ecological system Centre for Climate Change Economics and Policy. preprint&lt;/li&gt;
&lt;li&gt;Torney, C. J., Levin, S. a. &amp;amp; Couzin, I. D. 2013 Decision Accuracy and the Role of Spatial Interaction in Opinion Dynamics. Journal of Statistical Physics (doi:10.1007/s10955-013-0700-5)&lt;/li&gt;
&lt;li&gt;Wang, S. &amp;amp; Campbell, B. C. 2013 Mr. Bayes Goes to Washington. Science 339, 758–759. (doi:10.1126/science.1232290)&lt;/li&gt;
&lt;li&gt;Kiernan, V. 2003 Diffusion of News about Research. Science Communication 25, 3–13. (doi:10.1177/1075547003255297) Interesting one of few papers discussing the role coverage in popular media has on citations&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/02/14/notes.html"/>
   <updated>2013-02-14T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/02/14/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
    
   <category term="//categories.html#evolution" label="evolution"/>
   
   <content type="html">&lt;h2 id=&quot;research&quot;&gt;Research&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;consolidate and revise EWS text(?)&lt;/li&gt;
&lt;li&gt;replies to Luke and Brian on model choice&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;notebook-meta&quot;&gt;Notebook meta&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;fix google-analytics plugin (still needs to get toggle working?)&lt;/li&gt;
&lt;li&gt;tests of notebook-parsing.Rmd. New errors on &lt;code&gt;;&lt;/code&gt; somehow in straight XML parsing, ignoring for the moment.&lt;/li&gt;
&lt;li&gt;Opened a few new issues around improving site semantics. (#59, #60)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;ropensci&quot;&gt;ropensci&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Resubmit rfishbase – silently load to local, not global namespace. Updated data cache (and ASCII-ify and compress).&lt;br /&gt;Also replaced &lt;code&gt;data&lt;/code&gt; loading with &lt;code&gt;system.file(&amp;quot;data&amp;quot;, &amp;quot;fishbase.rda&amp;quot;, package=&amp;quot;fishbase&amp;quot;)&lt;/code&gt;. ASCII-only .rda is very annoying. Should work around this with alternative data file?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;Resubmit rfigshare – punt on 3.0.0 compatible vignette for the moment&lt;/li&gt;
&lt;li&gt;&lt;p&gt;knitcitations: Fix the stupid disambiguation for inline citations (took way too long).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reading&quot;&gt;reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Brandt, G. &amp;amp; Merico, A. 2013 Tipping points and user-resource system collapse in a simple model of evolutionary dynamics. Ecological Complexity (doi:10.1016/j.ecocom.2012.12.003)&lt;/li&gt;
&lt;li&gt;Cuddington, K., Fortin, M. &amp;amp; Gerber, L. 2013 Process-based models are required to manage ecological systems in a changing world. Ecosphere 4, 1–12. (doi:10.1890/ES12-00178.1)&lt;/li&gt;
&lt;li&gt;Reiner, R. C. et al. 2013 A systematic review of mathematical models of mosquito-borne pathogen transmission: 1970-2010. Journal of The Royal Society Interface 10, 20120921–20120921. (doi:10.1098/rsif.2012.0921)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/02/13/notes.html"/>
   <updated>2013-02-13T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/02/13/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h3 id=&quot;ropensci&quot;&gt;ropensci&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;rfishbase: 0.1-1 released to CRAN: bugfix updating server address. (Broke &lt;code&gt;updateCache()&lt;/code&gt;). See &lt;a href=&quot;https://github.com/ropensci/rfishbase/blob/master/NEWS&quot;&gt;NEWS&lt;/a&gt; for details.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;rfigshare: 0.2-4 released to CRAN: added method to remove attached files (issue &lt;a href=&quot;https://github.com/ropensci/rfigshare/issues/42&quot;&gt;#42&lt;/a&gt;), see &lt;a href=&quot;https://github.com/ropensci/rfigshare/blob/master/NEWS&quot;&gt;NEWS&lt;/a&gt; for details&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;misc&quot;&gt;Misc&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;My reply to John on Prosecutor’s Fallacy piece.&lt;/li&gt;
&lt;li&gt;Thinking about a better way to provide convenient, stable access to code and data. Should provide csv versions of data.table outputs used to create each of the figures. Could by Dryad archived.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;reading&quot;&gt;Reading&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Deyle, E. R. &amp;amp; Sugihara, G. 2011 Generalized theorems for nonlinear state space reconstruction. PloS one 6, e18295. (doi:10.1371/journal.pone.0018295)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Brock, W., Xepapadeas, A. &amp;amp; Yannacopoulos, A. 2013 Robust Control of a Spatially Distributed Commercial Fishery. (preprint)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Costello, C., Ovando, D., Hilborn, R., Gaines, S. D., Deschenes, O. &amp;amp; Lester, S. E. 2012 Status and solutions for the world’s unassessed fisheries. Science (New York, N.Y.) 338, 517–20. (doi:10.1126/science.1223389)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2013/02/12/notes.html"/>
   <updated>2013-02-12T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/02/12/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;writing&quot;&gt;Writing&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Working on nonparametric-bayes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;/h2&gt;
&lt;p&gt;Interesting PNAS comment from &lt;a rel=&quot;http://purl.org/spar/cito/discusses&quot;, href=&quot;http://dx.doi.org/10.1073/pnas.1222736110&quot;&gt;Doney &amp;amp; Sailley, (2013)&lt;/a&gt; (“When an ecological regime shift is really just stochastic noise”) on the &lt;a rel=&quot;http://purl.org/spar/cito/discusses&quot;, href=&quot;http://dx.doi.org/10.1073/pnas.1218022110&quot;&gt;Di Lorenzo &amp;amp; Ohman, (2013)&lt;/a&gt; piece in the same issue, showing that time integrated zooplankton data correlates closely with environmental drivers: in this case, the pacific decadal oscillation (PDO) index, which would be missed by the traditional approach of direct correlations. This refutes the previous explanation of such shifts observed in the krill populations as being driven by nonlinear ecological interactions, rather than merely linearly tracking the environment (&lt;a rel=&quot;http://purl.org/spar/cito/refutes&quot;, href=&quot;http://dx.doi.org/10.1016/S0079-6611(00)00033-1&quot;&gt;(Hare &amp;amp; Mantua, 2000)&lt;/a&gt;). While there is some mention of how this may complicate traditional assumptions of warning signals, they do not remark on the obvious converse that the integral data may be more informative of detecting such shifts (whether or not they are tracking some abiotic dynamics).&lt;/p&gt;
&lt;p&gt;In a related vein in the same issue is &lt;a rel=&quot;http://purl.org/spar/cito/discusses&quot;, href=&quot;http://dx.doi.org/10.1073/pnas.1215508110&quot;&gt;Liu &lt;em&gt;et. al.&lt;/em&gt; (2013)&lt;/a&gt;, discussing their algorithm for inferring complex dynamics from limited observations. Seems to do a poor job of putting the method into context of the suite of related approaches to addressing this problem (hidden Markov models, POMDP, etc), let alone directly comparing to them, which makes for a somewhat frustrating read. Still, could be a gem in the method I haven’t had a chance to dig into.&lt;/p&gt;
&lt;h2 id=&quot;ropensci&quot;&gt;ropensci&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/sandbox/blob/b5fc66ddfa690416a3d10c299f3245fe6e660416/testcache/inst/doc/example.md&quot;&gt;Example of caching for authentication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Finalize scoring, replies to &lt;a href=&quot;http://ropensci.org/open-science-challenge/&quot;&gt;challenge&lt;/a&gt; participants&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;div prefix=&quot;dc: http://purl.org/dc/terms/,
                      bibo: http://purl.org/ontology/bibo/,
                      foaf: http://xmlns.com/foaf/spec/,
                      biro: http://purl.org/spar/biro/&quot;
        rel=&quot;http://purl.org/spar/biro/ReferenceList&quot;&gt; &lt;ul class='bibliography'&gt; 
&lt;li&gt; 
&lt;span property=&quot;dc:title&quot;&gt;From The Cover: A Double-Integration Hypothesis to Explain Ocean Ecosystem Response to Climate Forcing.&lt;/span&gt; &lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;E.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Di Lorenzo&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;M. D.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Ohman&lt;/span&gt;, &lt;/span&gt; (&lt;span property=&quot;dc:date&quot;&gt;2013&lt;/span&gt;) &lt;span rel=&quot;http://purl.org/dc/terms/isPartOf&quot; 
                            resource=&quot;[http://purl.org/dc/terms/journal]&quot;&gt; &lt;span property=&quot;http://purl.org/dc/terms/title&quot;
                                content=&quot; Proceedings of The National Academy of Sciences &quot;&gt; &lt;/span&gt; &lt;span property=&quot;bibo:shortTitle&quot;&gt; Proceedings of The National Academy of Sciences &lt;/span&gt; &lt;/span&gt; &lt;span property=&quot;bibo:volume&quot;&gt;110&lt;/span&gt; &lt;a property=&quot;bibo:doi&quot; href=&quot;http://dx.doi.org/10.1073/pnas.1218022110&quot;&gt;10.1073/pnas.1218022110&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; 
&lt;span property=&quot;dc:title&quot;&gt;When an Ecological Regime Shift is Really Just Stochastic Noise.&lt;/span&gt; &lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;S. C.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Doney&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;S. F.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Sailley&lt;/span&gt;, &lt;/span&gt; (&lt;span property=&quot;dc:date&quot;&gt;2013&lt;/span&gt;) &lt;span rel=&quot;http://purl.org/dc/terms/isPartOf&quot; 
                            resource=&quot;[http://purl.org/dc/terms/journal]&quot;&gt; &lt;span property=&quot;http://purl.org/dc/terms/title&quot;
                                content=&quot; Proceedings of The National Academy of Sciences &quot;&gt; &lt;/span&gt; &lt;span property=&quot;bibo:shortTitle&quot;&gt; Proceedings of The National Academy of Sciences &lt;/span&gt; &lt;/span&gt; &lt;span property=&quot;bibo:volume&quot;&gt;110&lt;/span&gt; &lt;a property=&quot;bibo:doi&quot; href=&quot;http://dx.doi.org/10.1073/pnas.1222736110&quot;&gt;10.1073/pnas.1222736110&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt; 
&lt;span property=&quot;dc:title&quot;&gt;Observability of Complex Systems.&lt;/span&gt; &lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;Y.-Y.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Liu&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;J.-J.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Slotine&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;A.-L.&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Barabasi&lt;/span&gt;, &lt;/span&gt; (&lt;span property=&quot;dc:date&quot;&gt;2013&lt;/span&gt;) &lt;span rel=&quot;http://purl.org/dc/terms/isPartOf&quot; 
                            resource=&quot;[http://purl.org/dc/terms/journal]&quot;&gt; &lt;span property=&quot;http://purl.org/dc/terms/title&quot;
                                content=&quot; Proceedings of The National Academy of Sciences &quot;&gt; &lt;/span&gt; &lt;span property=&quot;bibo:shortTitle&quot;&gt; Proceedings of The National Academy of Sciences &lt;/span&gt; &lt;/span&gt; &lt;span property=&quot;bibo:volume&quot;&gt;110&lt;/span&gt; &lt;a property=&quot;bibo:doi&quot; href=&quot;http://dx.doi.org/10.1073/pnas.1215508110&quot;&gt;10.1073/pnas.1215508110&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt; 
&lt;span property=&quot;dc:title&quot;&gt;Empirical Evidence For North Pacific Regime Shifts in 1977 And 1989.&lt;/span&gt; &lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;Steven R&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Hare&lt;/span&gt;, &lt;/span&gt;&lt;span property=&quot;dc:creator&quot;&gt; &lt;span property=&quot;foaf:givenName&quot;&gt;Nathan J&lt;/span&gt; &lt;span property=&quot;foaf:familyName&quot;&gt;Mantua&lt;/span&gt;, &lt;/span&gt; (&lt;span property=&quot;dc:date&quot;&gt;2000&lt;/span&gt;) &lt;span rel=&quot;http://purl.org/dc/terms/isPartOf&quot; 
                            resource=&quot;[http://purl.org/dc/terms/journal]&quot;&gt; &lt;span property=&quot;http://purl.org/dc/terms/title&quot;
                                content=&quot; Progress in Oceanography &quot;&gt; &lt;/span&gt; &lt;span property=&quot;bibo:shortTitle&quot;&gt; Progress in Oceanography &lt;/span&gt; &lt;/span&gt; &lt;span property=&quot;bibo:volume&quot;&gt;47&lt;/span&gt; &lt;a property=&quot;bibo:doi&quot; href=&quot;http://dx.doi.org/10.1016/S0079-6611(00)00033-1&quot;&gt;10.1016/S0079-6611(00)00033-1&lt;/a&gt;
&lt;/li&gt;


&lt;/ul&gt;
&lt;/div&gt;



</content>
 </entry>
 
 <entry>
   <title>Ews Review Paper Chat</title>
   <link href="/2013/02/11/ews-review-paper-chat.html"/>
   <updated>2013-02-11T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/02/11/ews-review-paper-chat</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;skype-with-alan-and-noam-on-ews&quot;&gt;Skype with Alan and Noam on EWS&lt;/h2&gt;
&lt;ul&gt;&lt;li&gt; 
&lt;a href=&quot;https://github.com/cboettig/ews-review/issues/11&quot;&gt;Expand section on statistical power and noise (following draft of Alan’s intro)&lt;/a&gt;
&lt;/li&gt;&lt;li&gt; 
&lt;a href=&quot;https://github.com/cboettig/ews-review/issues/10&quot;&gt;Flush out unfinished sections in main body&lt;/a&gt;
&lt;/li&gt;&lt;li&gt; 
&lt;a href=&quot;https://github.com/cboettig/ews-review/issues/9&quot;&gt;Write discussion (after intro is done)&lt;/a&gt;
&lt;/li&gt;&lt;li&gt; 
&lt;a href=&quot;https://github.com/cboettig/ews-review/issues/8&quot;&gt;Discussion with Alan - misc notes&lt;/a&gt;
&lt;/li&gt;&lt;li&gt; 
&lt;a href=&quot;https://github.com/cboettig/ews-review/issues/7&quot;&gt;edit introduction&lt;/a&gt;
&lt;/li&gt;&lt;li&gt; 
&lt;a href=&quot;https://github.com/cboettig/ews-review/issues/6&quot;&gt;Schreiber figure&lt;/a&gt;
&lt;/li&gt;&lt;li&gt; 
&lt;a href=&quot;https://github.com/cboettig/ews-review/issues/5&quot;&gt;Kefi figure&lt;/a&gt;
&lt;/li&gt;&lt;li&gt; 
&lt;a href=&quot;https://github.com/cboettig/ews-review/issues/4&quot;&gt;Venn Diagram figure should have numbers corresponding to the references that examine each area&lt;/a&gt;
&lt;/li&gt;&lt;li&gt; 
&lt;a href=&quot;https://github.com/cboettig/ews-review/issues/3&quot;&gt;Finalize edits before sending for internal review&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;


&lt;h2 id=&quot;other&quot;&gt;Other&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Some &lt;a href=&quot;https://github.com/cboettig/knitcitations/commits?author=cboettig&quot;&gt;updates to knitcitations&lt;/a&gt; addressing special cases.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Re-organized methods section to &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes&quot;&gt;nonparametric-bayes&lt;/a&gt; manuscript.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Updates Across Various Projects</title>
   <link href="/2013/02/04/updates-across-various-projects.html"/>
   <updated>2013-02-04T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/02/04/updates-across-various-projects</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;At home after birth of Edward since Jan 19th, leaving little time for research. Assembled notes from a few side projects I’ve moved forward in the wee hours. Covers the past several days.&lt;/p&gt;
&lt;h2 id=&quot;xml-and-rdfa-parsing&quot;&gt;XML and RDFa parsing&lt;/h2&gt;
&lt;p&gt;I have been using the lab notebook to explore technology for scientific communication, including making use of semantic and linked data concepts. To illustrate some of the potential these tools can offer I’ve started working on a short post with examples parsing and exploring the XML and RDFa data in the notebook. Still forthcoming. The &lt;a href=&quot;http://any23.org&quot;&gt;any23&lt;/a&gt; API provides a great tool for this (particularly RDFa to RDF XML, where we can then take full advantage of xpath tools on the semantics).&lt;/p&gt;
&lt;h2 id=&quot;other-notebook-updates&quot;&gt;Other notebook updates&lt;/h2&gt;
&lt;p&gt;MathML: Can have Pandoc render source in MathML and MathJax will still perform the HTML rendering in all browsers. Unfortunately, certain commands seem not to parse in this mode that do parse in Pandoc mathjax mode (e.g. those with &lt;code&gt;operatorname&lt;/code&gt; in 2012-11-01 post).&lt;/p&gt;
&lt;p&gt;Updated timeout setting on twitter plugin. &lt;a href=&quot;https://github.com/cboettig/labnotebook/commit/0cb7a11247d3dd4ca040ed156a63b6a5d2197bf7&quot;&gt;0cb7a11&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;pdg-control-follow-up&quot;&gt;PDG Control Follow-up&lt;/h2&gt;
&lt;p&gt;Skype with Paul for follow-up on third working group meeting. Key steps forward on policy costs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;All comparisons should be with reference to total value/profit of the strategy, rather than induced cost. Then compare against induced values directly. (Issue #35)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Quadratic costs should appear in supplement only (Issue #45)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Real-world context framing worked out. (Issue #39)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These and further details are listed in &lt;a href=&quot;https://github.com/cboettig/pdg_control/issues?direction=desc&amp;amp;labels=policy+costs&amp;amp;page=1&amp;amp;sort=created&amp;amp;state=open&quot;&gt;issues tracker&lt;/a&gt; for the project.&lt;/p&gt;
&lt;h2 id=&quot;updates-to-knitcitations&quot;&gt;Updates to knitcitations&lt;/h2&gt;
&lt;h3 id=&quot;v0.3-3&quot;&gt;v0.3-3&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Added a new display option, &lt;code&gt;bibliography('markdown')&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;fixed BUG in the printing of the text-based name in bibliography for bibstyle-based calls&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;v0.3-2&quot;&gt;v0.3-2&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Semantic citations now enabled. &lt;code&gt;bibliography&lt;/code&gt; can print with method ‘rdfa’ to provide RDFa enhanced HTML bibliography data, and citations can take cito arguments as an option. (Closes issues #16 and #17)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bibliography&lt;/code&gt; now takes more options to match the &lt;code&gt;bibstyle&lt;/code&gt; and &lt;code&gt;print.bibentry&lt;/code&gt; functions.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;citet&lt;/code&gt; and &lt;code&gt;citep&lt;/code&gt; take an optional argument for formating the citation, defaulting to &lt;code&gt;authoryear&lt;/code&gt; format. Future versions may move this into an option.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;newbib()&lt;/code&gt; function initializes and clears existing cache files.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;README.md updated with semantic examples and more background text (generated by inst/examples/README.Rmd).&lt;/li&gt;
&lt;li&gt;Some basic unit tests built in. Could use more, but meanwhile closes #8.&lt;/li&gt;
&lt;li&gt;Test cases work with knit2html button in RStudio, closes #14&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;v0.3-1&quot;&gt;v0.3-1&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Switched to handling citation data using environment rather than an external bibfile. This does not refer to the handling of user-provided bibtex files as input data, which are supported as before, but changes only the backend management of that data. The external bibtex file method can be switched back on by setting &lt;code&gt;options(&amp;quot;bibtex_data&amp;quot; = TRUE)&lt;/code&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;There is no need to call &lt;code&gt;print(bibliography, &amp;quot;html&amp;quot;)&lt;/code&gt;, one can simply call &lt;code&gt;bibliography()&lt;/code&gt; or &lt;code&gt;bibliography(&amp;quot;html&amp;quot;)&lt;/code&gt;. Sort is still an option, other options that were for internal use (&lt;code&gt;debug&lt;/code&gt;, &lt;code&gt;remove_duplicates&lt;/code&gt;) are removed as they are no longer necessary.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Several new functions have been added to handle the new methods.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;v0.2-0&quot;&gt;v0.2-0&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Fix vignette error that prevents knitr 1.0 submission&lt;/li&gt;
&lt;li&gt;Fixed errors on installing package and lack of entries in bibliography&lt;/li&gt;
&lt;li&gt;Semantic print option added but still in early testing&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;/h2&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;O’Dwyer, J. P. &amp;amp; Green, J. L. 2010 Field theory for biogeography: a spatially explicit model for predicting patterns of biodiversity. Ecology letters 13, 87–95. (doi:10.1111/j.1461-0248.2009.01404.x)&lt;/li&gt;
&lt;li&gt;Stewart, E. C. A., Almes, G. T., Mccaulay, D. S. &amp;amp; Bradley, C. 2009 Cyberinfrastructure Software Sustainability and Reusability : Report from an NSF-funded workshop Report from an NSF-funded workshop held 27 and 28 March 2009.&lt;/li&gt;
&lt;li&gt;Ingram, T. &amp;amp; Mahler, D. L. 2013 SURFACE: detecting convergent evolution from comparative data by fitting Ornstein-Uhlenbeck models with stepwise AIC. Methods in Ecology and Evolution , 1–25. (doi:10.1111/2041-210X.12034)&lt;/li&gt;
&lt;li&gt;Shelton, A. &amp;amp; Munch, S. 2012 Maternal age, fecundity, egg quality, and recruitment: linking stock structure to recruitment using an age-structured Ricker model. Canadian Journal of … 1641, 1631–1641. (doi:10.1139/F2012-082)&lt;/li&gt;
&lt;li&gt;Regan, T. J., Chadès, I. &amp;amp; Possingham, H. P. 2011 Optimally managing under imperfect detection: a method for plant invasions. Journal of Applied Ecology 48, 76–85. (doi:10.1111/j.1365-2664.2010.01915.x)&lt;/li&gt;
&lt;li&gt;Gewin, V. 2013 Turning point: Carl Boettiger. Nature 493, 711–711. (doi:10.1038/nj7434-711a)&lt;/li&gt;
&lt;li&gt;Nicol, S. &amp;amp; Chadès, I. 2012 Which states matter? An application of an intelligent discretization method to solve a continuous POMDP in conservation biology. PloS one 7, e28993. (doi:10.1371/journal.pone.0028993)&lt;/li&gt;
&lt;li&gt;McDonald-Madden, E., Chadès, I., McCarthy, M. a, Linkie, M. &amp;amp; Possingham, H. P. 2011 Allocating conservation resources between areas where persistence of a species is uncertain. Ecological applications : a publication of the Ecological Society of America 21, 844–58.&lt;/li&gt;
&lt;li&gt;Krell 2011 The U.S. Department of Energy Computational Science Graduate Fellowship 1991-­‐2011: Recipient Outcomes and Programmatic Impacts.&lt;/li&gt;
&lt;li&gt;Dougherty, D. T., Hilborn, R., Punt, A. E. &amp;amp; Stewart, I. J. 2013 Modeling co-occurring species : a simulation study on the effects of spatial scale for setting management targets. 8, 1–8.&lt;/li&gt;
&lt;li&gt;Chadès, I., Martin, T. G., Nicol, S., Burgman, M. a, Possingham, H. P. &amp;amp; Buckley, Y. M. 2011 General rules for managing and surveying networks of pests, diseases, and endangered species. Proceedings of the National Academy of Sciences of the United States of America 108, 8323–8. (doi:10.1073/pnas.1016846108)&lt;/li&gt;
&lt;li&gt;Chad, I., Carwardine, J., Martin, T. G. &amp;amp; Nicol, S. In press. MOMDPs : A Solution for Modelling Adaptive Management Problems. , 267–273.&lt;/li&gt;
&lt;li&gt;Kapaun, U. &amp;amp; Quaas, M. 2012 Does the optimal size of a fish stock increase with environmental uncertainties?&lt;/li&gt;
&lt;li&gt;Mattmann, C. A. 2013 Computing: A vision for data science. Nature 493, 473–5. (doi:10.1038/493473a)&lt;/li&gt;
&lt;li&gt;Seekell, D. a., Cline, T. J. &amp;amp; Winchcombe, R. J. 2013 Can Management Reduce Harvest Inequality in Recreational Fisheries? North American Journal of Fisheries Management 33, 148–152. (doi:10.1080/02755947.2012.746246)&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>Data Uris For Image Archives</title>
   <link href="/2013/01/24/Data-URIs-for-image-archives.html"/>
   <updated>2013-01-24T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/01/24/Data-URIs-for-image-archives</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;Figures have been one of the standing challenges of the open notebook. Displaying figures online requires that they are first uploaded to a server somewhere. Recently I have used automated uploads to external servers such as figshare to host all images generated in the course of my research, and simply point to those graphs which I wish to include in a notebook page using an image link. Unfortunately, this means that the images themselves are not being permanently archived when I deposit my notebook entries into their annual archives on figshare. (Because figshare provides objects with unique identifier DOIs and benefits from &lt;a href=&quot;http://clockss.org&quot;&gt;CLOCKSS&lt;/a&gt; archival preservation, I use it to ensure a permanent backup of the notebook contents is available). I’ve recently discovered Data URIs, which provide a way to embed the image data directly into HTML (or markdown) entries. I am trying to decide if they offer a better way to address this challenge, so working through my thinking here.&lt;/p&gt;
&lt;h2 id=&quot;history-of-figure-management-in-the-notebook&quot;&gt;History of Figure management in the notebook&lt;/h2&gt;
&lt;p&gt;When I first started an open online notebook on the MediaWiki platform &lt;a href=&quot;http://openwetware.org/wiki/User:Carl_Boettiger&quot;&gt;OpenWetWare&lt;/a&gt;, I simply uploaded all images manually to the wiki. Soon I discovered that it was much easier to upload them programmatically. To accomplish this, I used Flickr as the image hosting service. Flickr gave me a few convenient tools like batch uploads, pre-sized images and slide-shows for embedding. More conveniently, Flickr allowed me to automate the uploading of images through the API. Using the API in my R scripts I could &lt;a href=&quot;http://www.carlboettiger.info/2010/12/10/socialr-an-r-package-to-track-the-status-of-computations-with-social-network-tools.html&quot;&gt;automate uploading&lt;/a&gt; of the figures as they were created when scripts were run. This integration became easier with my adoption of &lt;code&gt;knitr&lt;/code&gt;, which has the option to automatically upload images built in (using imgur.com). I soon extended this to &lt;a href=&quot;http://www.carlboettiger.info/2012/02/28/knitr-with-flickr-and-wordpress.html&quot;&gt;use Flickr or Wordpress&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;challenges-of-linked-images&quot;&gt;Challenges of linked images&lt;/h2&gt;
&lt;p&gt;While this simplified the workflow considerably, it does not lend itself to archiving content well. Since &lt;a href=&quot;http://www.carlboettiger.info/2012/09/19/migrating-from-wordpress-to-jekyll.html&quot;&gt;migrating to Jekyll&lt;/a&gt;, it is relatively straight forward to archive the notebook entry by entry in markdown format, without all the external web content for the appearance. Unfortunately, with images linked in from Flickr and other external hosting services are not included in this way. Even archiving the entire HTML source for the site doesn’t help, since the figures are on a remote repository. When I migrated my OWW and Wordpress notebooks to Jekyll, the image links remained pointing to OWW or Flickr or wherever the images were originally uploaded. Should Flickr vanish (as Delicious effectively did), the images would be lost. The copies of the notebook entries I &lt;a href=&quot;http://figshare.com/authors/Carl%20Boettiger/96387&quot;&gt;deposit on figshare&lt;/a&gt; only have the links to these entries, not the entries themselves. Even if the images were copied over, the entry would still point to the original URL, not the copy. To address this, I started &lt;a href=&quot;http://www.carlboettiger.info/2012/11/30/Note-on-notebook-figures.html&quot;&gt;archiving the images locally&lt;/a&gt;. This removed the external dependency and kept everything together so that it could be archived in a way that preserved the link structure, but has its own drawbacks.&lt;/p&gt;
&lt;p&gt;As I do far more runs of the scripts then I post to the notebook (though most of these can be found in the Github links), the image archive is much larger than what images are actually included in the notebook. Another issue is that the notebook source files are all conveniently managed with git and stored on Github, so storing the images locally involves explicitly excluding the image files which are both much larger and as binaries not ideal for version management.&lt;/p&gt;
&lt;h2 id=&quot;data-uris&quot;&gt;Data URIs&lt;/h2&gt;
&lt;p&gt;The simple solution is to avoid linking the images externally, but instead embed the image data directly into the notebook entry. &lt;a href=&quot;http://en.wikipedia.org/wiki/Data_URI_scheme&quot;&gt;Data URIs&lt;/a&gt; do exactly that, encoding all the image as part of the link url following a declaration of MIME type, such as&lt;/p&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;&lt;span class=&quot;kw&quot;&gt;&amp;lt;img&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; src=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA&lt;/span&gt;
&lt;span class=&quot;st&quot;&gt;AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO&lt;/span&gt;
&lt;span class=&quot;st&quot;&gt;9TXL0Y4OHwAAAABJRU5ErkJggg==&amp;quot;&lt;/span&gt; &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Image data URIs are usually introduced to reduce the load and waiting time on the server, which has to query each external image separately (CSS sprites are a more effective way to accomplish that goal; which is what I use for the icons on this site). They are also convenient for generating stand-alone HTML files, in which the externally linked data sources, such as images, CSS, etc, are encoded as 64bit data strings.&lt;/p&gt;
&lt;h2 id=&quot;generating-uris&quot;&gt;Generating URIs&lt;/h2&gt;
&lt;p&gt;Given an image, we can generate the data URI using the &lt;code&gt;knitr&lt;/code&gt; function &lt;code&gt;image_uri(&amp;quot;image_name.png&amp;quot;)&lt;/code&gt;. Knitr also supports data URIs as directly as an image output option, in just the same way that one would specify a custom upload function, using the command&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;opts_knit$&lt;span class=&quot;kw&quot;&gt;set&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;upload.fun =&lt;/span&gt; image_uri)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Pandoc can also generate HTML with data URIs for images in place of the remote image links using the &lt;code&gt;--self-contained&lt;/code&gt; option, where it will download all the external images and encode them. This may be the best strategy for creating archival versions of entries for figshare, etc. Unfortunately the conversion is not available when running markdown to markdown, but can be effected using markdown to HTML, and then back. The only downside of this approach is that the yaml header formatting is lost, and the output markdown used is Pandoc’s flavor.&lt;/p&gt;
&lt;h2 id=&quot;difficulties-of-data-uris&quot;&gt;Difficulties of Data URIs&lt;/h2&gt;
&lt;h3 id=&quot;not-displayed-in-github-markdown&quot;&gt;Not displayed in Github Markdown&lt;/h3&gt;
&lt;p&gt;My chief disappointment is realizing that Github’s markdown renderer will not display data URIs, so images won’t show up on the Github copy of &lt;code&gt;knitr&lt;/code&gt; markdown files. It would have been most convenient to have knitr always embed the images for my scripts and avoid external linking for Github files. This would be particularly helpful for scripts run on remote servers where the compute nodes do not have external web connections and so images have to be uploaded from the head node after running the script. Oh well, hopefully Github will consider addressing this.&lt;/p&gt;
&lt;p&gt;I don’t see a good reason why Github markdown doesn’t display images, since markdown displays any other valid HTML. Perhaps it is security related since almost anything can be put in a data URI. It may have something to do with how there server is handling images to begin with, since the images that are displayed come not from the original URL but from a separate link on &lt;code&gt;akamai.net&lt;/code&gt;. I did send in a suggestion that they address this and was told they would look into it. Meanwhile I will continue uploading these images externally, and converting to data URIs when generating the files for the notebook version.&lt;/p&gt;
&lt;h3 id=&quot;large-file-sizes&quot;&gt;Large File Sizes&lt;/h3&gt;
&lt;p&gt;Because all of the image encoding is embedded directly within the link, and these data URIs are huge. This creates several issues.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The markdown a deal less readable before it is rendered. A decent editor can just fold these away (e.g. select block and &lt;code&gt;zf&lt;/code&gt; in vim).&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;The data URIs increase the filesize of the HTML dramatically. Compression is about 1/3rd more than the original image sizes. This can slow load times and makes the repository larger. As most images in the notebook are generated as basic pngs, the file sizes aren’t huge (100 Kb range), but much larger than the raw HTML.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Not all browsers support Data URIs, so images may not render in older versions of IE&lt;/li&gt;
&lt;li&gt;The markdown parser takes much longer to generate the output. This appears to actually time out Jekyll building in my current notebook.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;resolution&quot;&gt;Resolution&lt;/h2&gt;
&lt;p&gt;I have a branch of the notebook, &lt;a href=&quot;https://github.com/cboettig/labnotebook/blob/image-uri&quot;&gt;image-uri&lt;/a&gt;, in which (almost) all images are converted to data URIs. Unfortunately, the images do not display on the Github copy and the branch takes rather much longer to compile, making this an impractical standard solution for the notebook.&lt;/p&gt;
&lt;p&gt;As I discussed above, I have recently experimented with hosting all images I generate on the local server, removing the dependency and archival concerns of Figshare. Unfortunately, it makes for a very large and potentially more fragile site to have to carry around the complete image log, 99% of which does not appear in the notebook but only on Github script runs. Keeping only the images used in posts makes more sense, but requires an extra step which is otherwise redundant, since the web being what it is can just point to the external copy. To address the primary concern is making sure that the archival copies on figshare include the images, I think I will stick with compiling an archival version with Data URIs while otherwise continuing to host the images on Flickr.&lt;/p&gt;
&lt;p&gt;Archival copies can be made using Pandoc by generating the site using the &lt;code&gt;--self-contained&lt;/code&gt; option for the pandoc parser in &lt;code&gt;_config.yaml&lt;/code&gt;, though this is rather slow. Then the archive would be the HTML files in the &lt;code&gt;_site&lt;/code&gt; directory, rather than the raw markdown files. While alternatively I could use a script to just render the markdown, overall it may make more sense to archive the stand-alone HTML, since it includes more metadata and the advantages of the XML formatting.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Tipping Points Comment In Nature</title>
   <link href="/2013/01/12/tipping-points-comment-in-nature.html"/>
   <updated>2013-01-12T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2013/01/12/tipping-points-comment-in-nature</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;On Wednesday my comment piece with Alan, &lt;a href=&quot;http://www.nature.com/nature/journal/v493/n7431/full/493157a.html&quot;&gt;&lt;em&gt;Tipping points: from patterns to predictions&lt;/em&gt;&lt;/a&gt; appeared in Nature (next to a nice &lt;a href=&quot;http://www.nature.com/nature/journal/v493/n7431/full/493159a.html&quot;&gt;comment by Heather Piwowar&lt;/a&gt; on NSF’s move to recognizing products of research more broadly than publications alone).&lt;/p&gt;
&lt;p&gt;Heather has written an excellent &lt;a href=&quot;http://researchremix.wordpress.com/2013/01/11/process-behind-a-nature-comment/&quot;&gt;post&lt;/a&gt; on the process of writing, which rings true with my own experience. Working with an editor with clear expertise in science writing and communication who was otherwise unfamiliar with the details of this field was an immensely rewarding experience, and her contributions really ought to be recognized more clearly. She stuck with me as I struggled to explain concepts I wasn’t even sure were well understood in my subfield, and then helped me rephrase towards a larger audience. I learned how specific examples and even potentially extraneous details could help anchor and clarify a description. Of course, some compromise was inevitable. I later had some explaining to do when the fact-checker questioned some of my citations. Yes, I know Sebastian doesn’t actually talk about salemanders in Schreiber and Randolf 2008, and Stephen Lade and Thilo Gross don’t talk about cod collapse; but their models do, I promise!&lt;/p&gt;
&lt;p&gt;I doubt any scholar takes on a topic of close personal interest in the space of two pages and feels completely happy with the resulting message. While the piece will no doubt be received as a pushback against the bandwagon, our goal was more road-map to interesting open questions than critique of the early steps. In the piece, I aimed to raise two important issues or gaps in the existing literature, and then to propose two potential ways forward for each issue. The goal is not to close the door on early warning signals, but to further unroll the map and draw more attention to the uncharted lands.&lt;/p&gt;
&lt;h2 id=&quot;warning-signals-without-controls&quot;&gt;Warning signals without controls&lt;/h2&gt;
&lt;p&gt;The first gap we highlight is the need to understand how early warning signals might be applied in the real world, rather than in experimental designs that rely on replicates and controls to identify what is and what isn’t a warning signal. We propose two potential directions, one primarily empirical, one primarily theoretical:&lt;/p&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Establish baselines.&lt;/strong&gt; The challenges to doing this well are manifold, but we won’t know if or how to address them without more active research.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Statistical Models&lt;/strong&gt; In the absence of controls, appropriate null models might be able to simulate comparison groups we do not have. I have begun to explore this in my own work, see &lt;a href=&quot;/vita.html&quot;&gt;Boettiger and Hastings (2012).&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;inability-to-leverage-context-specific-information&quot;&gt;Inability to leverage context-specific information&lt;/h2&gt;
&lt;p&gt;In our comment, this comes off as condeming the generality of warning signals. Early warning signals such as variance (Carpenter and Brock 2006) or spatial autocorrelation (Dakos et al 2011) may incerase before a catastrophic transition, but they can also decrease (Schreiber and Rudolf 2008, Bel et al 2012).&lt;/p&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use all the data&lt;/strong&gt;. While a lack of detailed mechanistic understanding of complex systems is more often the rule then the exception, we mustn’t give into the huberis that we can ignore context-specific information we know. When facing problems as challenging as detecting sudden shifts are no time to go battle with one hand tied behind our backs. By working with domain experts in areas where transitions are best understood, we may learn how best to do this.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Follow the data&lt;/strong&gt; A more widely appreciated issue for any signal is the concern of an adequately long and well sampled data set. While the globe ushers in an era of “big data”, long time series aren’t easy to come by. Perhaps this is a case in which searching under the street light for the keys can pay off. Early warning signal research has already shown us once how to find weak patterns if we know what to look for. A promising line of of work would identify (potentially system-specific) signals in the kind of data that is most likely to be available, such as high-resolution spatial imagery. Ignoring such patterns because they do not generalize to other systems will only slow us down.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;icanhazpdf&quot;&gt;#icanhazpdf?&lt;/h3&gt;
&lt;p&gt;Unfortunately the piece is not available open access (though do write to me for a reprint if you are interested). I can distribute the original text in 6 months. As an advocate for open science, my 0/9 record of publishing in open access journals might raise eyebrows, if also unequivocally demonstrating my commitment to pragmatism ;-). All my other papers are available through as green open access/preprints on arXiv, and I hope this one can join them when the terms permit.&lt;/p&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;Lade, S. J. &amp;amp; Gross, T. Early Warning Signals for Critical Transitions: A Generalized Modeling Approach. PLoS Computational Biology 8, e1002360 (2012). doi:10.1371/journal.pcbi.1002360&lt;/li&gt;
&lt;li&gt;Schreiber, S. J. &amp;amp; Rudolf, V. H. W. Crossing habitat boundaries: coupling dynamics of ecosystems through complex life cycles. Ecology Letters 11, 576–87 (2008). doi:10.1111/j.1461-0248.2008.01171.x&lt;/li&gt;
&lt;li&gt;Dakos, V., Kéfi, S., Rietkerk, M., Nes, E. H. Van &amp;amp; Scheffer, M. Slowing Down in Spatially Patterned Ecosystems at the Brink of Collapse. The American Naturalist (2011).doi:10.1086/659945&lt;/li&gt;
&lt;li&gt;Bel, G., Hagberg, A. &amp;amp; Meron, E. Gradual regime shifts in spatially extended ecosystems. Theoretical Ecology 5, 591–604 (2012). doi:10.1007/s12080-011-0149-6&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>Learning Jekyll</title>
   <link href="/2012/12/30/learning-jekyll.html"/>
   <updated>2012-12-30T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/12/30/learning-jekyll</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;h1 id=&quot;some-quick-thoughts-on-learning-jekyll&quot;&gt;Some quick thoughts on learning Jekyll&lt;/h1&gt;
&lt;p&gt;After recieving a few queries on how to get started with Jekyll I thought I’d jot down my own opinions here. Of course there is already rather good documentation for the software and plenty of blogs providing tutorials. While no doubt more than adequate, I have more opinions on how to get started actually &lt;em&gt;learning&lt;/em&gt; what’s going on than I could easily fit into a tweet, and also a couple favorite links to references so I thought I’d jot down my reply in long form here.&lt;/p&gt;
&lt;h2 id=&quot;brief-background&quot;&gt;Brief Background&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/mojombo/jekyll&quot;&gt;Jekyll&lt;/a&gt; is a fantastic and popular static blogging platform, written in Ruby by a Github founder, &lt;a href=&quot;http://tom.preston-werner.com/&quot;&gt;Tom Preston-Werner&lt;/a&gt;, which powers this site (at least currently). Similar static website generators exist for Python (&lt;a href=&quot;https://github.com/hyde/hyde&quot;&gt;Hyde&lt;/a&gt;) Haskell (&lt;a href=&quot;https://github.com/jgm/yst&quot;&gt;yst&lt;/a&gt;), and probably others, but Jekyll is quite widespread.&lt;/p&gt;
&lt;p&gt;With the (unofficial) slogan of the bloging platform for hackers, Jekyll is aimed at folks who don’t mind a little coding. If you’re looking for a polished, user-friendly product where a huge community of developers has written most imaginable extensions, check out Wordpress.org. If you want something where you can easily get into the guts and customize everything, Jekyll may be the best game in town. Compared to a dynamic site, a static site is much more lightweight, which translates into faster, more stable, and less expensive. What’s not to like?&lt;/p&gt;
&lt;h2 id=&quot;where-to-start&quot;&gt;Where to start?&lt;/h2&gt;
&lt;p&gt;A couple pre-configured Jekyll setups have emerged to reduce the learning curve, most notably &lt;a href=&quot;https://github.com/imathis/octopress&quot;&gt;Octopress&lt;/a&gt; and &lt;a href=&quot;https://github.com/plusjade/jekyll-bootstrap&quot;&gt;Jekyll Bootstrap&lt;/a&gt;. In my opinion, in an attempt to make things easier through tricks such as automated Ruby makefiles (Rakefiles) I think these projects have actually made Jekyll appear much more complicated than it really is, as evidenced by the number of talented programmers running Octopress with the identical configuration. They may get you started faster, but their use of advanced techniques to provide more functionality out-of-the-box makes for a tougher learning curve.&lt;/p&gt;
&lt;p&gt;See the Jekyll-Bootstrap’s &lt;a href=&quot;http://jekyllbootstrap.com/lessons/jekyll-introduction.html&quot;&gt;introduction&lt;/a&gt; to Jekyll for a nice explanation of how Jekyll is laid out. Understand the basic YAML headers, and the role of the &lt;code&gt;_layout&lt;/code&gt;, &lt;code&gt;_includes&lt;/code&gt; and &lt;code&gt;_posts&lt;/code&gt; directories, and you’ve mastered the basics. Or read on below for my take on getting started.&lt;/p&gt;
&lt;h2 id=&quot;running-jekyll&quot;&gt;Running Jekyll&lt;/h2&gt;
&lt;p&gt;For a basic site hosted on Github, one never actually has to run Jekyll locally – just push the site to a gh-pages branch of a Github repository, or to the master branch of a repository named &lt;code&gt;username.github.com&lt;/code&gt; for a personal website, and Jekyll will be run by the server. Jekyll is frequently run locally instead, allowing the user to copy the static website it generates to any (static) web server (see Hosting options, below). Simply install Jekyll following the directions on its &lt;a href=&quot;https://github.com/mojombo/jekyll&quot;&gt;homepage README&lt;/a&gt;.[^1]&lt;/p&gt;
&lt;h2 id=&quot;my-rough-guide-to-learn-by-doing&quot;&gt;My rough guide to learn-by-doing&lt;/h2&gt;
&lt;p&gt;I believe the best way to start with Jekyll is start with a really bare-bones site. You add features as you need them, making maintenance easy.&lt;/p&gt;
&lt;p&gt;Start with an empty repository. Create a markdown file, say, &lt;code&gt;index.md&lt;/code&gt;. Write whatever you want in standard markdown, just stick a &lt;a href=&quot;http://en.wikipedia.org/wiki/YAML&quot;&gt;YAML&lt;/a&gt; header on the top. Stick what? From your standardized testing days, think something like &lt;code&gt;markdown:html :: yaml:xml&lt;/code&gt;. Three &lt;code&gt;-&lt;/code&gt; on their own line to start, three &lt;code&gt;-&lt;/code&gt; on another line to close define the block of YAML data, whose mere existence is enough to get Jekyll to pay attention to that file. Here we specify any metadata we want.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    ---
    layout: default
    ---

    # My site title

    some text
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And voilà, we have a functional Jekyll site. The basic thing to remember is that everything else is gravy, to be mastered as you have a need for it. The advanced features can be super helpful once you know them, but in the beginning they may just get in the way of understanding what’s actually going on.&lt;/p&gt;
&lt;h3 id=&quot;getting-deeper-jekyll-site-file-structure&quot;&gt;Getting deeper: Jekyll site file structure&lt;/h3&gt;
&lt;p&gt;Directories that are functional for Jekyll but do not appear in the generated website start with an underscore &lt;code&gt;_&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Root directory. You don’t need any of the standard directories for a barebones site. As we saw above, any markdown file with YAML header matter in the root directory will be parsed. Don’t like markdown? We could write these files in html (with .html extension) instead. Jekyll will parse them as long as they have some YAML header matter, allowing us to still use things like page templates and other tricks from Liquid code described below.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;_posts&lt;/code&gt; Your posts live here. They should be titled in &lt;code&gt;YYYY-MM-DD-post-title.md&lt;/code&gt; format, which will allow Jekyll to automatically figure out the post date and title, while also keeping the posts neatly organized in this directory. (The title and the publication date, optionally including time can alternatively be given in the YAML header matter if you don’t like this convention. See below).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;_layout&lt;/code&gt; For a completely barebones site, you don’t need this directory. Here you can provide files defining the basic HTML layout, or template, for each of the pages in your website. If your familiar with HTML, you can go ahead and set up a page as you like, and then add the single line of Liquid code in the body to pull in the HTML generated by parsing the markdown files. The mimimal layout file might look something like this (see an HTML tutorial for details):&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;&lt;span class=&quot;er&quot;&gt;&amp;lt;&lt;/span&gt;!doctype html&amp;gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;html&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; lang=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;en&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; charset=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;utf-8&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt; {{ page.title }} &lt;span class=&quot;kw&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;

{{ page.content }}

&lt;span class=&quot;kw&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;where the double braces and words &lt;code&gt;page.title&lt;/code&gt; and &lt;code&gt;page.content&lt;/code&gt; are Liquid code that will tell Jekyll to insert the title and content of the page in the appropriate spot. To use a layout, save this file in &lt;code&gt;_layout&lt;/code&gt; with the desired layout name, e.g. &lt;code&gt;plainlayout&lt;/code&gt;, and then it can be applied to any page (markdown or html file in the root directory) or post by adding &lt;code&gt;layout: plainlayout&lt;/code&gt; to the YAML header of that file. This provides a super convenient way to create page templates for a static site.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;_includes&lt;/code&gt; Often one might have several layouts corresponding to different kinds of pages on your site. To avoid copy-pasting the parts of the layout that stay the same (perhaps all have the same header matter pointing to your CSS files and analytics tracker), you can just place these snippets inside the &lt;code&gt;_includes&lt;/code&gt; directory with their own filenames. For instance, we could move the header text to a file called &lt;code&gt;header&lt;/code&gt; in that directory with the contents:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;&lt;span class=&quot;er&quot;&gt;&amp;lt;&lt;/span&gt;!doctype html&amp;gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;html&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; lang=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;en&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; charset=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;utf-8&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt; {{ page.title }} &lt;span class=&quot;kw&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To automatically reuse a snippet of HTML code in any file on your site (a layout file or other), we need to learn one more Liquid command. This one goes between brace-percent symbols, and uses the command &lt;code&gt;include&lt;/code&gt;, followed by the filename, like so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{% include header %}
&amp;lt;body&amp;gt;
{{ page.content }}
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above example provides a shorter layout file, which pulls in the header snippet. If you have only one layout, this is of course pointless, but the more you add to and change your site, the more useful the ability to reuse a single HTML chunk with just a line of code becomes.&lt;/p&gt;
&lt;h3 id=&quot;configuration&quot;&gt;Configuration&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;YAML&lt;/strong&gt; and the &lt;code&gt;_config.yml&lt;/code&gt; file. Recall that YAML is the very human-readable data structure, whose syntax is explained quite throughly on &lt;a href=&quot;http://en.wikipedia.org/wiki/YAML&quot;&gt;it’s wikipedia page&lt;/a&gt;. One glance at an example reveals almost all you need to know about the syntax, such as:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;
---
layout: post
category: ecology
tags: 
  - howto
  - jekyll
modified: 2013-01-07
---&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lists can be done in a variety of ways, comma-s&lt;/p&gt;
&lt;p&gt;One of the Jekyll beginner’s mysteries is knowing just what words/metadata/variables are already available in Jekyll and how to add those that are not. &lt;a href=&quot;https://github.com/mojombo/jekyll/wiki/Template-Data&quot;&gt;A list appears on the Jekyll Wiki&lt;/a&gt;. Note that the syntax uses the ruby structure, so &lt;code&gt;page.title&lt;/code&gt; and &lt;code&gt;page.date&lt;/code&gt; are both part of the page. We can create any custom variable by adding it to that page’s yaml header. For instance, &lt;code&gt;modified&lt;/code&gt; is not defined anywhere in Jekyll’s default Template Data, but none-the-less we can access this modification date in this page’s &lt;code&gt;layout&lt;/code&gt; or the page itself using {{ page.modified }} liquid tag.&lt;/p&gt;
&lt;p&gt;Metadata belonging to the site as a whole, rather than a particular page, is specified in the &lt;code&gt;_config.yml&lt;/code&gt; file, along with a few options telling Jekyll how to parse the site. Again, the &lt;a href=&quot;https://github.com/mojombo/jekyll/wiki/Configuration&quot;&gt;Jekyll wiki has a great overview&lt;/a&gt;. As the extension implies, this entire file is in YAML. If we want to create new global variables, such as our twitter account, we can just add them to the YAML like so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;author:
  twitter: cboettig
  github: cboettig&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(note the indentation for hierarchy) and now my twitter username is available through the liquid command &lt;code&gt;site.author.twitter&lt;/code&gt;. Again, it’s just another trick to insert some text, just like &lt;code&gt;_layout&lt;/code&gt; and &lt;code&gt;_includes&lt;/code&gt;. Only use can prove how helpful this can be.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Markdown parser hell&lt;/strong&gt;. A lot of Jekyll adopters are already familar with Github and it’s flavor of markdown with such features as fenced codeblocks, thus it comes as real suprise to run into advice explaining how code blocks need to be wrapped in the never-heard-of “Liquid” syntax &lt;code&gt;{% highlight %}&lt;/code&gt;. Ignore this nonsense. How your markdown is parsed depends on what flavor of markdown you use, and there is a special level of hell for anyone inventing a new flavor (&lt;a href=&quot;http://www.codinghorror.com/blog/2012/10/the-future-of-markdown.html&quot;&gt;Atwood 2012&lt;/a&gt;). Fortunately Github’s Tom Preston-Werner finally gave up the perfect irony that Github’s flavor was not one of the built-in Jekyll parsers (though being a hacker system, this could be added manually), and you can now get that behavior by setting your chosen parser to be &lt;code&gt;redcarpet&lt;/code&gt; with the convenient extensions [^2]&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;markdown: redcarpet
redcarpet:
  extensions: [&amp;quot;no_intra_emphasis&amp;quot;, &amp;quot;fenced_code_blocks&amp;quot;, &amp;quot;autolink&amp;quot;, &amp;quot;tables&amp;quot;, &amp;quot;with_toc_data&amp;quot;]&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;more-advanced-tricks&quot;&gt;More advanced tricks&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Liquid&lt;/strong&gt; Your next stop should really be to read &lt;a href=&quot;https://github.com/Shopify/liquid/wiki/Liquid-for-Designers&quot;&gt;Liquid for Designers&lt;/a&gt;. Liquid is the glue that specifies all the rules needed to assemble your site, and is quite simple. Understand how Liquid works and you’ve mastered Jekyll. Jekyll provides &lt;a href=&quot;https://github.com/mojombo/jekyll/wiki/Liquid-Extensions&quot;&gt;some additional Liquid functions&lt;/a&gt; common for blogs.&lt;/p&gt;
&lt;p&gt;Your next stop is to get some really nice customizable CSS scaffolding to control the layout for your site. While there’s a huge number of free CSS themes available, this isn’t 2002, so head on over to &lt;a href=&quot;http://twitter.github.com/bootstrap&quot;&gt;Twitter-Bootstrap&lt;/a&gt; (a project originally created by some of the programmers at Twitter, now evolved to it’s own community). The CSS-based grid layout and some very nice JQuery Javascripts tools can make your site as pretty and as interactive as you can imagine. Like Octopress, prebuilt CSS can lead to all sites looking the same. Check out themes for Bootstrap, and the excellent set of icons by &lt;a href=&quot;http://fortawesome.github.com/Font-Awesome/&quot;&gt;FontAwesome&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Your final step is where the hacking really begins. Now and again you imagine something you just can’t do with these tools. Your only recourse is to &lt;del&gt;ask on &lt;a href=&quot;http://stackoverflow.com&quot;&gt;Stackoverflow&lt;/a&gt; for someone to do it for you&lt;/del&gt; learn a bit of Ruby. Anything you can write in Ruby you can add to Jekyll as a “plugin”, by defining a Liquid extension for a Ruby function. Ruby is clearly a favorite language of web-developers thanks to its dynamic-site implementation Ruby-on-Rails and a vibrant Github community, so there’s a wealth of useful tools, including an implementation to most APIs you might care to interact with (Github, Twitter, various Google APIs, are among the ones I’m using).&lt;/p&gt;
&lt;h2 id=&quot;hosting-options&quot;&gt;Hosting options&lt;/h2&gt;
&lt;p&gt;Because Jekyll generates a static site, it can be hosted almost anywhere for nothing or next to nothing in costs. The primary question to consider is your choice of domain name. If you wish to host your site from university domain name, just copy the contents of &lt;code&gt;_site&lt;/code&gt; into your &lt;code&gt;public_html&lt;/code&gt; or similarly named directory on the web server.&lt;/p&gt;
&lt;p&gt;While having a university affiliated domain can appear more official and help with discoverability, buying your own domain name as your permanent Internet home may be a more reliable long-term solution. Once you’ve purchased a domain name from a provider, a static site can be hosted at your own domain name for next to nothing on &lt;a href=&quot;http://docs.amazonwebservices.com/AmazonS3/latest/dev/WebsiteHosting.html&quot;&gt;Amazon S3&lt;/a&gt;, or for literally nothing &lt;a href=&quot;https://help.github.com/articles/setting-up-a-custom-domain-with-pages&quot;&gt;through Github&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;[1]: Details on installing and running ruby gems for Jekyll will vary by operating system, so I won’t bother with more details here. Some further background for linux based platforms at least appears in my &lt;a href=&quot;http://www.carlboettiger.info/README.html&quot;&gt;site’s info file&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/12/27/notes.html"/>
   <updated>2012-12-27T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/12/27/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h1 id=&quot;nonparametric-bayes&quot;&gt;Nonparametric Bayes&lt;/h1&gt;
&lt;h2 id=&quot;continuing-sensitivity-analysis&quot;&gt;Continuing sensitivity analysis&lt;/h2&gt;
&lt;p&gt;The commit log to &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commits/af970f7c4ac759b95fca929b87cd06d45a5d2178/inst/examples/sensitivity.md&quot;&gt;sensitivity.md&lt;/a&gt; and earlier to &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commits/6aba5dce46370c600351eff270a76a664dacc7db/inst/examples/myers-exploration.md&quot;&gt;myer-exploration.md&lt;/a&gt; (now depricated) capture the summary figures for replicate runs of the observation data, with commits corresponding to various parameter configurations, etc. Here is a nice collection of replicates from &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/af970f7c4ac759b95fca929b87cd06d45a5d2178/inst/examples/sensitivity.md&quot;&gt;sensitivity.md&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Harvest during observations&lt;/strong&gt; Tweaked calculation of observation data given the harvest regime under which observations were taken (simulation was not implementing all harvests).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Also adjusted norm used in GP (the parametric use log-normal densities in calculating the transition function on the untransformed data. The GP, also on untransformed data, uses normal noise as per its model).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Relaxed priors, shows no impact on GP performance.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;non-stationary-dynamics&quot;&gt;Non-stationary dynamics&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Ran the Allen et al. Allee model under conditions for non-stationary stable states (e.g. period 2, period 4) etc, with and without substantial process noise (to confirm the cyclical pattern). Shows good performance of GP against terrible perfomance of alternative parametric approaches. Closes issue &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/16&quot;&gt;#16&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-27-16-11-45-5da7c1081b-unnamed-chunk-2.png&quot; alt=&quot;plot of chunk unnamed-chunk-2&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-2&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-27-16-13-35-5da7c1081b-unnamed-chunk-4.png&quot; alt=&quot;plot of chunk unnamed-chunk-4&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-4&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/da0fb51032334c0e11f962674d4022cc04b2279b/inst/examples/allee.md&quot;&gt;allee.md&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Commit log links to some additional examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;another allee example altering MLE initial condition to attempt better likelihood estimates. GP still outperforms. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/606350a764ff9998e87216f627ee94c1dce12460&quot;&gt;04:40 pm 2012/12/27&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;in oscillatory regime with non-negligible noise. again GP performs nearly optimally while MLE methods suffer greatly &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/4c05a9ca5864a5983fae4a6e015f2bc1b2c3e1c0&quot;&gt;04:27 pm 2012/12/27&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Example of Ricker-Allee in oscillation regime, shows non-trivial dynamics, GP does very well (closes #22) &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/da0fb51032334c0e11f962674d4022cc04b2279b&quot;&gt;04:17 pm 2012/12/27&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;work with non-named arguments in MLE, consistent ordering for plot legends &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/5da7c1081b1c260e95f9808fc3c698d12e3b7cbd&quot;&gt;04:05 pm 2012/12/27&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;other-projects&quot;&gt;Other projects&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Upgraded gems, had to update notebook’s liquid code metadata to handle dates in string format on pages vs being date objects in posts. &lt;a href=&quot;https://github.com/cboettig/labnotebook/commit/de4d4cc0737eb5d16ca1785edcb39c01c646080a&quot;&gt;de4d4cc&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Setting up &lt;a href=&quot;https://github.com/cboettig/multiple_uncertainty&quot;&gt;multiple_uncertainty&lt;/a&gt; as a separate repository (branched from &lt;a href=&quot;https://github.com/cboettig/pdg_control&quot;&gt;pdg-control&lt;/a&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/12/23/notes.html"/>
   <updated>2012-12-23T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/12/23/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;ul&gt;
&lt;li&gt;&lt;p&gt;added generation of observational data under varying harvest conditions (issue &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/19&quot;&gt;#19&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;added MLE fit based on the data-generating model (issue &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/20&quot;&gt;#20&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;GP plot with and without nugget variance (issue &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/17&quot;&gt;#17&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run longer simulations under policy such that sustainable profits clearly beat out collapsing the fishery (part of issue &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/22&quot;&gt;#22&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Progress Summary</title>
   <link href="/2012/12/21/progress-summary.html"/>
   <updated>2012-12-21T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/12/21/progress-summary</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h1 id=&quot;progress-mid-october-through-mid-december&quot;&gt;Progress mid-October through mid-December&lt;/h1&gt;
&lt;h2 id=&quot;time-nonparametric-bayes&quot;&gt;80% Time: nonparametric-bayes&lt;/h2&gt;
&lt;p&gt;The bulk of my time has been spent becoming familiar with the literature on Gaussian Processes and their numerical implementation. I have written my own Gaussian process code from scratch to convince myself of my understanding of the methodology, and explored some of the related numerical issues addressing computational speed and stability.&lt;/p&gt;
&lt;p&gt;I then developed an algorithm for applying the Gaussian process inference of the state dynamics to stochastic dynamic programming methods for determining an optimal harvesting policy. I have compared the performance of the Gaussian-process inferred model to the optimal solution (given the exact underlying model) and to solutions based on estimated parametric models (both matching and not matching the underlying structure). This analysis shows the benefit of the nonparametric approach in better accounting for structural uncertainty in the underlying dynamics.&lt;/p&gt;
&lt;p&gt;Steve and I have just started to look into the potential for state shifts and warning signals there-of in the ENSO / Pacific decadal oscillation. I obtained 2 appropriate datasets and have run a very preliminary &lt;a href=&quot;http://www.carlboettiger.info/2012/12/17/random_ews_example.html&quot;&gt;analysis&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;time-independent-projects&quot;&gt;20% Time: Independent projects&lt;/h2&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;&lt;strong&gt;pdg-control Working group paper.&lt;/strong&gt; Updated analysis for Figures 3 and 4. Updated draft. Conference call for feedback from working group participants. (&lt;a href=&quot;https://github.com/cboettig/pdg_control/blob/master/inst/doc/policycosts/policycosts.tex&quot;&gt;Current draft&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Wrote &lt;strong&gt;comment&lt;/strong&gt; piece on Early Warning Signals for &lt;em&gt;Nature&lt;/em&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Working on EWS review paper for Theoretical Ecology with Noam Ross. (&lt;a href=&quot;https://github.com/cboettig/ews-review&quot;&gt;Current draft&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Working on analysis optimal policies under multiple uncertainties (with Jim Sanchirico, Mike Springborn). &lt;a href=&quot;http://www.carlboettiger.info/tags.html#multiple-uncertainty&quot;&gt;#multiple-uncertainty&lt;/a&gt; tag in notebook; currently analyses are part of &lt;a href=&quot;https://github.com/cboettig/pdg_control/tree/master/inst/examples&quot;&gt;pdg-control&lt;/a&gt; repository.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Finished and submitted NSF post-doc application&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;other-academic-activities&quot;&gt;Other academic activities&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Wrote requested reviews for &lt;em&gt;Conservation Letters&lt;/em&gt;, &lt;em&gt;Ecology Letters&lt;/em&gt;, &lt;em&gt;Proceedings of the Royal Society B&lt;/em&gt;. Declined to review for &lt;em&gt;Systematic Biology&lt;/em&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Presented my &lt;a href=&quot;http://dx.doi.org/10.6084/m9.figshare.97500&quot;&gt;exit seminar&lt;/a&gt; in the UC Davis Center for Population Biology Colloquia series.&lt;/li&gt;
&lt;li&gt;Interviewed for the &lt;em&gt;Nature&lt;/em&gt; column &lt;em&gt;Turning Point&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Invited and attended the PLoS alt-metrics workshop and hackathon&lt;/li&gt;
&lt;li&gt;Ran two sessions on version management, dynamic/reproducible papers, and building academic websites for the Mangel group.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Presented scaling from individual to population level models through the van Kampen expansion in Steve’s Applied Math Club&lt;/li&gt;
&lt;li&gt;Participated regularly in applied math club meetings.&lt;/li&gt;
&lt;li&gt;Established communication with FishBase team, arranged a coalition of developers interested in API access.&lt;/li&gt;
&lt;li&gt;ongoing development in &lt;a href=&quot;https://github.com/ropensci&quot;&gt;rOpenSci project&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;goals-for-january---march&quot;&gt;Goals for January - March&lt;/h1&gt;
&lt;h2 id=&quot;time&quot;&gt;80% Time&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Writeup of the Nonparametric Bayesian approach to management paper.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Initial goal for manuscript is proof of concept piece with the aim of demonstrating the value of a nonparametric approach to ecological decision-making. Alternatively a more technical piece could focus on the details of using Gaussian processes models for stochastic dynamic programming.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Outline of manuscript: Dec 31st&lt;/li&gt;
&lt;li&gt;Decide on manuscript figures to include&lt;/li&gt;
&lt;li&gt;Complete draft&lt;/li&gt;
&lt;li&gt;Appendices&lt;/li&gt;
&lt;li&gt;Solocit friendly revisions&lt;/li&gt;
&lt;li&gt;Submit (by March 31?)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Next steps and Additional projects&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The multi-species context is probably the next goal. Depending on timing, Steve may take the lead on that in these three months; I aim to be working in this in March. The step after will be the active/reinforcement learning/approximate SDP approaches. I aim to start into the background reading for that material but real progress on that front will happen after March.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Steve and I will likely continue to do something with the ENSO / PDO analysis as well. (Currently waiting on Steve’s pending queries to domain experts for further discussion)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I will also need to determine my summer conference schedule during this interval, and submit abstracts, etc. I have committed to the symposium to which I was invited at SIAM in San Deigo, July 8 - 12, and plan on attending ESA.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;time-goals&quot;&gt;20% Time goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Finish and submit EWS review paper: end of January&lt;/li&gt;
&lt;li&gt;Finish and submit pdg-control policy costs paper (see &lt;a href=&quot;https://github.com/cboettig/pdg_control/issues?direction=desc&amp;amp;labels=policy+costs&amp;amp;milestone=&amp;amp;page=1&amp;amp;sort=created&amp;amp;state=open&quot;&gt;current issues&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Finish the methods section for the Labrids paper&lt;/li&gt;
&lt;li&gt;Finish my pending review for &lt;em&gt;Environmental Modeling and Assessment&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Skype with pdg-control Working group, basic follow-up tasks.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Some next steps on multiple uncertainty.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;additional-academic-goals&quot;&gt;Additional academic goals&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Present in mega-group meeting: Feburary 20th&lt;/li&gt;
&lt;li&gt;Join the phylotastic hackathon remotely(?)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Results Comparing Gp To Parametric</title>
   <link href="/2012/12/20/results-comparing-gp-to-parametric.html"/>
   <updated>2012-12-20T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/12/20/results-comparing-gp-to-parametric</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Comparison of the Gaussian process inference to the true optimum and a parametric estimate.&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-20-23-12-06-60abafd424-unnamed-chunk-22.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;Comparison across 100 simulations under the policies inferred from each approach show the nearly optimal performance of the GP and the tragic crashes introduced by the parametric management.&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-20-23-12-07-60abafd424-unnamed-chunk-23.png&quot; /&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;sensitivity-analysis&quot;&gt;Sensitivity analysis&lt;/h2&gt;
&lt;p&gt;Working through an exploratory sensitivity analysis to see GP performance over different parameters.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/6aba5dce46370c600351eff270a76a664dacc7db/inst/examples/myers-exploration.md&quot;&gt;Example from 32 replicates&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Distribution of yield over replicates shows the parametric model performing rather poorly, while most of the GP replicates perform nearly optimally.&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-20-23-13-46-60abafd424-unnamed-chunk-3.png&quot; /&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/60abafd4242b3840454b3a138a428a1c633e73fd/inst/examples/myers-exploration.md&quot;&gt;smaller noise&lt;/a&gt;:&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-20-22-57-55-96ad28dd6e-unnamed-chunk-3.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/9d5cd1f027bdfe5f356dce83756726c95a6fcdd8/inst/examples/myers-exploration.md&quot;&gt;larger growth-rate parameters&lt;/a&gt;:&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-20-20-50-42-3f7bd6aa34-unnamed-chunk-3.png&quot; /&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;from-the-commit-log&quot;&gt;from the commit log&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;smaller r, shows GP outperform parametric estimate &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/6aba5dce46370c600351eff270a76a664dacc7db&quot;&gt;09:21 am 2012/12/21&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;small noise. works well. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/60abafd4242b3840454b3a138a428a1c633e73fd&quot;&gt;11:01 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;GP performs poorly with weak noise prior (nugget) when not conditioned on 0,0 &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/96ad28dd6edfbcec720b77fe645719fa673dd44a&quot;&gt;10:45 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;less successful with higher noise level &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/0fdaadb9b57715390e149b3c182b8115ff036960&quot;&gt;09:10 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Ah here we go! with a decent allee effect model, the results are much clearer! &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/9d5cd1f027bdfe5f356dce83756726c95a6fcdd8&quot;&gt;08:52 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;strange Ricker Allee example – even true model doesn’t harvest successfully &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/3f7bd6aa349d23aa7aeb28b772b9b32b5d7645b1&quot;&gt;08:37 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;delta 1.5, r 1.3 K 4.5 &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/ee54f02a6d81ca0e89395837666055f4f6d1bcb0&quot;&gt;08:17 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;higher K value results in better persistence in general, not always outperforming parametric model though. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/db67f4ccb4f185b3000bbe6a93d770490e027593&quot;&gt;07:57 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;harvest, and then escaped population recruits; comparable &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/8e5a4cd1abe38671fb884855bae3babac7d4802d&quot;&gt;07:09 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;shorter OptTime and lower initial state do not much change the fraction that fail to persist &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/1130545ef69d6b6e064ca3a0360ee905c0a2b32d&quot;&gt;06:31 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Sensitivity analysis over replicates shows mixed results &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/e823ed12ef20d5c6dcbd04540bb957bf33116cab&quot;&gt;05:35 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;fixed bug (had Ef and V in gp_transition_matrix) &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/8307de6858cc9fe067d7c86c31ce93a91862f75e&quot;&gt;05:18 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;still crashing &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/44c19ba3882ce5a419c63d13c61a1b63377d051b&quot;&gt;05:01 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;more iterations &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/61aeba3dd05033f6b9184a145035cf9708dbc18a&quot;&gt;04:34 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;corrected iterations &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/278d66f2af22eada8d704b87a20738aba874ceb4&quot;&gt;04:28 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;cpu=8 for running on one.ucdavis &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/4adf814f23c90b4d415e5580e776f07bb1f5f355&quot;&gt;02:21 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;unique seeds for parallel computing &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/9a79a72650d3bfbb9768853f9132cd5dec6f88d6&quot;&gt;02:11 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;30 replicates with full graphs &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/88d4295e217bc6b52e23c19f4094b2a85cb61bfb&quot;&gt;02:03 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;avoid external source call, print plots &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/fd14d9146826c529b6ce0a1912feffd839d37261&quot;&gt;12:49 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;trying methods for looping over replicates efficiently &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/edee0e6ef100702ed3f420dc2c0d47a691b52d3f&quot;&gt;12:38 pm 2012/12/20&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;next-goalsissues&quot;&gt;next goals/issues&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;#22 &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/22&quot;&gt;Minor modifcations for the replicate comparisons&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;#20 &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/20&quot;&gt;Compare against correct parametric model with parameters estimated from the data&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;#19 &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/19&quot;&gt;Vary harvest policy during the observation stage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;#17 &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/17&quot;&gt;GP process plots should show with and without nugget variance&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Exploring Gp Model Space</title>
   <link href="/2012/12/19/exploring-gp-model-space.html"/>
   <updated>2012-12-19T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/12/19/exploring-gp-model-space</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Trying to think about a more systematic way to go about varying the parameters: the underlying parametric model has 3 parameters for the stock-recruitment curve’s deterministic skeleton, plus growth noise. (My first exploratory phase has been just to try different things. See my &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commits/master/inst/examples/myer-example.md&quot;&gt;various tweaks in the history log&lt;/a&gt; Clearly time to be more systematic about both running and visualizing the various cases.)&lt;/p&gt;
&lt;p&gt;Should I just choose a handful of parameter combinations to test? (Trying to think of a way to do this that is easy to summarize – at least I can summarize expected profit under each set). Presumably, for each set of these parameters, I’d want a few (many?) stochastic realizations of the calibration/training data.&lt;/p&gt;
&lt;p&gt;Would it be worth digging up some real-world data-sets and base the selection of underlying model parameters on them?&lt;/p&gt;
&lt;p&gt;Then there’s a variety of nuisance parameters: grid size, discount rate, price of fish (non-dimensionalization eliminates that one I guess), cost to fishing (and whether the cost is on effort or harvest, whether linear or quadratic, etc), harvest grid size / possible constraints on maximum or minimum allowable levels for the control; length of the calibration period (and related dynamics if we use any of the variable fishing effort models you showed me today).&lt;/p&gt;
&lt;p&gt;Additionally there’s the MCMC-related nuisance parameters – parameters for the priors, possibly hyperpriors, and the MCMC convergence analysis (selecting burn-in period – currently 2000 steps out of 16000, etc) . Also the distributional shapes for the priors, and perhaps more meaningfully, the GP covariance function (using Gaussian for simplicity, but might want to look at Matern, and the various linear + Gaussian covariances).&lt;/p&gt;
&lt;h2 id=&quot;new-and-progressing-issues&quot;&gt;New and progressing issues&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/19&quot;&gt;Vary harvest policy during the observation stage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/18&quot;&gt;Add prior &amp;amp; posterior graphs (on same plot) to standard analysis (i.e. gaussian-process-control.R)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/17&quot;&gt;GP process plots should show with and without nugget variance&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/16&quot;&gt;examples with non-stationary dynamics (e.g. Ricker with oscillations)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/14&quot;&gt;evaluate GP under large noise conditions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/12&quot;&gt;Characterize and develop a strategy for inferred GP that are not self-sustaining&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;from-the-commit-log-today&quot;&gt;from the commit log today&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;prior/posterior plots added to the BH-Ricker example. Comparable but non-optimal performance by GP. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/f1711a171c62005e88a17af13a7ad3e697ae382e&quot;&gt;06:07 pm 2012/12/19&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;oscillating ricker still does not give decent solutions &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/19c32b33a15c675c8bf900f24962aee4a6ade31f&quot;&gt;05:45 pm 2012/12/19&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;shows posteriors and priors of hyperparameters &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/4ce05b91910168114c86a417ec56de925de94969&quot;&gt;05:38 pm 2012/12/19&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;fixed minor typo in calc of posterior distribution plots #18 &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/01d0f47bcce6aa977f79f27cb8a980eef04d4673&quot;&gt;05:15 pm 2012/12/19&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;plotting for posteriors and priors added #18 &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/ab9cfac258cfdc7c888c95473329f048e32a8ec3&quot;&gt;04:13 pm 2012/12/19&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;replicate &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/ae91163f2e8c4eb5094913908f49e722cff52656&quot;&gt;02:22 pm 2012/12/19&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;time to start writing &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/aef1d1ac8af8b7a49bcc4f8d13b397c587805087&quot;&gt;09:16 am 2012/12/19&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Ah, good. With a bit more data, a very nice example of how GP can avoid problems of a structurally inaccurate parametric approach (Myers vs Ricker). &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/a8ea0c17c1a4ed4ca8ab51bebb75a9c98ec32564&quot;&gt;09:15 am 2012/12/19&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;more data going up to positive equilibrium, better but still does not avoid crash &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/325786ba1798c0f888da59b584af67e4a0117e42&quot;&gt;08:29 am 2012/12/19&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;An interesting example – seems to work despite being calibrated on a crashing dataset. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/b88842a2537eff45c9b383f04a4ffc0a126e3fe7&quot;&gt;08:08 am 2012/12/19&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;With smaller K, GP cannot quite determine a proper policy &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/a462d4165b92a6c226e02460bd83d48acae7232f&quot;&gt;07:37 am 2012/12/19&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;try different dynamic parameters on Myers (lower K) &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/36a9985baf70df0d020a7a509490650d9bcd6f80&quot;&gt;05:59 am 2012/12/19&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;misc-ropensci&quot;&gt;Misc: ropensci&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;resolved some outstanding issues on rfigshare (&lt;a href=&quot;https://github.com/ropensci/rfigshare/issues?state=closed&quot;&gt;rfigshare/issues?state=closed&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Random_ews_example</title>
   <link href="/2012/12/17/random_ews_example.html"/>
   <updated>2012-12-17T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/12/17/random_ews_example</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h1 id=&quot;enso-ews&quot;&gt;ENSO EWS&lt;/h1&gt;
&lt;p&gt;Let’s just see what happens with the &lt;a href=&quot;http://www.esrl.noaa.gov/psd/enso/mei/&quot;&gt;MEI data&lt;/a&gt; for PDO:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;read.table&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;http://www.carlboettiger.info/assets/data/mei.csv&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;header=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;!-- html table generated in R 2.15.2 by xtable 1.7-0 package --&gt;
&lt;!-- Mon Dec 17 15:31:58 2012 --&gt;

&lt;p&gt;For the moment let’s ignore annual structure and just collapse this into timeseries sampled bimonthly.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(reshape2)
dt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(dat, &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;YEAR&amp;quot;&lt;/span&gt;)
X &amp;lt;- dt$value
Z &amp;lt;- X[!&lt;span class=&quot;kw&quot;&gt;is.na&lt;/span&gt;(X)]
Z &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:(&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(Z)-&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;), Z[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:(&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(Z)-&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)])&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;png&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;mei.png&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(earlywarnings)
a &amp;lt;- &lt;span class=&quot;kw&quot;&gt;generic_ews&lt;/span&gt;(Z, &lt;span class=&quot;dt&quot;&gt;detrending=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;gaussian&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-18-6c85b56d2c-mei2012.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;How about the data from MacDonald (2005)&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;ftp://ftp.ncdc.noaa.gov/pub/data/paleo/treering/reconstructions/pdo-macdonald2005.txt&quot;&gt;original data link&lt;/a&gt;&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;read.table&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;http://www.carlboettiger.info/assets/data/pdo-macdonald2005.csv&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;header=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;png&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;macdonald2005.png&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(earlywarnings)
a &amp;lt;- &lt;span class=&quot;kw&quot;&gt;generic_ews&lt;/span&gt;(dat, &lt;span class=&quot;dt&quot;&gt;detrending=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;gaussian&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;dev.off&lt;/span&gt;()&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-18-6c85b56d2c-pdo-macdonald2005.png&quot; /&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>Nonparametric Bayes Comparisons</title>
   <link href="/2012/12/15/nonparametric-bayes-comparisons.html"/>
   <updated>2012-12-15T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/12/15/nonparametric-bayes-comparisons</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;notes-on-structure-of-examples&quot;&gt;Notes on structure of examples&lt;/h2&gt;
&lt;p&gt;Externalized code so that different example scripts call identical commands for fitting and plotting to avoid duplication of code. Example scripts tend to be pretty text poor at the moment, would probably benefit by better descriptions in the markdown. May still involve redundant and potentially out of date descriptions though.&lt;/p&gt;
&lt;p&gt;Currently, externalized code for GP comparison experiments is in &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/526b54b09e23f550198863741bce9e9cb52e9325/inst/examples/gaussian-process-control.R&quot;&gt;gaussian-process-control.R&lt;/a&gt;, and is called by &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/cac79bcc42433a6b8720d5d4c5824c57a850a56c/inst/examples/may79-example.Rmd&quot;&gt;may79-example.Rmd&lt;/a&gt;, &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/cac79bcc42433a6b8720d5d4c5824c57a850a56c/inst/examples/myer-example.Rmd&quot;&gt;myer-example.Rmd&lt;/a&gt;, and &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/cac79bcc42433a6b8720d5d4c5824c57a850a56c/inst/examples/reed-example.Rmd&quot;&gt;reed-example.Rmd&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Also fixed &lt;a href=&quot;https://github.com/cboettig/knitcitations&quot;&gt;knitcitations&lt;/a&gt; to at least include citations in markdown files.&lt;/p&gt;
&lt;h2 id=&quot;performance-of-gp-compared-to-ricker-on-an-underlying-allee-model&quot;&gt;Performance of GP compared to Ricker on an underlying Allee model&lt;/h2&gt;
&lt;h3 id=&quot;using-stationary-data-only&quot;&gt;Using stationary data only&lt;/h3&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-15-f42127cba3-gp-plot.png&quot; alt=&quot;Inferred GP&quot; /&gt;&lt;figcaption&gt;Inferred GP&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-15-f42127cba3-policy_plot.png&quot; alt=&quot;plot of policy functions&quot; /&gt;&lt;figcaption&gt;plot of policy functions&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-15-f42127cba3-sim-fish.png&quot; alt=&quot;fish stock dynamics&quot; /&gt;&lt;figcaption&gt;fish stock dynamics&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-15-f42127cba3-sim-harvest.png&quot; alt=&quot;harvest dynamics&quot; /&gt;&lt;figcaption&gt;harvest dynamics&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;(see &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/a3aad15b159aae10264e39ccf3cbe0cdb8aec279/inst/examples/myer-example.md&quot;&gt;myer-example.md&lt;/a&gt; for code and more graphs &amp;amp; details)&lt;/p&gt;
&lt;h3 id=&quot;using-more-data&quot;&gt;Using more data&lt;/h3&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-15-003da6e98e-gp-plot.png&quot; alt=&quot;Inferred GP&quot; /&gt;&lt;figcaption&gt;Inferred GP&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-15-003da6e98e-policy_plot.png&quot; alt=&quot;plot of policy functions&quot; /&gt;&lt;figcaption&gt;plot of policy functions&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-15-003da6e98e-sim-fish.png&quot; alt=&quot;plot of sim-fish&quot; /&gt;&lt;figcaption&gt;plot of sim-fish&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-15-003da6e98e-sim-harvest.png&quot; alt=&quot;plot of sim-harvest&quot; /&gt;&lt;figcaption&gt;plot of sim-harvest&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;(from &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/a1bc09a4a7a2edabbd63916416db6b095d1ead6b/inst/examples/myer-example.md&quot;&gt;earlier myer-example.md&lt;/a&gt;)&lt;/p&gt;
&lt;h2 id=&quot;comparing-gp-to-estimated-ricker-on-bh-dynamics&quot;&gt;Comparing GP to estimated Ricker on BH dynamics:&lt;/h2&gt;
&lt;p&gt;GP performs well, but Ricker performs adequately as well: &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/cac79bcc42433a6b8720d5d4c5824c57a850a56c/inst/examples/reed-example.md&quot;&gt;reed-example.md&lt;/a&gt; (shows an example with stationary data).&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-15-8b057f1f24-gp-plot.png&quot; alt=&quot;plot of chunk gp-plot&quot; /&gt;&lt;figcaption&gt;plot of chunk gp-plot&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-15-8b057f1f24-policy_plot.png&quot; alt=&quot;plot of chunk policy_plot&quot; /&gt;&lt;figcaption&gt;plot of chunk policy_plot&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-15-8b057f1f24-sim-fish.png&quot; alt=&quot;plot of chunk sim-fish&quot; /&gt;&lt;figcaption&gt;plot of chunk sim-fish&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-15-8b057f1f24-sim-harvest.png&quot; alt=&quot;plot of chunk sim-harvest&quot; /&gt;&lt;figcaption&gt;plot of chunk sim-harvest&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;other-advances&quot;&gt;Other advances&lt;/h2&gt;
&lt;p&gt;Approaches shown above address a variety of issues as well:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Compares to a Ricker estimated by MLE (&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/8&quot;&gt;#8&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Considers fewer non-stationary observations, but include 0,0 as observation (&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/13&quot;&gt;#13&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Includes scrap value (&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/10&quot;&gt;#10&lt;/a&gt;), though this does not guarentee no fishing under non-persistence estimation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A few next steps:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;measurement error should be introduced in the simulations (&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/11&quot;&gt;#11&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Evaluate GP performance under larger noise conditions. (&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/14&quot;&gt;#14&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;See issues log for further issues to explore and more details on closed issues. See commit log for full details, this entry summarizes progress over the latter half of the week.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Nonparametric Bayes Notes</title>
   <link href="/2012/12/11/nonparametric-bayes-notes.html"/>
   <updated>2012-12-11T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/12/11/nonparametric-bayes-notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;ul&gt;
&lt;li&gt;Code &lt;code&gt;gp_transition_matrix&lt;/code&gt; for generic multi-dimensional case&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;understanding-gaussian-process-performance&quot;&gt;Understanding Gaussian Process performance&lt;/h2&gt;
&lt;p&gt;If the estimated recruitment dynamics correspond to population dynamics that are non-persistent (might call this non self-sustaining, but in a rather stricter sense than when Reed (1979) introduced that term), and if no reward is offered at the terminal time point for a standing stock (zero scrap value), the GP dictates the rather counter-intuitive practice of simply removing the stock entirely.&lt;/p&gt;
&lt;p&gt;Exploring this by comparing evolution of the probability density for the population size under the transition function. Consider this example from a May1979 model (full run in &lt;a href=&quot;&quot;&gt;may1979-example.md&lt;/a&gt;): The Gaussian process infers a rather pessemistic evolution of the probabilty density (grey distribution becomes black distribution when unharvested, 20 years (OptTime)):&lt;/p&gt;
&lt;h4 id=&quot;gp-transition-function&quot;&gt;GP transition function&lt;/h4&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-15-a3aad15b15-gp-F-sim.png&quot; alt=&quot;plot of chunk gp-F-sim&quot; /&gt;&lt;figcaption&gt;plot of chunk gp-F-sim&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Whereas the actual transition function moves the stock to a tight window around the high carrying capacity:&lt;/p&gt;
&lt;h4 id=&quot;true-transition-function&quot;&gt;true transition function&lt;/h4&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-15-a3aad15b15-par-F-sim.png&quot; alt=&quot;plot of chunk par-F-sim&quot; /&gt;&lt;figcaption&gt;plot of chunk par-F-sim&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Often this results in a policy function that harvests all the fish, since they won’t persist. Exploring approaches to avoid such solutions, such as adding a reward for leaving some standing stock at the boundary time (issue &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/10&quot;&gt;#10&lt;/a&gt;).&lt;/p&gt;
&lt;h2 id=&quot;multi-species-examples-issue-7&quot;&gt;Multi-species examples (issue &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/7&quot;&gt;#7&lt;/a&gt;)&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/b5b1d3300497399fb364a40c9f4523203944702d/inst/examples/multidimensional.md&quot;&gt;multidimensional.md&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;fragility-of-parametric-rigidity-examples&quot;&gt;Fragility of parametric rigidity examples&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;infer under BH and simulate under allee&lt;/li&gt;
&lt;li&gt;Infer ricker, simulate under BH&lt;/li&gt;
&lt;li&gt;Other examples?&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;mcmc&quot;&gt;MCMC&lt;/h2&gt;
&lt;p&gt;Examples of controlling priors, resulting posteriors. &lt;a href=&quot;http://www.carlboettiger.info/2012/12/10/prior-distributions-for-tgp-mcmc.html&quot;&gt;See yesterday’s notes for details&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;additional-r-software-support&quot;&gt;additional R software support&lt;/h2&gt;
&lt;p&gt;Have been focusing recently on the MCMC implementation for treed Gaussian Processes, provided in the &lt;a href=&quot;http://cran.r-project.org/web/packages/tgp&quot;&gt;&lt;code&gt;tgp&lt;/code&gt;&lt;/a&gt; package.&lt;/p&gt;
&lt;p&gt;Lots of various implementations of Gaussian Proccesses in R in &lt;a href=&quot;http://cran.r-project.org/web/views/Spatial.html&quot;&gt;geospatial stats packages&lt;/a&gt; (e.g. Kriging implementations) including some the offer fully heirachical Bayesian approaches with a variety of twists:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://cran.r-project.org/web/packages/psgp/index.html&quot;&gt;&lt;code&gt;psgp&lt;/code&gt;&lt;/a&gt; Projected Spatial Gaussian Process (psgp) methods, Implements projected sparse Gaussian process kriging for the intamap package&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://cran.r-project.org/web/packages/gstat/&quot;&gt;&lt;code&gt;gstat&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://cran.r-project.org/web/packages/geoR/&quot;&gt;&lt;code&gt;geoR&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://cran.r-project.org/web/packages/spBayes/index.html&quot;&gt;&lt;code&gt;spBayes&lt;/code&gt;&lt;/a&gt; spBayes fits univariate and multivariate spatial models with Markov chain Monte Carlo (MCMC).&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://cran.r-project.org/web/packages/ramps/index.html&quot;&gt;&lt;code&gt;ramps&lt;/code&gt;&lt;/a&gt; Bayesian geostatistical modeling of Gaussian processes using a reparameterized and marginalized posterior sampling (RAMPS) algorithm designed to lower autocorrelation in MCMC samples. Package performance is tuned for large spatial datasets.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;from-the-commit-log&quot;&gt;From the commit log…&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;another example (includes some data in the higher range) #7 &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/b5b1d3300497399fb364a40c9f4523203944702d&quot;&gt;06:49 pm 2012/12/11&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;a simple multi-demensional example (no policy function yet) #7 &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/b74ccc45667d4e20790acca3c5947d9a23fc5e95&quot;&gt;06:43 pm 2012/12/11&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;updated notes on mcmc approach #6 &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/19bbd1028b702ab9243cb525e3a8b441324408c7&quot;&gt;03:51 pm 2012/12/11&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;transition matrix method for GP takes Ef, Cf explicitly now. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/49cea150618907f48b058e45bbbc01a43c44f8c5&quot;&gt;03:50 pm 2012/12/11&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;GP that results in scorched earth fishing strategy &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/6fc937211b6c5381b46dc0e8ffff6092545d7519&quot;&gt;02:19 pm 2012/12/11&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Prior Distributions For Tgp Mcmc</title>
   <link href="/2012/12/10/prior-distributions-for-tgp-mcmc.html"/>
   <updated>2012-12-10T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/12/10/prior-distributions-for-tgp-mcmc</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;I am trying to understand the interface for tgp method, but much of it is not well documented (yes, despite reading through the package R manual, two nice vignettes, and a the PhD Thesis describing it.)&lt;/p&gt;
&lt;p&gt;Just to get some consistent notation down: consider the case of a Gaussian process with a Gaussian/radial basis function kernel, parameterized as:&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?K(X, X&amp;#39;) = \sigma^2 e^{\frac{(X-X&amp;#39;)^2}{d}}&quot; alt=&quot;K(X, X&amp;#39;) = \sigma^2 e^{\frac{(X-X&amp;#39;)^2}{d}}&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;And observations from &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?Z = f(X) + \varepsilon\inline&quot;/&gt;&lt;/span&gt;, for which we seek to approximate &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?f\inline&quot;/&gt;&lt;/span&gt; as a (multivariate) Gaussian process, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?Z | X ~ N(\mu, C)\inline&quot;/&gt;&lt;/span&gt;. The covariance matrix &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?C\inline&quot;/&gt;&lt;/span&gt; is given by our kernel &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?K\inline&quot;/&gt;&lt;/span&gt;, conditioned on our observations; the mean &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mu\inline&quot;/&gt;&lt;/span&gt; is given by a constant or linear model, likewise conditioned on our observations. If the multivariate normal of observed and predicted points is,&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\begin{align}\begin{pmatrix} y_{\textrm{obs}} \ y_{\textrm{pred}} \end{pmatrix} \sim \mathcal{N}\left( \mathbf{0}, \begin{bmatrix} cov(X_o,X_o) &amp;amp; cov(X_o, X_p) \ cov(X_p,X_o) &amp;amp; cov(X_p, X_p) \end{bmatrix} \right)\end{align}&quot; alt=&quot;\begin{align}\begin{pmatrix} y_{\textrm{obs}} \ y_{\textrm{pred}} \end{pmatrix} \sim \mathcal{N}\left( \mathbf{0}, \begin{bmatrix} cov(X_o,X_o) &amp;amp; cov(X_o, X_p) \ cov(X_p,X_o) &amp;amp; cov(X_p, X_p) \end{bmatrix} \right)\end{align}&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;the conditional probability is&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x|y \sim \mathcal{N}(E,C)&quot; alt=&quot;x|y \sim \mathcal{N}(E,C)&quot; /&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?E = \operatorname{cov}(X_p, X_o) (\operatorname{cov}(X_o,X_o) + \varepsilon \mathbb{I}) ^{-1} y&quot; alt=&quot;E = \operatorname{cov}(X_p, X_o) (\operatorname{cov}(X_o,X_o) + \varepsilon \mathbb{I}) ^{-1} y&quot; /&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?C= \operatorname{cov}(X_p, X_p) - \operatorname{cov}(X_p, X_o) (\operatorname{cov}(X_o,X_o)+ \varepsilon \mathbb{I} )^{-1} \operatorname{cov}(X_o, X_p)&quot; alt=&quot;C= \operatorname{cov}(X_p, X_p) - \operatorname{cov}(X_p, X_o) (\operatorname{cov}(X_o,X_o)+ \varepsilon \mathbb{I} )^{-1} \operatorname{cov}(X_o, X_p)&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Our hyperparameters are &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?d\inline&quot;/&gt;&lt;/span&gt;, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\sigma^2\inline&quot;/&gt;&lt;/span&gt;, and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\varepsilon\inline&quot;/&gt;&lt;/span&gt;, for which we need priors. We’ll use the inverse gamma,&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?P(x; a, g) = \frac{g^a}{\Gamma(a)} x^{-a - 1}\exp\left(-\frac{g}{x}\right)&quot; alt=&quot;P(x; a, g) = \frac{g^a}{\Gamma(a)} x^{-a - 1}\exp\left(-\frac{g}{x}\right)&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The distribution arises as the marginal posterior distribution for the unknown variance of a normal distribution if an uninformative prior is used; and as a useful conjugate prior if a less uninformative prior is preferred. However, it is common among Bayesians to consider an alternative parametrization of the normal distribution in terms of the precision, defined as the reciprocal of the variance, which allows the gamma distribution to be used directly as a conjugate prior.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?X\inline&quot;/&gt;&lt;/span&gt; is &lt;code&gt;X&lt;/code&gt;, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?Z\inline&quot;/&gt;&lt;/span&gt; is &lt;code&gt;Z&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\sigma^2\inline&quot;/&gt;&lt;/span&gt; is the parameter &lt;code&gt;s2&lt;/code&gt; in the &lt;code&gt;tgp&lt;/code&gt; package, coming from inverse gamma prior with parameters &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?a = a_0\inline&quot;/&gt;&lt;/span&gt; and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?g = g_0\inline&quot;/&gt;&lt;/span&gt;, which are set by &lt;code&gt;s2.p = c(a_0, g_0)&lt;/code&gt;. Optionally, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?a_0\inline&quot;/&gt;&lt;/span&gt; and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?g_0\inline&quot;/&gt;&lt;/span&gt; can be taken from an exponential prior &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\lambda e^{-\lambda x}\inline&quot;/&gt;&lt;/span&gt;, in which the value of &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\lambda\inline&quot;/&gt;&lt;/span&gt; is given by &lt;code&gt;s2.lam = c(lambda_a, lambda_g)&lt;/code&gt;. Setting &lt;code&gt;s2.lam = &amp;quot;fixed&amp;quot;&lt;/code&gt; “turns off” the use of a hyperprior.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?d\inline&quot;/&gt;&lt;/span&gt; I believe is &lt;code&gt;d&lt;/code&gt;, which Grammarcy calls the range parameter (other terms include the “lengthscale”). I am not sure what either &lt;code&gt;d&lt;/code&gt; or &lt;code&gt;s2&lt;/code&gt; correspond to if the covariance function &lt;code&gt;corr&lt;/code&gt; is something other than the radial basis function. I’m also not clear how to set the correlation function to a strictly Gaussian covariance – &lt;code&gt;corr&lt;/code&gt; is set to the &lt;code&gt;exp&lt;/code&gt; family, which leaves the power as a parameter &lt;code&gt;p_0&lt;/code&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?K(X, X&amp;#39;) =  e^{\frac{-(X-X&amp;#39;)^p_0}{d}}&quot; alt=&quot;K(X, X&amp;#39;) =  e^{\frac{-(X-X&amp;#39;)^p_0}{d}}&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;(from equation 4 in the Vignette (1)). The parameter &lt;code&gt;p_0&lt;/code&gt; is fixed at &lt;code&gt;2&lt;/code&gt;, and not treated as a hyperparameter.&lt;/p&gt;
&lt;p&gt;The length-scale comes from a hyperparameter that is the sum (mixture) of two Gamma distributions, with prior parameter &lt;code&gt;c(a1,g1,a2,g2)&lt;/code&gt; where &lt;code&gt;g1&lt;/code&gt; and &lt;code&gt;g2&lt;/code&gt; are scale (1/rate) parameters. As before, these parameters &lt;code&gt;c(a1, g1, a2, g2)&lt;/code&gt; can be drawn from an exponential distribution hyperprior whose &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\lambda\inline&quot;/&gt;&lt;/span&gt; values are given by &lt;code&gt;d.lam&lt;/code&gt;, or turned off.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\varepsilon\inline&quot;/&gt;&lt;/span&gt; is &lt;code&gt;nug&lt;/code&gt;. It seems to have same shape prior as &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?d\inline&quot;/&gt;&lt;/span&gt;, specified by &lt;code&gt;c(a1,g1,a2,g2)&lt;/code&gt;, and optional hyperprior as well. Additionally it can be fixed to a constant by setting &lt;code&gt;nug.p = 0&lt;/code&gt; and specifying the staring value as &lt;code&gt;gd[1]&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The mean is not fixed at zero but is instead a linear model, we need hyperparameters for it as well. The key parameter there is the slope &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\beta\inline&quot;/&gt;&lt;/span&gt;. The functional form for it’s prior is specified as &lt;code&gt;bprior&lt;/code&gt;, which takes values &lt;code&gt;bflat&lt;/code&gt;, &lt;code&gt;b0&lt;/code&gt;, &lt;code&gt;bmzt&lt;/code&gt;, or &lt;code&gt;bmznot&lt;/code&gt;. A sensible choice is as a Gaussian &lt;code&gt;b0&lt;/code&gt;, as shown in Equation 1 of the vignette&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;\[
\begin{align} 
Z | \beta, \sigma^2, K &amp;amp;\sim N_n(\mathbf{F} \beta, \sigma^2 \mathbf{K}) \\
\beta | \sigma^2, \tau^2, \mathbf{W}, \beta_0 &amp;amp;\sim N_m(\beta_0, \sigma^2 \tau^2 \mathbf{W} )  \\
\beta_0 &amp;amp;\sim N_m(\mathbf{\mu}, \mathbf{B})
\end{align}
\]&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;example-comparison&quot;&gt;Example comparison&lt;/h2&gt;
&lt;p&gt;Say, given some observed data pairs &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x,y\inline&quot;/&gt;&lt;/span&gt; and predictions desired on a grid &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?X\inline&quot;/&gt;&lt;/span&gt;,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;X = &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;length=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;50&lt;/span&gt;)
x = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;, -&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;, -&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)
y = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, -&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Manually I could just do:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;d = .&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;; epsilon = .&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;; sigma = &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;; &lt;span class=&quot;co&quot;&gt;#fixed hyperparamaters&lt;/span&gt;
SE &amp;lt;- function(Xi,Xj, d) sigma * &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(-&lt;span class=&quot;fl&quot;&gt;0.5&lt;/span&gt; * (Xi - Xj) ^ &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; / d ^ &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)
cov &amp;lt;- function(X, Y) &lt;span class=&quot;kw&quot;&gt;outer&lt;/span&gt;(X, Y, SE, d) 
cov_xx_inv &amp;lt;- &lt;span class=&quot;kw&quot;&gt;solve&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x, x) + epsilon * &lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(x)))
Ef &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(X, x) %*% cov_xx_inv %*% y
Cf &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(X, X) - &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(X, x)  %*% cov_xx_inv %*% &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x, X)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And &lt;code&gt;Ef&lt;/code&gt; and &lt;code&gt;Cf&lt;/code&gt; are the estimated (krieging) mean and covariance.&lt;/p&gt;
&lt;h2 id=&quot;priors&quot;&gt;Priors&lt;/h2&gt;
&lt;p&gt;Note: it appears that the mixed gammas for &lt;code&gt;d&lt;/code&gt; and &lt;code&gt;nug&lt;/code&gt; actually treat the second argument, &lt;code&gt;g1&lt;/code&gt; and &lt;code&gt;g2&lt;/code&gt;, as the rate instead of the scale, so I invert the desired scale:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;s2.p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;50&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;50&lt;/span&gt;)
tau2.p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;20&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)
d.p = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.01&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.01&lt;/span&gt;)
nug.p = &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.01&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/&lt;span class=&quot;fl&quot;&gt;0.01&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Define as curves and plot the priors:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;s2_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dinvgamma&lt;/span&gt;(x, s2.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], s2.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;])
tau2_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dinvgamma&lt;/span&gt;(x, tau2.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], tau2.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;])
d_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, d.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; d.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]) + &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, d.p[&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; d.p[&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;])
nug_prior &amp;lt;- function(x) &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, nug.p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; nug.p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]) + &lt;span class=&quot;kw&quot;&gt;dgamma&lt;/span&gt;(x, nug.p[&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;scale =&lt;/span&gt; nug.p[&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;])
beta0_prior &amp;lt;- function(x, tau) &lt;span class=&quot;kw&quot;&gt;dnorm&lt;/span&gt;(x, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, tau)

xx &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(.&lt;span class=&quot;dv&quot;&gt;0001&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;length.out=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;)
priors &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; xx, &lt;span class=&quot;dt&quot;&gt;s2 =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;s2_prior&lt;/span&gt;(xx), &lt;span class=&quot;dt&quot;&gt;tau2 =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;tau2_prior&lt;/span&gt;(xx), &lt;span class=&quot;dt&quot;&gt;beta0 =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;beta0_prior&lt;/span&gt;(xx, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;nug =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;nug_prior&lt;/span&gt;(xx), &lt;span class=&quot;dt&quot;&gt;d =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;d_prior&lt;/span&gt;(xx))
priors &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(priors, &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(priors) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, value)) + &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~variable, &lt;span class=&quot;dt&quot;&gt;scale=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-10-9b2d792442-unnamed-chunk-5.png&quot; alt=&quot;plot of chunk unnamed-chunk-5&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-5&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;bgp&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;X=&lt;/span&gt;x, &lt;span class=&quot;dt&quot;&gt;XX=&lt;/span&gt;X, &lt;span class=&quot;dt&quot;&gt;Z=&lt;/span&gt;y, &lt;span class=&quot;dt&quot;&gt;verb=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,
          &lt;span class=&quot;dt&quot;&gt;meanfn=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;constant&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;bprior=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;b0&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;BTE=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;2000&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;6000&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;m0r1=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, 
          &lt;span class=&quot;dt&quot;&gt;corr=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;exp&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;trace=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;beta =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,
          &lt;span class=&quot;dt&quot;&gt;s2.p =&lt;/span&gt; s2.p, &lt;span class=&quot;dt&quot;&gt;d.p =&lt;/span&gt; d.p, &lt;span class=&quot;dt&quot;&gt;nug.p =&lt;/span&gt; nug.p,
          &lt;span class=&quot;dt&quot;&gt;s2.lam =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;d.lam =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;nug.lam =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;, 
          &lt;span class=&quot;dt&quot;&gt;tau2.lam =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;tau2.p =&lt;/span&gt; tau2.p)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Extract the posterior Gaussian process mean and the &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\pm 2\inline&quot;/&gt;&lt;/span&gt; standard deviations over the predicted grid from the fit:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;V &amp;lt;- gp$ZZ.ks2
tgp_dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x   =&lt;/span&gt; gp$XX[[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]], 
                  &lt;span class=&quot;dt&quot;&gt;y   =&lt;/span&gt; gp$ZZ.km, 
                 &lt;span class=&quot;dt&quot;&gt;ymin =&lt;/span&gt; gp$ZZ.km - &lt;span class=&quot;fl&quot;&gt;1.96&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(gp$ZZ.ks2), 
                 &lt;span class=&quot;dt&quot;&gt;ymax =&lt;/span&gt; gp$ZZ.km + &lt;span class=&quot;fl&quot;&gt;1.96&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(gp$ZZ.ks2))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and likewise for our manual data:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;manual_dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; X, 
                         &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; Ef, 
                         &lt;span class=&quot;dt&quot;&gt;ymin =&lt;/span&gt; (Ef - &lt;span class=&quot;fl&quot;&gt;1.96&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(Cf))), 
                         &lt;span class=&quot;dt&quot;&gt;ymax =&lt;/span&gt; (Ef + &lt;span class=&quot;fl&quot;&gt;1.96&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(Cf))))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Compare the GP posteriors:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(tgp_dat) +
    &lt;span class=&quot;kw&quot;&gt;geom_ribbon&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y, &lt;span class=&quot;dt&quot;&gt;ymin =&lt;/span&gt; ymin, &lt;span class=&quot;dt&quot;&gt;ymax =&lt;/span&gt; ymax), &lt;span class=&quot;dt&quot;&gt;fill=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;alpha =&lt;/span&gt; .&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) + &lt;span class=&quot;co&quot;&gt;# Var&lt;/span&gt;
    &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y), &lt;span class=&quot;dt&quot;&gt;col=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;co&quot;&gt;# mean&lt;/span&gt;
    &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; x, &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; y), &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y)) + &lt;span class=&quot;co&quot;&gt;# raw data&lt;/span&gt;
    &lt;span class=&quot;kw&quot;&gt;geom_ribbon&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;dat =&lt;/span&gt; manual_dat, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y, &lt;span class=&quot;dt&quot;&gt;ymin =&lt;/span&gt; ymin, &lt;span class=&quot;dt&quot;&gt;ymax =&lt;/span&gt; ymax), &lt;span class=&quot;dt&quot;&gt;fill =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;blue&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;alpha =&lt;/span&gt; .&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) + &lt;span class=&quot;co&quot;&gt;# Var&lt;/span&gt;
    &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;dat =&lt;/span&gt; manual_dat, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y), &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;blue&amp;quot;&lt;/span&gt;)  + &lt;span class=&quot;co&quot;&gt;#MEAN    &lt;/span&gt;
    &lt;span class=&quot;kw&quot;&gt;theme_bw&lt;/span&gt;() + &lt;span class=&quot;kw&quot;&gt;theme&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;plot.background =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;element_rect&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;fill =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;transparent&amp;quot;&lt;/span&gt;,&lt;span class=&quot;dt&quot;&gt;colour =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;NA&lt;/span&gt;))&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-10-9b2d792442-gp-plot.png&quot; alt=&quot;plot of chunk gp-plot&quot; /&gt;&lt;figcaption&gt;plot of chunk gp-plot&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;posteriors-of-hyperparameters&quot;&gt;Posteriors of hyperparameters&lt;/h2&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(reshape2)
hyperparameters &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;index&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;s2&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;tau2&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;beta0&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;nug&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;d&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;ldetK&amp;quot;&lt;/span&gt;)
posteriors &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(gp$trace$XX[[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]][,hyperparameters], &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;index&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(posteriors) + &lt;span class=&quot;kw&quot;&gt;geom_histogram&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value)) + &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~variable, &lt;span class=&quot;dt&quot;&gt;scales=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-10-9b2d792442-unnamed-chunk-9.png&quot; alt=&quot;plot of chunk unnamed-chunk-9&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-9&lt;/figcaption&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>Github Issues Tracker: The Perfect Research Todo List</title>
   <link href="/2012/12/06/github-issues-tracker%3A-the-perfect-research-todo-list.html"/>
   <updated>2012-12-06T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/12/06/github-issues-tracker:-the-perfect-research-todo-list</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;Github issues tracker has increasingly become my research to-do list. Far beyond bugs and features of the code associated with the project, the issues sign-post different directions for investigation and the progress I’ve made in each. Tags serve to group issues related to a common sub-project (as in my &lt;a href=&quot;https://github.com/cboettig/pdg_control/issues&quot;&gt;pdg-control&lt;/a&gt;) repo or priotize tasks (as in my &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues&quot;&gt;nonparametric-bayes&lt;/a&gt; repo.&lt;/p&gt;
&lt;p&gt;Issues not only have title and tags, but support a comment thread for progress and discussion of the issue. Thanks to github-flavored-markdown, issues can reference each other simply by number, and can be updated or closed automatically by mentioning the issue number in a commit.&lt;/p&gt;
&lt;p&gt;Issues can also be grouped into shared deadlines, or milestones; a feature I haven’t fully exploited (but see our &lt;a href=&quot;https://github.com/cboettig/ews-review/issues/milestones&quot;&gt;ews-review&lt;/a&gt; paper). In any collaborative project the issues can be assigned to different people, (though currently this requires they have a Github account).&lt;/p&gt;
&lt;p&gt;A consequence of this workflow is a conveniently numbered, color-coded and cross-linked collection of steps involved in a given research project. This tends to be a higher-level overview than the individual commit log, particularly as I often use commits to track multiple runs with different parameters, or move code across to different supercomputers that do the actual runs.&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8490/8250376085_09f734c6f1.jpg&quot; alt=&quot;Example from closed issues on pdg-control&quot; /&gt;&lt;figcaption&gt;Example from closed issues on &lt;a href=&quot;https://github.com/cboettig/pdg_control/issues?labels=&amp;amp;milestone=&amp;amp;page=1&amp;amp;state=closed&quot;&gt;&lt;code&gt;pdg-control&lt;/code&gt;&lt;/a&gt;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;I am still figuring out the right level or “resolution” on which to create and track issues.&lt;sup&gt;&lt;a href=&quot;#fn1&quot; class=&quot;footnoteRef&quot; id=&quot;fnref1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; On one extreme, almost every commit could be seen as resolving an issue. The ideal use for me is probably nearer the other extreme, where individual issues are rather big-picture, and may be referenced by many commits. Perhaps the right way to think about it is that the questions addressed by resolving an issue are on the level of &lt;em&gt;what is interesting to others&lt;/em&gt;, while changes in individual commits are more for me. Hopefully I get better at finding this relevant level.&lt;/p&gt;
&lt;p&gt;Another nice feature of issues is that they can be closed when a particular line of investigation hits a dead-end, or stalls, or when the problem is resolved. Unlike the resulting paper from an investigation which essentially summarizes the issues that were closed successfully, the issues tracker also reveals the dead-ends, as well as those issues that were not closed a time of publication (but perhaps left to “further research”). Hopefully I will have some decent examples of this in the repositories accompanying my next papers.&lt;/p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;hr /&gt;
&lt;ol&gt;
&lt;li id=&quot;fn1&quot;&gt;&lt;p&gt;Unlike issues, commits do not have a native tag structure (so-called “tags” mark important events in the commit history rather than grouping common commits). So at least this would group commits by the tag of the associated issue.&lt;a href=&quot;#fnref1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/12/05/notes.html"/>
   <updated>2012-12-05T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/12/05/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;pdg-control-call&quot;&gt;pdg-control Call&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Send Figure 3 and 4 with stock dynamics to Paul.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Detailed to do items coming out of talk filed as Github Issues for &lt;a href=&quot;https://github.com/cboettig/pdg_control/issues?labels=policy+costs&amp;amp;page=1&amp;amp;state=open&quot;&gt;pdg-control (policycosts)&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/issues/41&quot;&gt;Comparisons between assumed and true policy costs (Figure 5 style but as a Table)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/issues/40&quot;&gt;Snappier, more meaningful names for “L1”, “L2” etc&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/issues/39&quot;&gt;Write real-world context/significance of L1, L2, fixed, etc.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/issues/38&quot;&gt;Add graph &amp;amp; discussion of stock dynamics for Fig 3 &amp;amp; 4&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/issues/37&quot;&gt;Figure 5 interpretation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/issues/36&quot;&gt;Fix boundary issues in Figure 4&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/issues/35&quot;&gt;Resolve confusion about apples-to-apples / definition of NPV0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/issues/34&quot;&gt;Resolve cost structure question&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/issues/33&quot;&gt;On functional forms, drop ALL asymmetric cases for now.&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;comment-piece&quot;&gt;Comment piece&lt;/h2&gt;
&lt;p&gt;Round 1 revisions sent to Lucy and Alan.&lt;/p&gt;
&lt;h3 id=&quot;workflow-workshop&quot;&gt;Workflow Workshop&lt;/h3&gt;
&lt;p&gt;At Simone’s invitation, I’m running a little session on workflow in git/Github, Rstudio, and knitr for the Mangel lab group. A quick brainstorm for an outline:&lt;/p&gt;
&lt;h4 id=&quot;a-first-tutorial&quot;&gt;A first tutorial&lt;/h4&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;Create a new repository on Github&lt;/li&gt;
&lt;li&gt;launch an RStudio session, select create new project&lt;/li&gt;
&lt;li&gt;Add the &lt;code&gt;git@&lt;/code&gt; url to the project, select a local directory, hit “create”&lt;/li&gt;
&lt;li&gt;In Rstudio, create new R Markdown file.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Editing the file. Hit “Knit HTML” button.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;add the files to git: git tab, check boxes.&lt;/li&gt;
&lt;li&gt;commit the .Rmd and md files, and push files to Github.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Viewing files on github.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigating Github: Project directory, viewing &lt;code&gt;.md&lt;/code&gt; files, raw mode, viewing history of a file, getting permanent links to specific versions.&lt;br /&gt;10: Github extras: using issues. (Referencing issues in commits)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Recovering a deleted file.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&quot;git-more-advanced&quot;&gt;Git More Advanced&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Create a gh-pages branch and add the html generated from the Rstudio/knitr. (Covers branching &amp;amp; webpage hosting on github)&lt;/li&gt;
&lt;li&gt;Create a github homepage&lt;/li&gt;
&lt;li&gt;Merging changes, resolving conflicts.&lt;/li&gt;
&lt;li&gt;collaborating via github.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;why sha hashes are awesome&lt;/li&gt;
&lt;li&gt;private repositories&lt;/li&gt;
&lt;li&gt;Repo Readmes&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;other-topics&quot;&gt;Other topics&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Managing references. Sharing collections (Mendeley)&lt;/li&gt;
&lt;li&gt;References in markdown. Pandoc. (knitcitations?)&lt;/li&gt;
&lt;li&gt;Managing data. Figshare.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Social media for science.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Tgp Mcmc For Gaussian Processes</title>
   <link href="/2012/12/04/tgp-mcmc-for-gaussian-processes.html"/>
   <updated>2012-12-04T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/12/04/tgp-mcmc-for-gaussian-processes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Exploring implementation through &lt;code&gt;tgp&lt;/code&gt; package MCMC routine and background reading (manual, vignettes, thesis).&lt;/p&gt;
&lt;p&gt;Example call:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;bgp&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;X=&lt;/span&gt;X, &lt;span class=&quot;dt&quot;&gt;XX=&lt;/span&gt;XX, &lt;span class=&quot;dt&quot;&gt;Z=&lt;/span&gt;Z, &lt;span class=&quot;dt&quot;&gt;meanfn=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;constant&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;bprior=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;b0&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;BTE=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;6000&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;m0r1=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;verb=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;corr=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;exp&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;trace=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;s2.p=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;tau2.p=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;s2.lam=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;tau2.lam=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Verbose return:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;n=39, d=1, nn=101
BTE=(1000,6000,2), R=1, linburn=0
RNG state RK using rk_seed
preds: data krige
T[alpha,beta,nmin,smin,bmax]=[0,0,10,1,1]
mean function: constant
beta prior: b0 hierarchical
s2[a0,g0]=[5,10]
s2 prior fixed
tau2[a0,g0]=[5,10]
tau2 prior fixed
corr prior: isotropic power
nug[a,b][0,1]=[1,1],[1,1]
nug prior fixed
gamlin=[0,0.2,0.7]
d[a,b][0,1]=[1,20],[10,10]
d prior fixed&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The parameters in this run are constant across the trace points (because hyperparameters are fixed).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;X&lt;/code&gt; is the observed X values (or matrix of appropriate dimension)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;XX&lt;/code&gt; the desired predicted grid. (will also predict on X)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Z&lt;/code&gt; is observed Y values (or matrix of appropriate dimension)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;m0r1&lt;/code&gt; means scale data to mean zero and unit range&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bprior&lt;/code&gt; is the prior distribution, defaulting to &lt;code&gt;bfalt&lt;/code&gt;. &lt;code&gt;b0&lt;/code&gt; is a Gaussian. This prior is for the Gaussian process and is not to be confused with the hyperpriors describing the distribution of various parameters.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;BTE&lt;/code&gt; Burn-in B steps, Terminate after T steps, sample Every E steps.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;verb&lt;/code&gt; Very verbose output&lt;/li&gt;
&lt;li&gt;Other options (for adaptive/query learning, etc, igored for now. Focus on priors).&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The priors for the hyperparameters are given by &lt;code&gt;s2.p&lt;/code&gt;, &lt;code&gt;tau.p&lt;/code&gt; etc (both are Inverse Gammas). Their parameters can vary hiearchically in general, but we hold them fixed, &lt;code&gt;s2.lam = 'fixed'&lt;/code&gt;, etc.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;s2&lt;/code&gt; is &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\sigma^2\inline&quot;/&gt;&lt;/span&gt; in Gramacy and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\tau\inline&quot;/&gt;&lt;/span&gt; in Rassmussen and Williams, is the scale of the noise. Comes from an inverse gamma prior. Set by inverse-gamma parameters &lt;code&gt;a0&lt;/code&gt; and &lt;code&gt;g0&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;tau2&lt;/code&gt; Also comes from an inverse gamma prior. It is also set by inverse-gamma parameters &lt;code&gt;a0&lt;/code&gt; and &lt;code&gt;g0&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?Z | \beta, \sigma^2, K \sim N_n(\mathbf{F} \beta, \sigma^2 \mathbf{K})&quot; alt=&quot;Z | \beta, \sigma^2, K \sim N_n(\mathbf{F} \beta, \sigma^2 \mathbf{K})&quot; /&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\beta | \sigma^2, \tau^2, \mathbf{W}, \beta_0 ~ N_m(\beta_0, \sigma^2 \tau^2 \mathbf{W} )&quot; alt=&quot;\beta | \sigma^2, \tau^2, \mathbf{W}, \beta_0 ~ N_m(\beta_0, \sigma^2 \tau^2 \mathbf{W} )&quot; /&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\beta_0 | N_m(\mathbf{\mu}, \mathbf{B})&quot; alt=&quot;\beta_0 | N_m(\mathbf{\mu}, \mathbf{B})&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We keep the heirachical priors fixed in the &lt;code&gt;tau.lm&lt;/code&gt;, &lt;code&gt;s2.lm&lt;/code&gt;, etc. &lt;code&gt;nug&lt;/code&gt; fixed by default. Note this results in the the priors from which these are sampled are fixed: e.g. &lt;code&gt;gp$trace$hier$s2.a0&lt;/code&gt;, &lt;code&gt;gp$trace$hier$s2.g0&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;nug.p&lt;/code&gt; This is the “nugget,” the measurement error. Comes from a mixture of gamma prior parameter (initial values) for the nugget parameter &lt;code&gt;c(a1,g1,a2,g2)&lt;/code&gt; where &lt;code&gt;g1&lt;/code&gt; and &lt;code&gt;g2&lt;/code&gt; are scale (&lt;code&gt;1/rate&lt;/code&gt;) parameters. &lt;em&gt;Default reduces to simple exponential prior.&lt;/em&gt; Specifying &lt;code&gt;nug.p = 0&lt;/code&gt; fixes the nugget parameter to the “starting” value in &lt;code&gt;gd[1]&lt;/code&gt;, i.e., it is excluded from the MCMC&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;index&lt;/code&gt; is the sampling point (from &lt;code&gt;BTE&lt;/code&gt;, we see we sample starting at step 1000 and ending at step 6000, recording every 2 steps, so there are &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?(T-B)/E = 2500\inline&quot;/&gt;&lt;/span&gt; index points).&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;lambda&lt;/code&gt; possibly a mixing parameter in the importance sampler temperature??&lt;/li&gt;
&lt;li&gt;&lt;code&gt;beta0&lt;/code&gt; No mention in the manual&lt;/li&gt;
&lt;li&gt;&lt;code&gt;d&lt;/code&gt; The parameter for priors using the hierachical exponential distribution for the parameters &lt;code&gt;a1&lt;/code&gt;, &lt;code&gt;a2&lt;/code&gt;, &lt;code&gt;g1&lt;/code&gt;, &lt;code&gt;g2&lt;/code&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;b&lt;/code&gt; ??&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Where are the hyperparameters for the correlation function (e.g. the length-scale for the Gaussian??)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;traces&quot;&gt;Traces&lt;/h3&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;pars &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(gp$trace$XX[[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]], &lt;span class=&quot;dt&quot;&gt;id =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;index&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(pars, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(index, value)) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;() + &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~variable, &lt;span class=&quot;dt&quot;&gt;scales=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free_y&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-04-046b509f8d-unnamed-chunk-5.png&quot; alt=&quot;plot of chunk unnamed-chunk-5&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-5&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;It is possible to calculate summary statistics and check out the distribution of these fellows.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;mean&lt;/span&gt;(gp$trace$XX[[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]][,&lt;span class=&quot;st&quot;&gt;&amp;quot;nug&amp;quot;&lt;/span&gt;])&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;[1] 0.009755&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(pars, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(value)) + &lt;span class=&quot;kw&quot;&gt;geom_histogram&lt;/span&gt;() + &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~variable, &lt;span class=&quot;dt&quot;&gt;scales=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;free&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-04-046b509f8d-unnamed-chunk-6.png&quot; alt=&quot;plot of chunk unnamed-chunk-6&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-6&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;extracting-the-estimated-process&quot;&gt;Extracting the estimated process&lt;/h2&gt;
&lt;p&gt;(The &lt;strong&gt;MAP&lt;/strong&gt;, maximum a posteriori expected mean and variance).&lt;/p&gt;
&lt;p&gt;Extract the posterior Gaussian process mean and the &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\pm 2\inline&quot;/&gt;&lt;/span&gt; standard deviations over the predicted grid from the fit:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;V &amp;lt;- gp$ZZ.ks2
dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x   =&lt;/span&gt; gp$XX[[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]], 
                 &lt;span class=&quot;dt&quot;&gt;y    =&lt;/span&gt; gp$ZZ.km, 
                 &lt;span class=&quot;dt&quot;&gt;ymin =&lt;/span&gt; gp$ZZ.km - &lt;span class=&quot;fl&quot;&gt;1.96&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(gp$ZZ.ks2), 
                 &lt;span class=&quot;dt&quot;&gt;ymax =&lt;/span&gt; gp$ZZ.km + &lt;span class=&quot;fl&quot;&gt;1.96&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(gp$ZZ.ks2))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Plot the posterior Gaussian Process:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;  p1 &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dat) +
    &lt;span class=&quot;kw&quot;&gt;geom_ribbon&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x,&lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;y, &lt;span class=&quot;dt&quot;&gt;ymin=&lt;/span&gt;ymin, &lt;span class=&quot;dt&quot;&gt;ymax=&lt;/span&gt;ymax), &lt;span class=&quot;dt&quot;&gt;fill=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;grey80&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;co&quot;&gt;# Var&lt;/span&gt;
    &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x,&lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;y), &lt;span class=&quot;dt&quot;&gt;size=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) + &lt;span class=&quot;co&quot;&gt;#MEAN&lt;/span&gt;
    &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;gp$obs,&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x,&lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;y)) + 
    &lt;span class=&quot;kw&quot;&gt;labs&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;title=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;paste&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;llik =&amp;quot;&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;prettyNum&lt;/span&gt;(gp$llik)))
  if(!&lt;span class=&quot;kw&quot;&gt;is.null&lt;/span&gt;(true))
    p1 &amp;lt;- p1 + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data =&lt;/span&gt; true, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y), &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;lty =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;) 
p1 + theme_notebook&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-04-046b509f8d-gp-plot.png&quot; alt=&quot;plot of chunk gp-plot&quot; /&gt;&lt;figcaption&gt;plot of chunk gp-plot&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Find the actual optimum policy from the true parametric model&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;x_grid &amp;lt;- dat$x
h_grid &amp;lt;- x_grid
matrices_true &amp;lt;- &lt;span class=&quot;kw&quot;&gt;f_transition_matrix&lt;/span&gt;(f, p, x_grid, h_grid)
opt_true &amp;lt;- &lt;span class=&quot;kw&quot;&gt;find_dp_optim&lt;/span&gt;(matrices_true, x_grid, h_grid, &lt;span class=&quot;dv&quot;&gt;20&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, profit, &lt;span class=&quot;dt&quot;&gt;delta=&lt;/span&gt;.&lt;span class=&quot;dv&quot;&gt;01&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Estimate a policy from the Gaussian Process:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;rownorm &amp;lt;- function(M) &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;apply&lt;/span&gt;(M, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, function(x) x/&lt;span class=&quot;kw&quot;&gt;sum&lt;/span&gt;(x)))
matrices_gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(h_grid, function(h){
    S &amp;lt;- dat$y - h
    F_ &amp;lt;- &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(S), function(i){
      if(S[i]&amp;gt;&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;) {
        out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;dlnorm&lt;/span&gt;(x_grid/S[i], &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, V[i])
      } else {
        out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;numeric&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(x_grid))
        out[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;
        out
      }
    }))
    F_ &amp;lt;- &lt;span class=&quot;kw&quot;&gt;rownorm&lt;/span&gt;(F_)
  })
opt_gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;find_dp_optim&lt;/span&gt;(matrices_gp, x_grid, h_grid, &lt;span class=&quot;dv&quot;&gt;20&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, profit, &lt;span class=&quot;dt&quot;&gt;delta=&lt;/span&gt;.&lt;span class=&quot;dv&quot;&gt;01&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and plot&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;policies &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;stock=&lt;/span&gt;x_grid, &lt;span class=&quot;dt&quot;&gt;GP =&lt;/span&gt; x_grid[opt_gp$D[,&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]], &lt;span class=&quot;dt&quot;&gt;Exact =&lt;/span&gt; x_grid[opt_true$D[,&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]]), &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;stock&amp;quot;&lt;/span&gt;)
policy_plot &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(policies, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(stock, stock - value, &lt;span class=&quot;dt&quot;&gt;color=&lt;/span&gt;variable)) +
  &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;() + &lt;span class=&quot;kw&quot;&gt;xlab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;stock size&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;ylab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;escapement&amp;quot;&lt;/span&gt;) 
policy_plot + theme_notebook&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-04-046b509f8d-policy_plot.png&quot; alt=&quot;plot of chunk policy_plot&quot; /&gt;&lt;figcaption&gt;plot of chunk policy_plot&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;We can see what happens when we attempt to manage a stock using this:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;z_g &amp;lt;- function() &lt;span class=&quot;kw&quot;&gt;rlnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, sigma_g)
&lt;span class=&quot;kw&quot;&gt;set.seed&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)
sim_gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ForwardSimulate&lt;/span&gt;(f, p, x_grid, h_grid, K, opt_gp$D, z_g, &lt;span class=&quot;dt&quot;&gt;profit=&lt;/span&gt;profit)
&lt;span class=&quot;kw&quot;&gt;set.seed&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)
sim_true &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ForwardSimulate&lt;/span&gt;(f, p, x_grid, h_grid, K, opt_true$D, z_g, &lt;span class=&quot;dt&quot;&gt;profit=&lt;/span&gt;profit)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;df &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time =&lt;/span&gt; sim_gp$time, &lt;span class=&quot;dt&quot;&gt;stock_gp =&lt;/span&gt; sim_gp$fishstock, &lt;span class=&quot;dt&quot;&gt;stock_true =&lt;/span&gt; sim_true$fishstock, &lt;span class=&quot;dt&quot;&gt;harvest_gp =&lt;/span&gt; sim_gp$harvest, &lt;span class=&quot;dt&quot;&gt;havest_true =&lt;/span&gt; sim_true$harvest)
df &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(df, &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;time&amp;quot;&lt;/span&gt;)
simplot &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(df) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time,value, &lt;span class=&quot;dt&quot;&gt;color=&lt;/span&gt;variable))
simplot + theme_notebook&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-04-046b509f8d-simplot.png&quot; alt=&quot;plot of chunk simplot&quot; /&gt;&lt;figcaption&gt;plot of chunk simplot&lt;/figcaption&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>Figures 3 And 4 For Policycosts</title>
   <link href="/2012/12/03/Figures-3-and-4-for-policycosts.html"/>
   <updated>2012-12-03T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/12/03/Figures-3-and-4-for-policycosts</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Straight-forward tasks can sometimes take forever. In advance of our upcoming conference call for the Pretty Darn Good Control (&lt;code&gt;pdg-control&lt;/code&gt;) NIMBioS working group, I had a few remaining issues to touch up in Figures 3 and 4.&lt;/p&gt;
&lt;p&gt;Figure 3 shows harvest and stock dynamics under the different functional forms fo the cost. The goal is to provide a very intuitive, visual sense of how the policies differ under these different functional forms, such as a fixed “transaction fee” (fixed) or a cost that is proportional to the size of the change in policy (L1), or the square of that change (L2), etc. I had already cobbled together the code for this, but simply had to run over the same set of replicates and pick a window length appropriate to see the differences. The trick was make sure we were comparing functional forms that had the same overall net impact on the Net Present Value of the stock. In this way, the differences observed are due only to differences in the form of the cost, and not the total magnitude of the cost. Figure 2 already provided a way to do this scaling, I simply needed to back out the scaling programmatically.&lt;/p&gt;
&lt;p&gt;Finding these “apples-to-apples” levels is something of a computational brute force excercise, computing the costs along a grid of coefficients for each method. Otherwise the idea is pretty straight forward. One trick was being able to use the policies calculated in this step to generate the Figure 3 simulations, rather than recalculating the policy once the right scaling value &lt;code&gt;c2&lt;/code&gt; is known.&lt;/p&gt;
&lt;p&gt;Figure 4 provides a more quantitative way to look at the comparison. I had already created a version of this graph that showed how variance and autocorrelation in the policy and state variable dynamics changed as the total magnitude of the cost increased. Unfortunately this suffered from the apples-to-oranges problem for comparing between functional forms. The x-axis needed to be calculated in terms of the reduction of the NPV, rather then the coefficients (&lt;code&gt;c2&lt;/code&gt;, which mean different things in the different forms), for a proper apples-to-apples comparison.&lt;/p&gt;
&lt;p&gt;Okay, straight forward exercise. 47 commits and 19 hours later, I have what I need. And it is 5am. Oh well, this post is still going down as “Monday”.&lt;/p&gt;
&lt;h3 id=&quot;figure-3&quot;&gt;Figure 3&lt;/h3&gt;
&lt;h4 id=&quot;stock-state-variable-dynamics&quot;&gt;Stock (state variable) dynamics&lt;/h4&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-05-72dc8741fb-p1.png&quot; /&gt;
&lt;/figure&gt;
&lt;h4 id=&quot;harvest-control-variable-dynamics&quot;&gt;Harvest (control variable) dynamics&lt;/h4&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-05-72dc8741fb-Figure3.png&quot; /&gt;
&lt;/figure&gt;
&lt;h3 id=&quot;figure-4&quot;&gt;Figure 4&lt;/h3&gt;
&lt;h4 id=&quot;stock-state-variable-dynamics-1&quot;&gt;Stock (state variable) dynamics&lt;/h4&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-05-72dc8741fb-Figure4S1.png&quot; /&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-05-72dc8741fb-Figure4S2.png&quot; /&gt;
&lt;/figure&gt;
&lt;h5 id=&quot;harvest-control-variable-dynamics-1&quot;&gt;Harvest (control variable) dynamics&lt;/h5&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-05-72dc8741fb-Figure41.png&quot; /&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-05-72dc8741fb-Figure42.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/blob/25e6f1c1a599440be790a7ec047b8b63540255c5/inst/examples/policycosts/writeup.md&quot;&gt;full knitr file here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;These are calculated with &lt;code&gt;c0 = 30&lt;/code&gt;. There’s corresponding figures when fishing effort itself is cost-free, &lt;code&gt;c0 = 0&lt;/code&gt;. See &lt;a href=&quot;https://github.com/cboettig/pdg_control/blob/cccec55a8ac2ef47dea99d45fdb732e5028aec98/inst/examples/policycosts/costfree.md&quot;&gt;costfree.md&lt;/a&gt;. Looks like the &lt;code&gt;c2&lt;/code&gt; range needs to be extended for this run.&lt;/p&gt;
&lt;h3 id=&quot;figure-2&quot;&gt;Figure 2&lt;/h3&gt;
&lt;p&gt;The apples-to-apples illustration is also generated in this script.&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-05-72dc8741fb-apples_plot.png&quot; /&gt;
&lt;/figure&gt;
&lt;h3 id=&quot;misc-notes&quot;&gt;Misc notes&lt;/h3&gt;
&lt;p&gt;Caching is pretty helpful in fiddling with these slow computations. Sometimes it helps to copy the cache of the intensive part of a run over from the supercomputer to the local machine, and load the whole cache into an interactive R session. Loading the whole cache can be done as such:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;e &amp;lt;- &lt;span class=&quot;kw&quot;&gt;environment&lt;/span&gt;()
files &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;.rdb&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;system&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;#39;ls *.rdb&amp;#39;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;intern=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;))
&lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(files, lazyLoad, &lt;span class=&quot;dt&quot;&gt;env=&lt;/span&gt;e)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;providied the target chache directory doesn’t have caches of different commits.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Note On Notebook Figures</title>
   <link href="/2012/11/30/Note-on-notebook-figures.html"/>
   <updated>2012-11-30T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/11/30/Note-on-notebook-figures</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;h2 id=&quot;plots-for-the-notebook&quot;&gt;plots for the notebook&lt;/h2&gt;
&lt;p&gt;I have started uploading images to my own server, rather than flickr. Programmatically, this is just a matter of switching the knitr upload function:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;opts_knit$&lt;span class=&quot;kw&quot;&gt;set&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;upload.fun =&lt;/span&gt; socialR::notebook.url)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;from my custom &lt;a href=&quot;https://github.com/cboettig/socialR/blob/299f4aeb8cc1a9b31c761dc7c9b14b1d73f7ef25/R/custom_knit.R&quot;&gt;flickr.url&lt;/a&gt; function (a wrapper to &lt;code&gt;Rflickr&lt;/code&gt;) to a custom function &lt;a href=&quot;https://github.com/cboettig/socialR/blob/e9a30fd6381c1a8147cbaec0e3886d559de6d48c/R/notebook.R&quot;&gt;notebook.url&lt;/a&gt; using a system call to &lt;code&gt;cp&lt;/code&gt; (to my local jekyll notebook) and &lt;code&gt;rsync&lt;/code&gt; (so the figure displays before my next jekyll push).&lt;/p&gt;
&lt;p&gt;The new script names image by date and the first 10 characters of the sha hash, as well as the knitr chunk name. This way multiple runs tweaking an individual file are not recorded as separate files if no commits are made to the repository, but every commit is guaranteed to link to a unique set of figures (unless the chunk is loaded from cache and does not generate a new image). All figures also &lt;a href=&quot;http://www.carlboettiger.info/assets/figures/&quot;&gt;appear sorted by date on the webserver&lt;/a&gt; in the manner. I could probably put some lightweightphotobrowser on the server, if browsing images serves any purpose.&lt;/p&gt;
&lt;p&gt;The real reason for the change is to maintain the images in my labnotebook directory, such that the directory is a complete archive that can exist independent of web services such as flickr. The images aren’t included in the git management for obvious reasons. My current archiving on figshare has simple involved zipping up the markdown versions of all my posts by year (in _posts). If I continue in this way, I should need to archive the &lt;code&gt;figures/&lt;/code&gt; directory along with it. Perhaps I should archive the entire Jekyll directory instead.&lt;sup&gt;&lt;a href=&quot;#fn1&quot; class=&quot;footnoteRef&quot; id=&quot;fnref1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;An alternative strategy would be to upload each figure to figshare directly in the same way I was doing with flickr. While this has the advantage of clockss archiving, mostly I’m not sure that I should flood my figshare account in this way. I really don’t need a different doi for every attempt to create a figure (just as I’ve decided not to archive each notebook entry as a separate figshare object.)&lt;/p&gt;
&lt;h3 id=&quot;plot-appearance-transparency-in-the-notebook&quot;&gt;Plot appearance (transparency) in the notebook&lt;/h3&gt;
&lt;p&gt;It’s not easy to generate figures that display nicely in both dark and light themes (well, I should just tell ggplot to use a solarized set of theme colors, but I’m too lazy to write that). Meanwhile, just setting the transparent background to the plot, and transparent grid lines against the grey boxes seems to do pretty well:&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-12-04-046b509f8d-unnamed-chunk-6.png&quot; alt=&quot;Example transparent plot&quot; /&gt;&lt;figcaption&gt;Example transparent plot&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;This is accomplished with the codeblock below. Note that we need to tell &lt;code&gt;knitr&lt;/code&gt; chunks to set the background of the png device to transparent, as well as telling ggplot what we want to be transparent:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;opts_chunk$&lt;span class=&quot;kw&quot;&gt;set&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;dev.args=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;bg=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;transparent&amp;quot;&lt;/span&gt;))
theme_notebook &amp;lt;- 
  &lt;span class=&quot;kw&quot;&gt;theme_grey&lt;/span&gt;() + 
  &lt;span class=&quot;kw&quot;&gt;theme&lt;/span&gt;(
    &lt;span class=&quot;dt&quot;&gt;plot.background =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;element_rect&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;fill =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;transparent&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;colour =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;NA&lt;/span&gt;),
    &lt;span class=&quot;dt&quot;&gt;panel.grid.major =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;element_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;colour =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;transparent&amp;quot;&lt;/span&gt;)),
    panel.grid.minor = &lt;span class=&quot;kw&quot;&gt;element_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;colour =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;transparent&amp;quot;&lt;/span&gt;)&lt;span class=&quot;er&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;theme_set&lt;/span&gt;(theme_notebook)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(It appears this makes the gridlines invisible, since they appear over the grey &lt;code&gt;panel.background&lt;/code&gt;. For now, best to leave them white, which shows up against the grey background in any event).&lt;/p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;hr /&gt;
&lt;ol&gt;
&lt;li id=&quot;fn1&quot;&gt;&lt;p&gt;One challenge this introduces is private posts (such as the reviews I write in peer review, which I sign but cannot publicly disclose). Currently these are ignored by github (&lt;code&gt;.gitignore&lt;/code&gt;) and by Jekyll (&lt;code&gt;exclude:&lt;/code&gt; in &lt;code&gt;_config.yml&lt;/code&gt;). I suppose I could likewise simply tell tarball to ignore &lt;code&gt;_posts/private&lt;/code&gt;.&lt;a href=&quot;#fnref1&quot;&gt;↩&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</content>
 </entry>
 
 <entry>
   <title>early results in nonparametric-bayes approaches to optimal policy</title>
   <link href="/2012/11/28/nonparametric-bayes-work.html"/>
   <updated>2012-11-28T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/11/28/nonparametric-bayes-work</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;resolving-numerical-and-computational-issues&quot;&gt;Resolving Numerical and Computational issues&lt;/h2&gt;
&lt;h4 id=&quot;sequential-approach-issue-4&quot;&gt;Sequential approach? (&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/4&quot;&gt;issue #4&lt;/a&gt;)&lt;/h4&gt;
&lt;p&gt;Thinking through whether or not it is worth optimizing the computational performance of the sequential approach.&lt;/p&gt;
&lt;p&gt;Can it be demonstrated that this actually has higher numerical stability? Alternatively, can it be demonstrated that this is (or is not) equivalent to the calculation performed by the direct inversion? What is the difference in computational complexity between these approaches? e.g. the inverse ends up effectively O(n^3), but what is the recursion?&lt;/p&gt;
&lt;p&gt;If we assume measurement noise, is stability an issue? e.g. introducing such small noise or jitter apparently a standard method to address stability; see pg 12 and citations there-in (Matheron, 1963; Cressie, 1991, Neal, 1997).&lt;/p&gt;
&lt;p&gt;How much accuracy is lost with reasonable grids? Compared to adding jitter?&lt;/p&gt;
&lt;p&gt;Is there any evidence of use for this approach in the substantial GP literature of computational experts?&lt;/p&gt;
&lt;p&gt;With large data sets, the determinant does get close to zero, but solutions appear stable with direct (DGESV) inversion. See &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/4&quot;&gt;issue #4&lt;/a&gt; for a discussion.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;seeing if I get singular matrices in the inversion &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/7faf6791cb386db48687144937868f976814dc65&quot;&gt;09:55 pm 2012/11/28&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;print determinant value &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/71f2443754193910bd20af1e9659848d5de1dc86&quot;&gt;10:00 pm 2012/11/28&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;choleski-issue-2&quot;&gt;Choleski, (&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/2&quot;&gt;issue #2&lt;/a&gt;)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;basic example comparing methods &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/113df7a98a46e0fb91443a60867c887a76f3ccb6&quot;&gt;08:10 pm 2012/11/28&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;choleski approach using backsolve &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/5c332aa3ade026973fa5cb873f7ec3c7b5c6f7d3&quot;&gt;05:49 pm 2012/11/28&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Some explaining to do here.&lt;/p&gt;
&lt;h3 id=&quot;hyperparameter-optimization-issue-3&quot;&gt;Hyperparameter optimization (&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/issues/3&quot;&gt;issue #3&lt;/a&gt;)&lt;/h3&gt;
&lt;p&gt;Added necessary hyperparameter for variance in the covariance kernel &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\tau\inline&quot;/&gt;&lt;/span&gt;, in kernel &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\tau e^{-(x-x&amp;#39;)^2/\ell}\inline&quot;/&gt;&lt;/span&gt;. Alternatively should be scaling data s.t. variance is unity. Manually tuning this does allow for better fits. Need to try optimization still. Have added a method to condition on the function going through (0,0) with negligible error, currently in a somewhat direct/inelegant code (and potential for numerical instability).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Reed example using tau not set to 1 and conditioning on going through (0,0) &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/0de731ae0924ea649549dafebb4914f2da3269a6&quot;&gt;05:34 pm 2012/11/28&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;allow for tau as hyperparameter &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/ca583db171b79f732c00ce8acd5b902942619c4e&quot;&gt;02:55 pm 2012/11/28&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now getting reasonable performance of the Gaussian process relative to the optimal policy (also see earlier examples below). Comforting to see that the Gaussian Process results in slightly larger uncertainty and manages slightly more conservatively (higher standing stock, lower harvests). Very conservative outside range of data – resulting in a policy function deviating strongly from Reed’s constant escapement.&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-11-28-ca583db171-unnamed-chunk-2.png&quot; alt=&quot;plot of chunk unnamed-chunk-2&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-2&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-11-28-ca583db171-policy_plot.png&quot; alt=&quot;plot of chunk policy_plot&quot; /&gt;&lt;figcaption&gt;plot of chunk policy_plot&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-11-28-ca583db171-simplot.png&quot; alt=&quot;plot of chunk simplot&quot; /&gt;&lt;figcaption&gt;plot of chunk simplot&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h3 id=&quot;functionalize-package&quot;&gt;Functionalize package&lt;/h3&gt;
&lt;p&gt;Existing methods now all implemented in package function &lt;code&gt;gp_fit&lt;/code&gt;, and method for SDP via GP in &lt;code&gt;gp_transition_matrices&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;as before but with kernlab fit (underestimates lengthscale) &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/16892e97b750b8d2e0bf7e31cf05cdaae592e979&quot;&gt;02:16 pm 2012/11/28&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Identical to previous reed-example commit but with kernlab engine (not fit) &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/ba98931d271492ff1b819b558dceefcc04c444f2&quot;&gt;02:14 pm 2012/11/28&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Example of direct method using subroutines from &lt;code&gt;R/&lt;/code&gt; &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/158fae025441495527c58dda627756ff54d9862f&quot;&gt;02:11 pm 2012/11/28&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Different GP fitting routines can all be called with gp_fit and plotted with plot.gpfit. transition matrices for GP can be estimated with &lt;code&gt;gp_transition_matrices&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;See example use in reed-example.R &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/8fa49628f1969eab457109c7364382649e87143e&quot;&gt;01:48 pm 2012/11/28&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Policy Costs Work</title>
   <link href="/2012/11/27/policy-costs-work.html"/>
   <updated>2012-11-27T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/11/27/policy-costs-work</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Scripts to estimate apples to apples comparisons for different penalty functions and plot instances of the resulting policy. Example run with fixed linear costs on effort.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Double the actual variance leads to terminal overfishing &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/ee608e9a5dc94f98c7cb97e13133e01bd0823815&quot;&gt;11:16 am 2012/11/28&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;use fixed seed. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/22930fb2a81b2e89d848516b6bbca4278fc1e59b&quot;&gt;09:45 am 2012/11/28&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Compare GP to Reed optimum for BH (successful run this time) &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/59d864f621fbe6926407fb2e9adf7a255f8b84a7&quot;&gt;09:37 am 2012/11/28&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;basic GP example in BH system, compared to Reed Optimum &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/05e096fce1f65155b7b288be39d983717069edef&quot;&gt;09:17 am 2012/11/28&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Content of current working example, run on server &lt;em&gt;zero&lt;/em&gt;. See commit &lt;a href=&quot;https://github.com/cboettig/pdg_control/blob/942b2faa91d4930622133f7c9385ef2c65e976f1/inst/examples/policycosts/policycosts_writeup_c0_30.md&quot;&gt;942b2faa91&lt;/a&gt;&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;seed &amp;lt;- &lt;span class=&quot;dv&quot;&gt;123&lt;/span&gt;  &lt;span class=&quot;co&quot;&gt;# Random seed (replicable results)&lt;/span&gt;
delta &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.05&lt;/span&gt;  &lt;span class=&quot;co&quot;&gt;# economic discounting rate&lt;/span&gt;
OptTime &amp;lt;- &lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;  &lt;span class=&quot;co&quot;&gt;# stopping time&lt;/span&gt;
gridsize &amp;lt;- &lt;span class=&quot;dv&quot;&gt;50&lt;/span&gt;  &lt;span class=&quot;co&quot;&gt;# grid size for fish stock and harvest rate (discretized population)&lt;/span&gt;
sigma_g &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.2&lt;/span&gt;  &lt;span class=&quot;co&quot;&gt;# Noise in population growth&lt;/span&gt;
reward &amp;lt;- &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;  &lt;span class=&quot;co&quot;&gt;# bonus for satisfying the boundary condition&lt;/span&gt;
z_g &amp;lt;- function() &lt;span class=&quot;kw&quot;&gt;rlnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, sigma_g)  &lt;span class=&quot;co&quot;&gt;# mean 1&lt;/span&gt;
z_m &amp;lt;- function() &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;co&quot;&gt;# No measurement noise,&lt;/span&gt;
z_i &amp;lt;- function() &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;co&quot;&gt;# No implemenation noise&lt;/span&gt;
f &amp;lt;- BevHolt  &lt;span class=&quot;co&quot;&gt;# Select the state equation&lt;/span&gt;
pars &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;fl&quot;&gt;1.5&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.05&lt;/span&gt;)  &lt;span class=&quot;co&quot;&gt;# parameters for the state equation&lt;/span&gt;
K &amp;lt;- (pars[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] - &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)/pars[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]  &lt;span class=&quot;co&quot;&gt;# Carrying capacity (for reference&lt;/span&gt;
xT &amp;lt;- &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;  &lt;span class=&quot;co&quot;&gt;# boundary conditions&lt;/span&gt;
x0 &amp;lt;- K
profit &amp;lt;- &lt;span class=&quot;kw&quot;&gt;profit_harvest&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;price =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;c0 =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;30&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;c1 =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)
x_grid &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;fl&quot;&gt;0.01&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;1.2&lt;/span&gt; * K, &lt;span class=&quot;dt&quot;&gt;length =&lt;/span&gt; gridsize)
h_grid &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;fl&quot;&gt;0.01&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.8&lt;/span&gt; * K, &lt;span class=&quot;dt&quot;&gt;length =&lt;/span&gt; gridsize)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;SDP_Mat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;determine_SDP_matrix&lt;/span&gt;(f, pars, x_grid, h_grid, sigma_g)
opt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;find_dp_optim&lt;/span&gt;(SDP_Mat, x_grid, h_grid, OptTime, xT, profit, delta, &lt;span class=&quot;dt&quot;&gt;reward =&lt;/span&gt; reward)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;L1 &amp;lt;- function(c2) function(h, h_prev) c2 * &lt;span class=&quot;kw&quot;&gt;abs&lt;/span&gt;(h - h_prev)
free_increase &amp;lt;- function(c2) function(h, h_prev) c2 * &lt;span class=&quot;kw&quot;&gt;abs&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;min&lt;/span&gt;(h - h_prev, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;))  &lt;span class=&quot;co&quot;&gt;# increasing harvest is free&lt;/span&gt;
free_decrease &amp;lt;- function(c2) function(h, h_prev) c2 * &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(h - h_prev, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)  &lt;span class=&quot;co&quot;&gt;# decreasing harvest is free&lt;/span&gt;
fixed &amp;lt;- function(c2) function(h, h_prev) c2 * &lt;span class=&quot;kw&quot;&gt;as.numeric&lt;/span&gt;(!(h == h_prev))
L2 &amp;lt;- function(c2) function(h, h_prev) c2 * (h - h_prev)^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;
none &amp;lt;- function(h, h_prev) &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;
penaltyfns &amp;lt;- &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;L2 =&lt;/span&gt; L2, &lt;span class=&quot;dt&quot;&gt;L1 =&lt;/span&gt; L1, &lt;span class=&quot;dt&quot;&gt;free_decrease =&lt;/span&gt; free_decrease, &lt;span class=&quot;dt&quot;&gt;fixed =&lt;/span&gt; fixed, 
    &lt;span class=&quot;dt&quot;&gt;free_increase =&lt;/span&gt; free_increase)
c2 &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;length.out =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;30&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;apples-to-apples-levels&quot;&gt;Apples to Apples levels&lt;/h2&gt;
&lt;p&gt;This can take a while, so we use explicit parallelization,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(snowfall)
&lt;span class=&quot;kw&quot;&gt;sfInit&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;cpu =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;8&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;parallel =&lt;/span&gt; T)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;R Version:  R version 2.15.2 (2012-10-26) 
&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;sfLibrary&lt;/span&gt;(pdgControl)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;Library pdgControl loaded.&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;sfExportAll&lt;/span&gt;()&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;loop-over-penalty-functions-and-magnitudes&quot;&gt;Loop over penalty functions and magnitudes&lt;/h2&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;policies &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sfSapply&lt;/span&gt;(penaltyfns, function(penalty) {
    policies &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(c2, function(c2) {
        policycost &amp;lt;- &lt;span class=&quot;kw&quot;&gt;optim_policy&lt;/span&gt;(SDP_Mat, x_grid, h_grid, OptTime, xT, profit, 
            delta, reward, &lt;span class=&quot;dt&quot;&gt;penalty =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;penalty&lt;/span&gt;(c2))
        i &amp;lt;- &lt;span class=&quot;kw&quot;&gt;which&lt;/span&gt;(x_grid &amp;gt; K)[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]
        &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(policycost$penalty_free_V[i, ])
    })
})&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that &lt;code&gt;optim_policy&lt;/code&gt; has been updated to return the equilibrium value of profits from fish harvests before the adjustment costs have been paid, &lt;code&gt;penalty_free_V&lt;/code&gt;. This containst the values for all possible states, we simply evaluate it at the carrying capacity (which is our initial condition.) The index in &lt;code&gt;x_grid&lt;/code&gt; that corresponds to the carrying capacity (initial condition) &lt;code&gt;i&lt;/code&gt; indicates this.&lt;/p&gt;
&lt;p&gt;Quadratic costs on fishing effort have to be done separately,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;quad &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(c2, function(c2) {
    effort_penalty = function(x, h) &lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt; * c2 * h/x
    policycost &amp;lt;- &lt;span class=&quot;kw&quot;&gt;optim_policy&lt;/span&gt;(SDP_Mat, x_grid, h_grid, OptTime, xT, profit, 
        delta, reward, &lt;span class=&quot;dt&quot;&gt;penalty =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;fixed&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;), effort_penalty)
    i &amp;lt;- &lt;span class=&quot;kw&quot;&gt;which&lt;/span&gt;(x_grid &amp;gt; K)[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]
    &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(policycost$penalty_free_V[i, ])  &lt;span class=&quot;co&quot;&gt;# chooses the most sensible harvest in t=1&lt;/span&gt;
})
dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cbind&lt;/span&gt;(policies, quad)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Tidy up the data and plot the net present value (before the penalty has been paid) relative to that achieved when managed without a penalty.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;npv0 &amp;lt;- dat[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;]
npv0&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;free_decrease 
        709.7 &lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;c2 =&lt;/span&gt; c2, dat)
dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(dat, &lt;span class=&quot;dt&quot;&gt;id =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;c2&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dat, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(c2, value, &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; variable)) + &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;() + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;()&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-11-28-5e6d8d80ac-npv-plot.png&quot; alt=&quot;plot of chunk npv-plot&quot; /&gt;&lt;figcaption&gt;plot of chunk npv-plot&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Find the value of &lt;code&gt;c2&lt;/code&gt; that brings each penalty closest to 75% of the cost-free adjustment value:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dat, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(c2, (npv0 - value)/npv0, &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; variable)) + &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;() + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;()&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-11-28-5e6d8d80ac-apples_plot.png&quot; alt=&quot;plot of chunk apples_plot&quot; /&gt;&lt;figcaption&gt;plot of chunk apples_plot&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;closest &amp;lt;- function(x, v) {
    &lt;span class=&quot;kw&quot;&gt;which.min&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;abs&lt;/span&gt;(v - x))
}
dt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.table&lt;/span&gt;(dat)
index &amp;lt;- dt[, &lt;span class=&quot;kw&quot;&gt;closest&lt;/span&gt;(&lt;span class=&quot;fl&quot;&gt;0.25&lt;/span&gt;, (npv0 - value)/value), by = variable]
apples &amp;lt;- c2[index$V1]
&lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(apples) = index$variable
apples&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;           L2            L1 free_decrease         fixed free_increase 
        1.034         1.724         0.000         8.276         0.000 
         quad 
        1.034 &lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;results&quot;&gt;Results&lt;/h2&gt;
&lt;p&gt;Solve the policy cost for the specified penalty function&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;L2_policy &amp;lt;- &lt;span class=&quot;kw&quot;&gt;optim_policy&lt;/span&gt;(SDP_Mat, x_grid, h_grid, OptTime, xT, profit, delta, 
    reward, &lt;span class=&quot;dt&quot;&gt;penalty =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;L2&lt;/span&gt;(apples[&lt;span class=&quot;st&quot;&gt;&amp;quot;L2&amp;quot;&lt;/span&gt;]))&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;fixed_policy &amp;lt;- &lt;span class=&quot;kw&quot;&gt;optim_policy&lt;/span&gt;(SDP_Mat, x_grid, h_grid, OptTime, xT, profit, delta, 
    reward, &lt;span class=&quot;dt&quot;&gt;penalty =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;fixed&lt;/span&gt;(apples[&lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;]))&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;L1_policy &amp;lt;- &lt;span class=&quot;kw&quot;&gt;optim_policy&lt;/span&gt;(SDP_Mat, x_grid, h_grid, OptTime, xT, profit, delta, 
    reward, &lt;span class=&quot;dt&quot;&gt;penalty =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;L1&lt;/span&gt;(apples[&lt;span class=&quot;st&quot;&gt;&amp;quot;L1&amp;quot;&lt;/span&gt;]))&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;free_increase_policy &amp;lt;- &lt;span class=&quot;kw&quot;&gt;optim_policy&lt;/span&gt;(SDP_Mat, x_grid, h_grid, OptTime, xT, profit, 
    delta, reward, &lt;span class=&quot;dt&quot;&gt;penalty =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;free_increase&lt;/span&gt;(apples[&lt;span class=&quot;st&quot;&gt;&amp;quot;free_increase&amp;quot;&lt;/span&gt;]))&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;free_decrease_policy &amp;lt;- &lt;span class=&quot;kw&quot;&gt;optim_policy&lt;/span&gt;(SDP_Mat, x_grid, h_grid, OptTime, xT, profit, 
    delta, reward, &lt;span class=&quot;dt&quot;&gt;penalty =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;free_decrease&lt;/span&gt;(apples[&lt;span class=&quot;st&quot;&gt;&amp;quot;free_decrease&amp;quot;&lt;/span&gt;]))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We also compare to the case in which costs of harvesting increase quadratically with effort; a common approach to create smoother policies.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;quad_profit &amp;lt;- &lt;span class=&quot;kw&quot;&gt;profit_harvest&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;price =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;c0 =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;30&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;c1 =&lt;/span&gt; apples[&lt;span class=&quot;st&quot;&gt;&amp;quot;quad&amp;quot;&lt;/span&gt;])
quad_costs &amp;lt;- &lt;span class=&quot;kw&quot;&gt;optim_policy&lt;/span&gt;(SDP_Mat, x_grid, h_grid, OptTime, xT, quad_profit, 
    delta, reward, &lt;span class=&quot;dt&quot;&gt;penalty =&lt;/span&gt; none)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;sims &amp;lt;- &lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;L1 =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;simulate_optim&lt;/span&gt;(f, pars, x_grid, h_grid, x0, L1_policy$D, z_g, 
    z_m, z_i, opt$D, &lt;span class=&quot;dt&quot;&gt;profit =&lt;/span&gt; profit, &lt;span class=&quot;dt&quot;&gt;penalty =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;L1&lt;/span&gt;(apples[&lt;span class=&quot;st&quot;&gt;&amp;quot;L1&amp;quot;&lt;/span&gt;]), &lt;span class=&quot;dt&quot;&gt;seed =&lt;/span&gt; seed), 
    &lt;span class=&quot;dt&quot;&gt;L2 =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;simulate_optim&lt;/span&gt;(f, pars, x_grid, h_grid, x0, L2_policy$D, z_g, z_m, 
        z_i, opt$D, &lt;span class=&quot;dt&quot;&gt;profit =&lt;/span&gt; profit, &lt;span class=&quot;dt&quot;&gt;penalty =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;L2&lt;/span&gt;(apples[&lt;span class=&quot;st&quot;&gt;&amp;quot;L2&amp;quot;&lt;/span&gt;]), &lt;span class=&quot;dt&quot;&gt;seed =&lt;/span&gt; seed), 
    &lt;span class=&quot;dt&quot;&gt;fixed =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;simulate_optim&lt;/span&gt;(f, pars, x_grid, h_grid, x0, fixed_policy$D, z_g, 
        z_m, z_i, opt$D, &lt;span class=&quot;dt&quot;&gt;profit =&lt;/span&gt; profit, &lt;span class=&quot;dt&quot;&gt;penalty =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;fixed&lt;/span&gt;(apples[&lt;span class=&quot;st&quot;&gt;&amp;quot;fixed&amp;quot;&lt;/span&gt;]), 
        &lt;span class=&quot;dt&quot;&gt;seed =&lt;/span&gt; seed), &lt;span class=&quot;dt&quot;&gt;increase =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;simulate_optim&lt;/span&gt;(f, pars, x_grid, h_grid, x0, 
        free_increase_policy$D, z_g, z_m, z_i, opt$D, &lt;span class=&quot;dt&quot;&gt;profit =&lt;/span&gt; profit, &lt;span class=&quot;dt&quot;&gt;penalty =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;free_increase&lt;/span&gt;(apples[&lt;span class=&quot;st&quot;&gt;&amp;quot;increase&amp;quot;&lt;/span&gt;]), 
        &lt;span class=&quot;dt&quot;&gt;seed =&lt;/span&gt; seed), &lt;span class=&quot;dt&quot;&gt;decrease =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;simulate_optim&lt;/span&gt;(f, pars, x_grid, h_grid, x0, 
        free_decrease_policy$D, z_g, z_m, z_i, opt$D, &lt;span class=&quot;dt&quot;&gt;profit =&lt;/span&gt; profit, &lt;span class=&quot;dt&quot;&gt;penalty =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;free_decrease&lt;/span&gt;(apples[&lt;span class=&quot;st&quot;&gt;&amp;quot;decrease&amp;quot;&lt;/span&gt;]), 
        &lt;span class=&quot;dt&quot;&gt;seed =&lt;/span&gt; seed), &lt;span class=&quot;dt&quot;&gt;quad =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;simulate_optim&lt;/span&gt;(f, pars, x_grid, h_grid, x0, free_decrease_policy$D, 
        z_g, z_m, z_i, opt$D, &lt;span class=&quot;dt&quot;&gt;profit =&lt;/span&gt; quad_profit, &lt;span class=&quot;dt&quot;&gt;penalty =&lt;/span&gt; none, &lt;span class=&quot;dt&quot;&gt;seed =&lt;/span&gt; seed))&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;co&quot;&gt;# Make data tidy (melt), fast (data.tables), and nicely labeled.&lt;/span&gt;
dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(sims, &lt;span class=&quot;dt&quot;&gt;id =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;names&lt;/span&gt;(sims[[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]]))
dt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.table&lt;/span&gt;(dat)
&lt;span class=&quot;kw&quot;&gt;setnames&lt;/span&gt;(dt, &lt;span class=&quot;st&quot;&gt;&amp;quot;L1&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;penalty_fn&amp;quot;&lt;/span&gt;)  &lt;span class=&quot;co&quot;&gt;# names are nice&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h1 id=&quot;plots&quot;&gt;Plots&lt;/h1&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;p0 &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dt) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, alternate), &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;grey20&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;lwd =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) + 
    &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, fishstock, &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; penalty_fn, &lt;span class=&quot;dt&quot;&gt;lty =&lt;/span&gt; penalty_fn)) + &lt;span class=&quot;kw&quot;&gt;labs&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;time&amp;quot;&lt;/span&gt;, 
    &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;stock size&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;title =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;Stock Dynamics&amp;quot;&lt;/span&gt;)
p0&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-11-28-5e6d8d80ac-p0.png&quot; alt=&quot;plot of chunk p0&quot; /&gt;&lt;figcaption&gt;plot of chunk p0&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;p1 &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dt) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, alternate), &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;grey20&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;lwd =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) + 
    &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, fishstock), &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;rgb&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.8&lt;/span&gt;)) + &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~penalty_fn) + 
    &lt;span class=&quot;kw&quot;&gt;labs&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;time&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;stock size&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;title =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;Stock Dynamics&amp;quot;&lt;/span&gt;)
p1&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-11-28-5e6d8d80ac-p1.png&quot; alt=&quot;plot of chunk p1&quot; /&gt;&lt;figcaption&gt;plot of chunk p1&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;p2 &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dt) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, harvest_alt), &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;grey20&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;lwd =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) + 
    &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, harvest), &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;rgb&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.8&lt;/span&gt;)) + &lt;span class=&quot;kw&quot;&gt;facet_wrap&lt;/span&gt;(~penalty_fn) + 
    &lt;span class=&quot;kw&quot;&gt;labs&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;time&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;havest intensity (fish taken)&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;title =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;Harvest Policy Dynamics&amp;quot;&lt;/span&gt;)
p2&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-11-28-5e6d8d80ac-p2.png&quot; alt=&quot;plot of chunk p2&quot; /&gt;&lt;figcaption&gt;plot of chunk p2&lt;/figcaption&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>Citing Lab Notebook Entries</title>
   <link href="/2012/11/23/citing-lab-notebook-entries.html"/>
   <updated>2012-11-23T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/11/23/citing-lab-notebook-entries</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;C. Titus Brown has an excellent &lt;a href=&quot;http://ivory.idyll.org/blog/posting-blog-entries-to-figshare.html&quot;&gt;post&lt;/a&gt; discussing his exploration into the merits and technicalities cross-posting his blog posts to figshare. The &lt;a href=&quot;https://github.com/ropensci/rfigshare&quot;&gt;&lt;code&gt;rfigshare&lt;/code&gt; package&lt;/a&gt; written by &lt;a href=&quot;http://emhart.github.com/&quot;&gt;Ted Hart&lt;/a&gt; and myself can do just this, once we puzzled out some of the same challenges (Notes to Titus: though the documentation doesn’t mention it, you can get a programmatic list of available categories from &lt;a href=&quot;http://api.figshare.com/v1/categories&quot;&gt;http://api.figshare.com/v1/categories&lt;/a&gt;. Figshare can also take code as a fileset or dataset, and may soon add a type for it. The coolest thing about figshare is perhaps the way they add types in response to how they see users using the service).&lt;/p&gt;
&lt;p&gt;The real discussion, though, is not about &lt;em&gt;how&lt;/em&gt;, but &lt;em&gt;why&lt;/em&gt;? Currently figshare doesn’t render the html or markdown/restructured-text source (other than as plain text), so it’s not a great place to &lt;em&gt;read&lt;/em&gt; the posts. This may change in the near future as well, but the primary motivation for doing this seems to be on the ability to get an honest-to-goodness DOI for your entry. So why a DOI?&lt;/p&gt;
&lt;p&gt;The answer most often put forward is that “a DOI facilitates citing a paper in the formal literature.” I think that’s not entirely accurate. For one, the formal literature has no trouble citing things that do not have a DOI. Perhaps the answer is meant to mean track citations to my content, &lt;em&gt;e.g.&lt;/em&gt; for statistical/impact purposes. This may be closer to the mark, but it still needs work. What counts depends on whose doing the counting. Anyone browsing the citation counts of a work through different mediums has surely encountered Thompson-Reuters has very specific criteria to be included, so I don’t believe they are tracking citations to anything with a DOI. Nor, I think is Scopus. Perhaps the target is Google then?&lt;/p&gt;
&lt;p&gt;If you want Google Scholar to count the number of citations to your blog post, I have good news for you. You do not need a DOI and cross-posting to figshare. You just need to follow the &lt;a href=&quot;http://scholar.google.com/intl/en/scholar/inclusion.html#indexing&quot;&gt;metadata requirements&lt;/a&gt; as outlined by Google Scholar itself. This will help Google Scholar identify your blog post as a academic object, and add it to your profile. Anything indexed by Google scholar that cites your blog post will count as a reference. The basics are really simple. Have metadata such as:&lt;/p&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;resource_type&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;Lab Notebook&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;citation_journal_title&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;Lab Notebook&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;citation_publication_date&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;2012-11-23 00:00:00 -0800&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;citation_date&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;2012-11-23 00:00:00 -0800&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;citation_author&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;Carl Boettiger&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;citation_title&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;Citing Lab Notebook Entries&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Just replace &lt;code&gt;Lab Notebook&lt;/code&gt; etc. with the correct values for your site. The example above will do so automatically if you use Jekyll using information specified in the YAML header. It seems the entry also needs a section called either “References” or “Bibliography” followed by a list of references. Not sure what format Google Scholar will do best at disambiguating. (Note that what I refer to as “Google Scholar” metadata looks like it was originally the convention adopted by HireWire Press.)&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.russet.org.uk&quot;&gt;Phil Lord&lt;/a&gt; and colleagues have written the fantastic API called &lt;a href=&quot;http://knowledgeblog.org/greycite&quot;&gt;greycite&lt;/a&gt; [Lord 2012], which can be used to generate citation data from any website that has semantic markup (including HTML5 semantics, also Dublin Core or OpenGraph ontologies and Google Scholar metadata). The API can return citations formatted in bibtex or JSON. Try it out at &lt;a href=&quot;http://greycite.knowledgeblog.org&quot;&gt;greycite.knowledgeblog.org&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now there is another reason to use DOIs and figshare, which is, I think, entirely independent – archival preservation (decoupled journal, anyone?). DOIs are potentially more permanent than URLs (though I’ll leave that debate to the experts). Figshare content is backed up by &lt;a href=&quot;http://clockss.org/&quot;&gt;CLOCKSS&lt;/a&gt;. Forever is a long time, but this certainly sounds like a better archiving strategy. Figshare should be providing the necessary Google Scholar metadata on each object now. My current practice has been to archive my notebook in annual chunks on figshare (posting entries individually feels fragmented and cluttered to me), and rely on the more native web solution of HTML metadata to allow my entries to “citable”. Perhaps this is not ideal, but for the short term, the content is discoverable and citable via Google Scholar, which points to my address. If my site vanishes from the web, one might hope that an academic search for my lab notebook might recover the content from the archived version.&lt;/p&gt;
&lt;h2 id=&quot;edit-thoughts-examples-and-disclaimer&quot;&gt;Edit: thoughts, examples and disclaimer&lt;/h2&gt;
&lt;p&gt;I stumbled across Google’s indexing of some of my lab notebook entries somewhat by accident. For instance, one of my &lt;a href=&quot;http://www.carlboettiger.info/2011/10/28/optimal-control-examples-continued-bellman-dynamic-programming.html&quot;&gt;entries&lt;/a&gt; on optimal control in which I had listed some references started turning up &lt;a href=&quot;http://scholar.google.com/citations?view_op=view_citation&amp;amp;hl=en&amp;amp;user=zj2rRtEAAAAJ&amp;amp;citation_for_view=zj2rRtEAAAAJ:4TOpqqG69KYC&quot;&gt;in Google Scholar&lt;/a&gt; Being able to engage in a scholarly exchange through blogs that can cite and be cited by the formal literature certainly sounds like an important step forward in generating new publishing models. Of course it is also obvious that the procedure I have outlined could be trivially exploited for some rather blatant gaming of Google Scholar’s citation statistics. This post certainly is not an endorsement of gaming such statistics. If nothing else, perhaps this once again underscores the weakness of reliance on metrics of quantity when trying to infer quality. Will we ever let go of that fallacy?&lt;/p&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;Titus Brown (2012) Posting blog entries to figshare, Living in an Ivory Basement. http://ivory.idyll.org/blog/posting-blog-entries-to-figshare.html&lt;/li&gt;
&lt;li&gt;Phillip Lord (2012) Greycite. Knowledge Blog. http://knowledgeblog.org/greycite&lt;/li&gt;
&lt;li&gt;Carl Boettiger (2011) Optimal Control examples continued: Bellman, Dynamic Programming, Lab Notebook http://www.carlboettiger.info/2011/10/28/optimal-control-examples-continued-bellman-dynamic-programming.html&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/11/22/notes.html"/>
   <updated>2012-11-22T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/11/22/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;multiple-uncertainty&quot;&gt;multiple-uncertainty&lt;/h2&gt;
&lt;p&gt;Working out the multiple uncertainty computational performance and noise forms. Fixing a few things in the way log-normal noise was calculated. Uniform noise in particular can still give rather non-smooth policy, needs a bit of digging. Uniform noise doesn’t show the non-monotonicity of the log-normal noise in measurement uncertainty though.&lt;/p&gt;
&lt;h2 id=&quot;uniform&quot;&gt;Uniform&lt;/h2&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-11-23-bcf87363db-policyfunctions.png&quot; alt=&quot;uniform noise policy functions&quot; /&gt;&lt;figcaption&gt;uniform noise policy functions&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;lognormal&quot;&gt;lognormal&lt;/h2&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-11-22-11f7d70977-policyfunctions.png&quot; alt=&quot;log-normal noise policy functions&quot; /&gt;&lt;figcaption&gt;log-normal noise policy functions&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h3 id=&quot;log&quot;&gt;log&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;A few small tweaks to probability calculations&lt;/li&gt;
&lt;/ul&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;Handle the case of mu = grid zero, not just exactly zero, to avoid introducing NAs&lt;/li&gt;
&lt;li&gt;Calculate dlnorm as &lt;code&gt;(x_grid/mu, 0, sigma)&lt;/code&gt;, rather than as &lt;code&gt;(x_grid, mu, sigma)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Transpose of measurement error in &lt;code&gt;M %*% F&lt;/code&gt;. Because now we want to treat x as given, integrate over range of y? (no, probably not?)&lt;/li&gt;
&lt;li&gt;standardize noise level between old and g &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/0f7889f9ce483735228e708b1f0770f295343d1d&quot;&gt;12:52 pm 2012/11/22&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;With transposed M time F. (include image) &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/e277e624334e7f6d2e3367676b032cac3eea26c2&quot;&gt;01:04 pm 2012/11/22&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And now without transpose, M %*% F &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/11f7d709775769c6f1cb1dca38b73d0b3b395742&quot;&gt;01:07 pm 2012/11/22&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Larger (log-normal in all variables) noise, weirder results. &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/ae6f7ff220a566c76330b8204529f3a5ec8aea8c&quot;&gt;01:39 pm 2012/11/22&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;Changes improving performance of F calculation (rate-limiting step)&lt;/li&gt;
&lt;/ul&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li&gt;vectorized calculation of mu.&lt;/li&gt;
&lt;li&gt;matrix-based calc of deterministic part of growth rate &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/d5f2509c5341dc3be2706dd42caaa7642ec6e782&quot;&gt;02:13 pm 2012/11/22&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Another efficiency change. Not identical but appears to be a decent approximation: Snap mu to the x_grid, and look up the pdfn value rather than calculating it each time in F. &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/f151258fe146199dd34cc0194fea55515e3f8716&quot;&gt;03:00 pm 2012/11/22&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now pretty efficient. Matrix multiplication is dominant time sink, followed by the applys. &lt;code&gt;snap_to_grid&lt;/code&gt; is probably the slowest functional contribution.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/11/21/notes.html"/>
   <updated>2012-11-21T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/11/21/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;ul&gt;
&lt;li&gt;writing comment piece. writing writing writing.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;also-today-misc&quot;&gt;Also today (misc):&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Check in with Peter re: Labrids paper&lt;/li&gt;
&lt;li&gt;Fix issue #32 rfigshare&lt;/li&gt;
&lt;li&gt;Follow up with Nina about improved FishBase API&lt;/li&gt;
&lt;li&gt;pay ESA and SSE dues&lt;/li&gt;
&lt;li&gt;Santa Cruz SOE email lists&lt;/li&gt;
&lt;li&gt;uniform growth noise version on corrected multiple-uncertainty run&lt;/li&gt;
&lt;li&gt;transparent plots in new ggplot theme? Set in &lt;code&gt;dev.args=list(bg=&amp;quot;transparent&amp;quot;)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Consider SOE AMS lecturer pool? &lt;a href=&quot;http://apo.ucsc.edu/academic_employment/jobs/T02-01rev2011.pdf&quot;&gt;Description&lt;/a&gt;, &lt;a href=&quot;https://intranet.soe.ucsc.edu/employment/application/lecturer&quot;&gt;Application&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;CV, Letter of application with course list.&lt;/li&gt;
&lt;li&gt;Optional: Teaching evaluations. Sample course material.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;multiple-uncertainty&quot;&gt;multiple uncertainty&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Whoops, not preventing negative harvest values can lead to some weird results. &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/c5e857ebeab2f73eff9afaf6d56d0e5dabd81e14&quot;&gt;06:16 pm 2012/11/21&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;numerical instabilities in uniform noise case? &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/9dc17dc56494b9e2f998e3992e4c891573d80570&quot;&gt;04:01 pm 2012/11/21&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;notes on policycost manuscript &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/81df88cc50ac0c7c2448e55b42dc2bfe8fd15299&quot;&gt;01:34 pm 2012/11/21&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Sequential Updating</title>
   <link href="/2012/11/19/sequential-updating.html"/>
   <updated>2012-11-19T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/11/19/sequential-updating</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Fixed the sequential updating algorithm (avoids numerical instabilities associated with matrix inversion). Currently defined as the function recursion:&lt;/p&gt;
&lt;p&gt;for the covariance:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;C_seq &amp;lt;- function(X, X_prime, i){
    if(i &amp;lt;= &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)
          &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(X, X_prime) - &lt;span class=&quot;kw&quot;&gt;mmult&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(X,x[i]), &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x[i], X_prime)) / &lt;span class=&quot;kw&quot;&gt;as.numeric&lt;/span&gt;( &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x[i], x[i]) + sigma_n^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)
            else
                  &lt;span class=&quot;kw&quot;&gt;C_seq&lt;/span&gt;(X, X_prime,   i&lt;span class=&quot;dv&quot;&gt;-1&lt;/span&gt;) - &lt;span class=&quot;kw&quot;&gt;mmult&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;C_seq&lt;/span&gt;(X,x[i],   i&lt;span class=&quot;dv&quot;&gt;-1&lt;/span&gt;), &lt;span class=&quot;kw&quot;&gt;C_seq&lt;/span&gt;(x[i], X_prime,   i&lt;span class=&quot;dv&quot;&gt;-1&lt;/span&gt;)) / &lt;span class=&quot;kw&quot;&gt;as.numeric&lt;/span&gt;( &lt;span class=&quot;kw&quot;&gt;C_seq&lt;/span&gt;(x[i], x[i],   i&lt;span class=&quot;dv&quot;&gt;-1&lt;/span&gt;)  + sigma_n^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;  )
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;for the mean:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;mu_seq &amp;lt;- function(X, i){
    if(i &amp;lt;= &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)
          &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x[i], X) * (y[i]-mu[i]) / &lt;span class=&quot;kw&quot;&gt;as.numeric&lt;/span&gt;( &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x[i], x[i]) + sigma_n^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)
            else
                  &lt;span class=&quot;kw&quot;&gt;mu_seq&lt;/span&gt;(X, i&lt;span class=&quot;dv&quot;&gt;-1&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;C_seq&lt;/span&gt;(x[i], X,  i&lt;span class=&quot;dv&quot;&gt;-1&lt;/span&gt;) * (y[i]-mu[i]) / &lt;span class=&quot;kw&quot;&gt;as.numeric&lt;/span&gt;( &lt;span class=&quot;kw&quot;&gt;C_seq&lt;/span&gt;(x[i], x[i], i&lt;span class=&quot;dv&quot;&gt;-1&lt;/span&gt;)  + sigma_n^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; )
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that this needed a custom matrix multiplication to handle scalar by vector cases:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;mmult &amp;lt;- function(x,y){
  if(&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(x) == &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;){
    x &amp;lt;- &lt;span class=&quot;kw&quot;&gt;as.numeric&lt;/span&gt;(x) 
    x * y
  } else if(&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(y) == &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;){ 
    y &amp;lt;- &lt;span class=&quot;kw&quot;&gt;as.numeric&lt;/span&gt;(y)
    x * y
  }  else 
  x %*% y
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And probably needs to be written in C at least to have any hope of scaling. See implementation in &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/e19802885c6ddf2a30807e6b3addf2b9fa3e2ff0/inst/examples/sequential-method.md&quot;&gt;sequential-method&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Match is perfect (jittered to avoid overplotting the lazy way):&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-11-19-58073767b5-unnamed-chunk-6.png&quot; alt=&quot;Sequential vs direct calculation of the mean&quot; /&gt;&lt;figcaption&gt;Sequential vs direct calculation of the mean&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Now should rewrite to use a grid for the covariance matrices of each data point. Memory intensive but should be much faster than function recursion.&lt;/p&gt;
&lt;p&gt;(Should also confirm variance calculation in comparison, and test on larger grid sizes)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Multiple uncertainty corrected</title>
   <link href="/2012/11/16/mult-uncertainty.html"/>
   <updated>2012-11-16T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/11/16/mult-uncertainty</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Fixed the &lt;a href=&quot;http://www.carlboettiger.info/2012/11/01/multiple-uncertainty-corrections.html&quot;&gt;multiple uncertainty calculation&lt;/a&gt; implementation. Code had transposed &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbb{I}\inline&quot;/&gt;&lt;/span&gt;, also one of the &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbb{M}\inline&quot;/&gt;&lt;/span&gt; matrices. Should still confirm final implementation. In the below example each case has log-normal growth noise present. The non-monotonic section of the measurement uncertainty&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-11-17-f6c225f69f-policyfunctions.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/954cea9310063150bb42567b19caa272b34d32c2&quot;&gt;See notes on code changes inline.&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;additional-notes-from-walking-through-algoritm-step-by-step.&quot;&gt;Additional notes from walking through algoritm step by step.&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt; index in the true state space&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt; index in the observed state space&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt; index in the true action&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q\inline&quot;/&gt;&lt;/span&gt; index in the policy/decision space&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?V[y,q]\inline&quot;/&gt;&lt;/span&gt; the Expected value of policy &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q\inline&quot;/&gt;&lt;/span&gt; and observed state &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\Pi[x,h]\inline&quot;/&gt;&lt;/span&gt; the profit of a harvest of &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt; given a true stock of &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?M[y,x]\inline&quot;/&gt;&lt;/span&gt; is the probability of a true state &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt; given an observed stock &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt;. (How does this relate to the probability the observed stock is &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt; given the true stock is &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt;? Should be the transpose? Is &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?M\inline&quot;/&gt;&lt;/span&gt; symmetric?)&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?I[h,q]\inline&quot;/&gt;&lt;/span&gt; is the probability of implementing a harvest &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt;, given a quota set to &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q\inline&quot;/&gt;&lt;/span&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?Q[y,q]\inline&quot;/&gt;&lt;/span&gt; the Expected profit from a policy &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q\inline&quot;/&gt;&lt;/span&gt; and observed state &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt;. In Einstein summation, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?Q[y_k,q_l] = M[y_k, x_i] \Pi[x_i,h_j] I[h_j, q_l]\inline&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?M(y_1, x_1) (\Pi(x_1,h_1)I(h_1, q_1) + \Pi(x_1,h_2)I(h_2, q_1) + \dots) +  M(y_1, x_2) (\Pi(x_2,h_1)I(h_1, q_1) + \Pi(x_2,h_2)I(h_2, q_1) + \dots)  +\dots&quot; alt=&quot;M(y_1, x_1) (\Pi(x_1,h_1)I(h_1, q_1) + \Pi(x_1,h_2)I(h_2, q_1) + \dots) +  M(y_1, x_2) (\Pi(x_2,h_1)I(h_1, q_1) + \Pi(x_2,h_2)I(h_2, q_1) + \dots)  +\dots&quot; /&gt;&lt;/div&gt;&lt;/span&gt; - &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?[\tilde{y}_t, y_k, q_l] = M[\tilde{y}_t, \tilde{x}_s] M[y_k, x_i] f[\tilde{x}_s, x_i, h_j] I[h_j, q_l]\inline&quot;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;misc&quot;&gt;Misc&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://flowingdata.com/2010/01/21/how-to-make-a-heatmap-a-quick-and-easy-solution/&quot;&gt;heatmap&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://learnr.wordpress.com/2010/01/26/ggplot2-quick-heatmap-plotting/&quot;&gt;ggplot version&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/11/15/notes.html"/>
   <updated>2012-11-15T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/11/15/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;stuck-on-many-things&quot;&gt;Stuck on many things&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Have not correctly defined the recursion in the sequential updating approach. Can I really calculate &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?P(y_3 | (y2 | y_1))\inline&quot;/&gt;&lt;/span&gt; in place of &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?P(y_3 | y2, y1)\inline&quot;/&gt;&lt;/span&gt;? e.g. instead of calculating:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?V_3 = K(y_3, y_3) - K(y_{1:2}, y_3) K(y_{1:2}, y_{1:2})^{-1} ) K(y_3, y_{1:2})&quot; alt=&quot;V_3 = K(y_3, y_3) - K(y_{1:2}, y_3) K(y_{1:2}, y_{1:2})^{-1} ) K(y_3, y_{1:2})&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Is there some scalar &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?v_2\inline&quot;/&gt;&lt;/span&gt; such that&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?V_3 = K(y_3, y_3) - K(y_{1:2}, y_3) K(y_3, y_{1:2}) / v_2&quot; alt=&quot;V_3 = K(y_3, y_3) - K(y_{1:2}, y_3) K(y_3, y_{1:2}) / v_2&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;e.g. a term like:&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?V_2 = K(y_2, y_2) - K(y_1, y_2) K(y_1, y_1)^{-1} ) K(y_2, y_1)&quot; alt=&quot;V_2 = K(y_2, y_2) - K(y_1, y_2) K(y_1, y_1)^{-1} ) K(y_2, y_1)&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;and a similar recursion for the mean?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Cannot get posterior covariance matrix from kernlab’s &lt;code&gt;gausspr&lt;/code&gt;. Can this be reconstructed from &lt;code&gt;alpha&lt;/code&gt;? (&lt;a href=&quot;http://stats.stackexchange.com/questions/43713/how-do-i-access-or-compute-the-posterior-covariance-matrix-returned-by-kernlab&quot;&gt;question posted to cross-validated&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Likelihood optimization does not handle the noise term. Examples in Rasmussen and Wiliams suggest this should work. (See commit log below)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;nonparametric-bayes-log&quot;&gt;nonparametric-bayes log&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;re-run example with updated plots, but otherwise as before. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/73396d797b8398f25dcfe8307befafb7546c1097&quot;&gt;07:40 pm 2012/11/15&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Question on how to get the covariance matrix back from the kernlab gausspr method. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/80fcefbc391e5d75fa63300f95e60c98af7bcb2c&quot;&gt;07:39 pm 2012/11/15&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Attempted to fix the sequential method example.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Still incorrect. See sequential-method.Rmd &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/01307f5c36060a07fdbb9f3ba6b83b8660f88103&quot;&gt;07:37 pm 2012/11/15&lt;/a&gt; - Attempting to write the sequential method algorithm.&lt;/p&gt;
&lt;p&gt;Not correct at the moment, need to understand the recursion properly. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/e732f74985def53677478f6f0e10e8f931201252&quot;&gt;07:36 pm 2012/11/15&lt;/a&gt; - Stick with direct method.&lt;/p&gt;
&lt;p&gt;Current version of sequential method is not correct. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/14821223d59b6f68e9e0b6f962476b8c5119e2ce&quot;&gt;07:34 pm 2012/11/15&lt;/a&gt; - Updated hyperparameter-optimization example&lt;/p&gt;
&lt;p&gt;Shows that we can estimate l appropriately but fails to get sigma_n; instead estimating the upper boundary. &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/c28d09929f3765fff8a7b82e2d9b84d2f9cc8fa6&quot;&gt;07:32 pm 2012/11/15&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Better Tagging Practices</title>
   <link href="/2012/11/09/better-tagging-practices.html"/>
   <updated>2012-11-09T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/11/09/better-tagging-practices</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;h2 id=&quot;better-tagging-practices&quot;&gt;Better tagging practices&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Standardize use of tags: Match tags in notebook to project repository name. Tag papers in Mendeley by these tags as well.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I have also started tracking the medium of discovery for each paper I add to my Mendeley collection through a little set of Mendeley tags. I am curious to see through which mediums I obtain the most content, and what content. As with any ontology, I will struggle to select a vocabulary that is precise enought to be useful without being too verbose (b) to bother to continue to use this. We’ll see how I do.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr class=&quot;header&quot;&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;tag&lt;/th&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;source:reader&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Google Reader (RSS feed)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;source:twitter&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Mentioned on twitter stream (or G+ stream)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;source:search&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Searched for this article directly or by some keyword&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;source:bibliography&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;In the reference list of something I’m reading&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;source:conference&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Discussed at a conference&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;source:blog&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Mentioned in a blog I read&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;source:human&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Directly recommended to me (in person or email, from reviewer, adviser, etc)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;source:journal-club&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Something we read in a journal club&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;source:wikipedia&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Cited in a wikipedia article I read&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/11/08/notes.html"/>
   <updated>2012-11-08T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/11/08/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;ul&gt;
&lt;li&gt;Complete IACUC training for fish room. File forms: http://ehs.ucsc.edu/programs/research-safety/animal-research/index.html&lt;/li&gt;
&lt;li&gt;Online training – possibly see https://www.citiprogram.org/Default.asp?&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shiny: http://www.rstudio.com/shiny/&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;Comment piece&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Prep exit seminar&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Applied math club: Networks. Reading http://dx.doi.org/10.1155/2011/284909&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Discussion of when network structure has made an important difference on our understanding of a problem. When have the common summary statistics of a network (degree-distribution) allowed us to compte network dynamics without fully resolving the network?&lt;/p&gt;
&lt;h2 id=&quot;nonparametric-bayes&quot;&gt;nonparametric-bayes&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/5e4df576d70358b8049d6ee412f45de17a20cd38/inst/examples/testing-gp-sdp.md&quot;&gt;Comparing methods for Gaussian process fits&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;mlegp package appears more carefully constructed, but notation is terrible. Also unclear how to change covariance kernel. Example shows fitting with zero noise only, though somehow that should be adjusted (in the nugget parameters?). Has a vignette but it has not been particularly enlightening for me. Seems &lt;code&gt;kernlab::gausspr&lt;/code&gt; may be the only intelligent package function for GP I’ve seen.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;What explains the descrepancy in the Cholesky approach?&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What explains the descrepancy in the sequential approach?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Sequential updating algorithm avoids inverting the matrix, which can become unstable as state space becomes large. Instead of dealing with the vector of observations &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\vec y\inline&quot;/&gt;&lt;/span&gt; at states &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\vec x\inline&quot;/&gt;&lt;/span&gt; simultaneously, we update the GP mean &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?m_i\inline&quot;/&gt;&lt;/span&gt; and covariance &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?c_i\inline&quot;/&gt;&lt;/span&gt; at each observed point &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?(x_i, y_i)\inline&quot;/&gt;&lt;/span&gt; sequentially. Because we can compute this over the desired prediction grid &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?X\inline&quot;/&gt;&lt;/span&gt; simultaneously still, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?m_i\inline&quot;/&gt;&lt;/span&gt; is a vector of the same length as the prediction grid (&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_x\inline&quot;/&gt;&lt;/span&gt;), and the &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?c_i\inline&quot;/&gt;&lt;/span&gt; is a matrix of dimension &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_x\inline&quot;/&gt;&lt;/span&gt; by &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_x\inline&quot;/&gt;&lt;/span&gt;. Let &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?K(x_i, x_j)\inline&quot;/&gt;&lt;/span&gt; be the covariance function of &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_i, x_j\inline&quot;/&gt;&lt;/span&gt;, and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y = \mathcal{N(m, c)} + \sigma_n^2 \mathbb{I}\inline&quot;/&gt;&lt;/span&gt; be the noise model of the GP, then&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?m_{i+1} = m_i + \frac{K(X, x_i) y_i}{ K(x_i,x_i)+\sigma_n^2}&quot; alt=&quot;m_{i+1} = m_i + \frac{K(X, x_i) y_i}{ K(x_i,x_i)+\sigma_n^2}&quot; /&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?c_{i+1} = c_i + K(X, X) - \frac{K(X, x_i) K(x_i, X)}{K(x_i,x_i)+\sigma_n^2}&quot; alt=&quot;c_{i+1} = c_i + K(X, X) - \frac{K(X, x_i) K(x_i, X)}{K(x_i,x_i)+\sigma_n^2}&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Work out the multi-dimensional Gaussian process algorithm&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;multiple-uncertainty&quot;&gt;Multiple uncertainty&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Verify orientation of each matrix?&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/blob/a4d9af4260dd5bebf61d2cd57672338daaa2a235/inst/examples/mult_uncertainty_test.md&quot;&gt;higher resolution grid example (same problem)&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/11/06/notes.html"/>
   <updated>2012-11-06T00:00:00-08:00</updated>
   <id>http://www.carlboettiger.info/2012/11/06/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;monday&quot;&gt;Monday&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;altmetrics post&lt;/li&gt;
&lt;li&gt;post for multiple uncertainty, email to Steve, Marc&lt;/li&gt;
&lt;li&gt;Marc meeting&lt;/li&gt;
&lt;li&gt;ropensci proposals&lt;/li&gt;
&lt;li&gt;Phylotastic&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;notebook-configuration&quot;&gt;Notebook configuration&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;trying out http://greycite.knowledgeblog.org/. Add to knitcitations.&lt;/li&gt;
&lt;li&gt;Add Greycite recommended opengraph and google scholar metadata &lt;a href=&quot;https://github.com/cboettig/labnotebook/blob/3a977cca64b852574f16ca63fe66308d4af6b2ed/_includes/metadata.html&quot;&gt;metadata.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Import metadata from &lt;code&gt;_config.yml&lt;/code&gt;. Any custom variable defined in config can be accessed at &lt;code&gt;site.varname&lt;/code&gt;. See updated &lt;a href=&quot;https://github.com/cboettig/labnotebook/blob/b0749aac9dec7fbe08af3768e29b24724d378763/_config.yml&quot;&gt;&lt;code&gt;_config.yml&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;reading&quot;&gt;Reading&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Schnitzler, J., Graham, C. H., Dormann, C. F., Schiffers, K., &amp;amp; Peter Linder, H. (2012). Climatic niche evolution and species diversification in the Cape flora, South Africa. (S. Higgins, Ed.)Journal of Biogeography, n/a–n/a. doi:10.1111/jbi.12028&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Clark, T., Dale, R., Waard, A. D., Herman, I., Hovy, E. H., Shotton, D., Birukou, A., et al. (2012). Force11 White Paper : Improving The Future of Research Communications and e-Scholarship, 11.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shotton, D. (2009). Semantic publishing: the coming revolution in scientific journal publishing. Learned Publishing, 22(2), 85–94. doi:10.1087/2009202&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shotton, D. (2011). The Five Stars of Online Journal Articles–an article evaluation framework. Nature Preceedings. doi:10101/npre.2011.6542.1&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;tuesday&quot;&gt;Tuesday&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;FishBase paper is out&lt;/li&gt;
&lt;li&gt;Dissertation on FigShare&lt;/li&gt;
&lt;li&gt;Updated &lt;a href=&quot;http://www.carlboettiger.info/assets/data&quot;&gt;geospatial life history data list&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;reading-1&quot;&gt;Reading&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Allesina, S. (2012). Modeling peer review: an agent-based approach. Ideas in Ecology and Evolution, 5(2), 27–35. doi:10.4033/iee.2012.5b.8.f&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Costello, C., Ovando, D., Hilborn, R., Gaines, S. D., Deschenes, O., &amp;amp; Lester, S. E. (2012). Status and solutions for the world’s unassessed fisheries. Science (New York, N.Y.), 338(6106), 517–20. doi:10.1126/science.1223389&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Palumbo, M. J., Johnson, S. A., Mundim, F. M., Lau, A., Wolf, A. C., Arunachalam, S., Gonzalez, O., et al. (2012). Harnessing Smartphones for Ecological Education, Research, and Outreach. Bulletin of the Ecological Society of America, 93(4), 390–393. doi:10.1890/0012-9623-93.4.390&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sibert, J., Senina, I., Lehodey, P., &amp;amp; Hampton, J. (2012). Shifting from marine reserves to maritime zoning for conservation of Pacific bigeye tuna (Thunnus obesus). Proceedings of the National Academy of Sciences of the United States of America, 109(44), 1–5. doi:10.1073/pnas.1209468109&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Altmetrics Conference</title>
   <link href="/2012/11/03/altmetrics-conference.html"/>
   <updated>2012-11-03T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/11/03/altmetrics-conference</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;From Thursday Nov 1 through Saturday Nov 3 I attended the PLoS Altmetrics workshop as a member of the ROpensci project. An exciting meeting driven mostly by the opportunity to interact with a small and incredibly creative and innovative group of science publishers, funders, start-ups, and other researchers. Details of the event are largely recorded on the &lt;a href=&quot;https://sites.google.com/site/altmetricsworkshop&quot;&gt;altmetrics 2012 workshop website&lt;/a&gt;. We also have a few slides addressing the &lt;a href=&quot;http://ropensci.org/alm/&quot;&gt;ropensci slant&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The workshop followed up with a hackathon which produced prototypes of several ideas. I worked in the &lt;a href=&quot;https://github.com/karthikram/almviz&quot;&gt;altviz&lt;/a&gt; team. Also completed the first release of &lt;a href=&quot;https://github.com/ropensci/rfigshare&quot;&gt;rfigshare&lt;/a&gt; to &lt;a href=&quot;http://cran.at.r-project.org/web/packages/rfigshare/&quot;&gt;CRAN&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Another side goal of the conference for me was to discuss some of the ideas that had arisen in the BeyondThePDF workshop over a year ago in regards to semantic markup, an idea I’ve recently explored in this notebook. To this end it was useful talking with Martin Fenner, Paul Groth, and John Kunze about semantic issues, implicit/inferred semantics vs explicit markup, etc. Also some progress in incorporating these ideas into &lt;a href=&quot;://github.com/cboettig/knitcitations&quot;&gt;knitcitations&lt;/a&gt;. For more in this space, see the &lt;a href=&quot;http://force11.org/white_paper&quot;&gt;Force11 project&lt;/a&gt; (successor/outcoem of the BeyondThePDF).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Multiple Uncertainty Corrections</title>
   <link href="/2012/11/01/multiple-uncertainty-corrections.html"/>
   <updated>2012-11-01T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/11/01/multiple-uncertainty-corrections</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Consider a stock &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_t\inline&quot;/&gt;&lt;/span&gt; at time &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?t\inline&quot;/&gt;&lt;/span&gt; that recruits stochastically following harvest &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h_t\inline&quot;/&gt;&lt;/span&gt; from the escaped population (&lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?s_t := x_t - h_t\inline&quot;/&gt;&lt;/span&gt;), &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_{t+1} = z_g f(s_t)\inline&quot;/&gt;&lt;/span&gt;, where &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?z_g\inline&quot;/&gt;&lt;/span&gt; is a multiplicative stochastic shock to the growth. We imagine the decision maker sets a policy determining the harvest quota &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q_t\inline&quot;/&gt;&lt;/span&gt; each year, which is implemented as the real harvest with some error &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?z_i\inline&quot;/&gt;&lt;/span&gt;, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h_t = z_i q_t\inline&quot;/&gt;&lt;/span&gt;. Before setting a quota, the decision maker assesses the stock &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y_t = z_m x_t\inline&quot;/&gt;&lt;/span&gt;, so &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt; is a noisy measurement of the true stock &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt;. The decision maker seeks to maximize the expected present-value of profits &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\Pi(x_t,h_t)\inline&quot;/&gt;&lt;/span&gt; that are a function of both the actual stock &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt; and the realized harvest &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt; over some long term period &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?T_{\textrm{max}}\inline&quot;/&gt;&lt;/span&gt; subject to some discount rate &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\delta\inline&quot;/&gt;&lt;/span&gt;,&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?max_{\{q_1 \ldots q_{t_{\textrm{max}}} \}} \sum_{t=1}^{t=t_{\textrm{max}}} \operatorname{E}\left( \Pi(x_t,h_t) \right)&quot; alt=&quot;max_{\{q_1 \ldots q_{t_{\textrm{max}}} \}} \sum_{t=1}^{t=t_{\textrm{max}}} \operatorname{E}\left( \Pi(x_t,h_t) \right)&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;discrete-formulation&quot;&gt;Discrete formulation&lt;/h2&gt;
&lt;p&gt;We consider this problem in a discrete state space where &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt; and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt;, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q\inline&quot;/&gt;&lt;/span&gt; and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt; all take values on grids of &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_y\inline&quot;/&gt;&lt;/span&gt;, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_x\inline&quot;/&gt;&lt;/span&gt;, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_q\inline&quot;/&gt;&lt;/span&gt;, and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_h\inline&quot;/&gt;&lt;/span&gt; points respectively.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Let &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbf{P}\inline&quot;/&gt;&lt;/span&gt; be the &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_x\inline&quot;/&gt;&lt;/span&gt; by &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_h\inline&quot;/&gt;&lt;/span&gt; matrix of all possible profits in a time step, as given by &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\Pi(x_i, h_j)\inline&quot;/&gt;&lt;/span&gt;, where rows represent possible stock sizes and columns possible harvests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Let &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbf{M}\inline&quot;/&gt;&lt;/span&gt; be the row-normalized &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_y\inline&quot;/&gt;&lt;/span&gt; by &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_x\inline&quot;/&gt;&lt;/span&gt; matrix whose elements are &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?z_m(y_i, x_j)\inline&quot;/&gt;&lt;/span&gt;, the probability of observing a stock size &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y_i\inline&quot;/&gt;&lt;/span&gt; from a true size &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_j\inline&quot;/&gt;&lt;/span&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Let &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbf{I}\inline&quot;/&gt;&lt;/span&gt; be the row-normalized &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_h\inline&quot;/&gt;&lt;/span&gt; by &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_q\inline&quot;/&gt;&lt;/span&gt; matrix whose elements are &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?z_i(h_i, q_j)\inline&quot;/&gt;&lt;/span&gt;, the probability of implementing a harvest &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h_i\inline&quot;/&gt;&lt;/span&gt; given a quota &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q_j\inline&quot;/&gt;&lt;/span&gt; &lt;strong&gt;Edit&lt;/strong&gt;: I had been created in the code as &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_q\inline&quot;/&gt;&lt;/span&gt; by &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_h\inline&quot;/&gt;&lt;/span&gt;, so had to be transposed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Let &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbf{F}_q\inline&quot;/&gt;&lt;/span&gt; be the tensor of row-normalized &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_q\inline&quot;/&gt;&lt;/span&gt; &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_x\inline&quot;/&gt;&lt;/span&gt; by &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_x\inline&quot;/&gt;&lt;/span&gt; transition matrices given by &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?z_g(x_j,  \sum_i \sum_j f(x_i, h_j) \mathbf{M}[y_k, x_i] \mathbf{I}[h_j, q_l] )\inline&quot;/&gt;&lt;/span&gt;. By summing over the uncertainty in measurement and implementation, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbf{F}_q\inline&quot;/&gt;&lt;/span&gt; is in the space of observed state &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y_t\inline&quot;/&gt;&lt;/span&gt; into the true stock at the next timestep &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_{t+1}\inline&quot;/&gt;&lt;/span&gt;, given quota &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q\inline&quot;/&gt;&lt;/span&gt;. We transfer into the future measured state through another application of &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbf{M} \mathbf{F}_q\inline&quot;/&gt;&lt;/span&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The profits expected given a measurement of the stock &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt; for a quota &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q\inline&quot;/&gt;&lt;/span&gt; are &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\sum_j \sum_i \Pi(x_i, h_j) p(x_i | y) p(h_j | q)\inline&quot;/&gt;&lt;/span&gt;. Hence the matrix of expected profits for each possible combination of &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y_i\inline&quot;/&gt;&lt;/span&gt; and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q_j\inline&quot;/&gt;&lt;/span&gt; is given by the matrix product &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbf{M} \mathbf{P} \mathbf{I} =: \mathbf{Q}\inline&quot;/&gt;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Let &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbf{V}_t\inline&quot;/&gt;&lt;/span&gt; be the &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_y\inline&quot;/&gt;&lt;/span&gt; by &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_q\inline&quot;/&gt;&lt;/span&gt; matrix at time &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?t\inline&quot;/&gt;&lt;/span&gt; giving the value of choosing quota &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q_j\inline&quot;/&gt;&lt;/span&gt; having observed stock &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y_i\inline&quot;/&gt;&lt;/span&gt; and having selected the optimal &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q_{t+1} \ldots q_{t_{\textrm{max}}}\inline&quot;/&gt;&lt;/span&gt;, that is:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbf{V}_t = \mathbf{Q} + \delta \mathbf{V}_{t+1}(y_t)&quot; alt=&quot;\mathbf{V}_t = \mathbf{Q} + \delta \mathbf{V}_{t+1}(y_t)&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Let &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\vec{v}_t\inline&quot;/&gt;&lt;/span&gt; be the &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_y\inline&quot;/&gt;&lt;/span&gt; vector with the maximum value of the each row (i.e. for each state &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y_i\inline&quot;/&gt;&lt;/span&gt;) of the matrix &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbf{V}_t\inline&quot;/&gt;&lt;/span&gt;, and&lt;/li&gt;
&lt;li&gt;let &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\vec{d}_t\inline&quot;/&gt;&lt;/span&gt; be the &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n_y\inline&quot;/&gt;&lt;/span&gt; vector whose elements give the column number (e.g. the &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?j\inline&quot;/&gt;&lt;/span&gt; determine the choice &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q_j\inline&quot;/&gt;&lt;/span&gt;) of the quota that corresponds to that value.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thus &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\operatorname{max}_q V_t(y_t) = v_t\inline&quot;/&gt;&lt;/span&gt;. Starting from the final timepoint, we know the ending value &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?v_T\inline&quot;/&gt;&lt;/span&gt; as a function of the ending state &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y_T\inline&quot;/&gt;&lt;/span&gt;. The probability of ending up in each possible state for &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y_T\inline&quot;/&gt;&lt;/span&gt;, given a choice of quota &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q\inline&quot;/&gt;&lt;/span&gt; and the current state &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y_{T-1}\inline&quot;/&gt;&lt;/span&gt; is given by the transition matrix &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbf{M}\mathbf{F}_q\inline&quot;/&gt;&lt;/span&gt;. The Bellman recursion becomes&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbf{V}_t[,q] = \mathbf{Q}[,q] + \delta \mathbf{M} \mathbf{F}_q v_{t+1}&quot; alt=&quot;\mathbf{V}_t[,q] = \mathbf{Q}[,q] + \delta \mathbf{M} \mathbf{F}_q v_{t+1}&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h3 id=&quot;r-code-algorithm&quot;&gt;R code algorithm:&lt;/h3&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;    Ep &amp;lt;- M %*% P %*% I
    V &amp;lt;- Ep
    for(t in &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:Tmax){                                 
      D[,(Tmax-t&lt;span class=&quot;dv&quot;&gt;+1&lt;/span&gt;)] &amp;lt;- &lt;span class=&quot;kw&quot;&gt;apply&lt;/span&gt;(V, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, which.max)        
      v_t &amp;lt;- &lt;span class=&quot;kw&quot;&gt;apply&lt;/span&gt;(V, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, max)                        
      V &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:n_h, function(j){               
        Ep[,j] + (&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;-delta) * M %*% F[[j]] %*% v_t  
      })
    }
    D&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Where&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;    P &amp;lt;-  &lt;span class=&quot;kw&quot;&gt;outer&lt;/span&gt;(x_grid, h_grid, profit) 
    M &amp;lt;- &lt;span class=&quot;kw&quot;&gt;rownorm&lt;/span&gt;( &lt;span class=&quot;kw&quot;&gt;outer&lt;/span&gt;(x_grid, x_grid, pdfn, sigma_m) )
    I &amp;lt;- &lt;span class=&quot;kw&quot;&gt;rownorm&lt;/span&gt;( &lt;span class=&quot;kw&quot;&gt;outer&lt;/span&gt;(h_grid, h_grid, pdfn, sigma_i) )&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;F is a bit more complicated:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;    F &amp;lt;- &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:n_h, function(q){  
      &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:n_x, function(y){
        out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;numeric&lt;/span&gt;(n_x)
        mu &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sum&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:n_x, function(x)
          &lt;span class=&quot;kw&quot;&gt;f&lt;/span&gt;(x_grid[x],h_grid,p) %*% 
            I[q,] *  &lt;span class=&quot;co&quot;&gt;# Implementation error&lt;/span&gt;
            M[x,y])) &lt;span class=&quot;co&quot;&gt;# Measurement error&lt;/span&gt;
        if(mu==&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)
          out[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;
        else 
          out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;dlnorm&lt;/span&gt;(x_grid/mu, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, sigma_g)
        out/&lt;span class=&quot;kw&quot;&gt;sum&lt;/span&gt;(out)
      }))
    })&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Something seems to be a mistake, since the optimal policy under uncertainty does not make sense:&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm8.staticflickr.com/7132/8158258480_972c8543e6.jpg&quot; alt=&quot;policy function under each source of uncertainty&quot; /&gt;&lt;figcaption&gt;policy function under each source of uncertainty&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/blob/bbef99ec43c75ff1dca959c1511b44c5159f4f4c/inst/examples/mult_uncertainty_test.md&quot;&gt;example script&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Updated Edit&lt;/strong&gt;&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/2012-11-17-f6c225f69f-policyfunctions.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/954cea9310063150bb42567b19caa272b34d32c2&quot;&gt;See notes on code changes inline&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/10/31/notes.html"/>
   <updated>2012-10-31T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/31/notes</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;I enjoyed an excellent meeting with Annette Thomas, CEO of MacMillian Publishing and Nature Publishing group at UC Davis. It was impressive to here that Annette wanted to meet with UC Davis faculty and graduate students interested in open access and open science to discuss our opinions, desires and frustrations in the scientific publishing process. It was particularly valuable to discuss some of the failed experiments in open science at Nature. Following this event I sent the letter below to Annette recording my reflections on those experiments and what I think they might have revealed. The 2 hour discussion with four graduate students, two faculty members and members of UC Davis and Cal Digital Libraries hit on many other topics as well, and these reflections capture just a few of the issues discussed.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Yesterday we discussed the failure of the 2004 experiment in open peer review and the failure of the pre-print server, Nature Precedings. In my humble opinion, both of these were doomed by insufficient incentives to participate.&lt;/p&gt;
&lt;p&gt;A more successful model to open up peer review has been that practiced by EMBO, as discussed in a Nature Comment in 2010 (doi: 10.1038/468029a). As we are already doing the work of peer review, their is an immediate incentive to get credit for that work through this mechanism, and more journals should consider it. (Biology Direct has a slightly more extreme take on this policy. Both have been far more successful than either the Nature experiment, comments sections of PLoS, or F1000 approaches to post-publication peer review).&lt;/p&gt;
&lt;p&gt;Precedings was a bold and powerful idea that addressed many real gaps in the current publishing infrastructure – a preprint server for fields not represented in arXiv, support for posters and presentations, dois (okay, EZID handles; crossref DOIs might have been better), and a more modern interface than arXiv provided. I was sad to see this close. As you both surely know, preprints run strongly counter to the grain of mainstream biology and their concept of precedence (unlike physics, economics and other fields where the opposite is true). As recent genomic examples have illustrated, the value of faster communication and a broader pre-publication review may slowly shift that culture, but journals such as Nature could play a key role in easing the transition, as your 2004 experiment showed.&lt;/p&gt;
&lt;p&gt;What is needed here is a button to submit work to the preprint server integrated into the normal submission form to the journal. This will dispel the persistent myth that the journal is not okay with it, and will meet with much larger uptake than simply providing the server separately would do. I would bet your own data from the 2004 experiment shows this pattern – more authors choose to participate in that, as a fraction of the total submissions, than have independently uploaded work to a preprint server. As you both observed, the failure of the 2004 experiment was in the breadth and depth of comments received, but as a study in willingness to use a preprint, it was an important positive discovery about promoting preprint culture that would only strengthen the final journal copies.&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/10/29/notes.html"/>
   <updated>2012-10-29T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/29/notes</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;misc&quot;&gt;Misc&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Mostly writing application today…&lt;/li&gt;
&lt;li&gt;Review for EcoLet&lt;/li&gt;
&lt;li&gt;looking over pomdp/momdp&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Notebook archives now &lt;a href=&quot;http://figshare.com/authors/Carl%20Boettiger/96387&quot;&gt;on figshare&lt;/a&gt; (plain-txt versions). Can now also cite entries by doi, e.g.: Lab Notebook (2010) doi:10.6084/m9.figshare.96916, and Lab Notebook, (2011) doi:10.6084/m9.figshare.96919. Would publishing individual entries and individual figshare objects be preferable or just annoying?&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Meeting tomorrow with Annette Thomas, CEO NPG/MacMillian. review &lt;a href=&quot;http://www.youtube.com/watch?v=djFs1p_4r-Y&amp;amp;feature=related&quot;&gt;interview with David Worlock&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;munch-data-project&quot;&gt;Munch data project&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Data extraction for geospatial life history project (&lt;a href=&quot;http://www.carlboettiger.info/assets/data&quot;&gt;file&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;R script for converting place names into latitude/longitude:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(RCurl)
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(RJSONIO)
construct.geocode.url &amp;lt;- function(address, &lt;span class=&quot;dt&quot;&gt;return.call =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;json&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;sensor =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;false&amp;quot;&lt;/span&gt;) {
    root &amp;lt;- &lt;span class=&quot;st&quot;&gt;&amp;quot;http://maps.google.com/maps/api/geocode/&amp;quot;&lt;/span&gt;
    u &amp;lt;- &lt;span class=&quot;kw&quot;&gt;paste&lt;/span&gt;(root, return.call, &lt;span class=&quot;st&quot;&gt;&amp;quot;?address=&amp;quot;&lt;/span&gt;, address, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;amp;sensor=&amp;quot;&lt;/span&gt;, sensor, &lt;span class=&quot;dt&quot;&gt;sep =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;)
    &lt;span class=&quot;kw&quot;&gt;return&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;URLencode&lt;/span&gt;(u))
}
gGeoCode &amp;lt;- function(address,&lt;span class=&quot;dt&quot;&gt;verbose=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;) {
  if(verbose) &lt;span class=&quot;kw&quot;&gt;cat&lt;/span&gt;(address,&lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt;)
  u &amp;lt;- &lt;span class=&quot;kw&quot;&gt;construct.geocode.url&lt;/span&gt;(address)
  doc &amp;lt;- &lt;span class=&quot;kw&quot;&gt;getURL&lt;/span&gt;(u)
  x &amp;lt;- &lt;span class=&quot;kw&quot;&gt;fromJSON&lt;/span&gt;(doc,&lt;span class=&quot;dt&quot;&gt;simplify =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;)
  if(x$status==&lt;span class=&quot;st&quot;&gt;&amp;quot;OK&amp;quot;&lt;/span&gt;) {
    lat &amp;lt;- x$results[[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]]$geometry$location$lat
    lng &amp;lt;- x$results[[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]]$geometry$location$lng
    &lt;span class=&quot;kw&quot;&gt;return&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(lat, lng))
  } else {
  &lt;span class=&quot;kw&quot;&gt;return&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;ot&quot;&gt;NA&lt;/span&gt;,&lt;span class=&quot;ot&quot;&gt;NA&lt;/span&gt;))
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;xml-compliance-in-html5&quot;&gt;XML compliance in HTML5&lt;/h2&gt;
&lt;p&gt;See &lt;a href=&quot;https://github.com/cboettig/labnotebook/issues/21&quot;&gt;labnotebook/issues/21&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;HTML5 allows tags to be unclosed, e.g. &lt;code&gt;&amp;lt;meta charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;/code&gt; instead of &lt;code&gt;&amp;lt;meta charset=&amp;quot;utf-8&amp;quot; /&amp;gt;&lt;/code&gt; but this is not valid XML.&lt;/p&gt;
&lt;p&gt;See: * &lt;a href=&quot;http://dev.w3.org/html5/html-xhtml-author-guide/&quot;&gt;Polyglot/xhtml5 author guide&lt;/a&gt; * &lt;a href=&quot;http://www.xmlplease.com/xhtml/xhtml5polyglot/#s1&quot;&gt;Benefits of XML&lt;/a&gt; * &lt;a href=&quot;http://www.w3.org/TR/xhtml-media-types/#C_2&quot;&gt;W3C XHTML media type&lt;/a&gt; * &lt;a href=&quot;http://www.w3.org/TR/html5/syntax.html#optional-tags&quot;&gt;Optional tags in html5&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Note that tags with no content must be closed with &lt;code&gt;/&amp;gt;&lt;/code&gt; (like the &lt;code&gt;meta&lt;/code&gt; example) while tags with content must get a normal closing (&lt;code&gt;&amp;lt;li&amp;gt; item &amp;lt;/li&amp;gt;&lt;/code&gt; etc). Despite this, the HTML5 spec is kinda logical since closing is syntax redundant even though not closing is not valid XML, see &lt;a href=&quot;http://stackoverflow.com/questions/3008593/html-include-or-exclude-optional-closing-tags&quot;&gt;SO question&lt;/a&gt; for discussion.&lt;/p&gt;
&lt;h3 id=&quot;example&quot;&gt;example&lt;/h3&gt;
&lt;p&gt;Basic XML parsing is now possible, e.g. in R:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(XML)
&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(RCurl)
tt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;getURLContent&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;http://www.carlboettiger.info/2012/10/25/stochastic-dynamic-programming-with-gaussian-process-approx.html&amp;quot;&lt;/span&gt;)
doc &amp;lt;- &lt;span class=&quot;kw&quot;&gt;xmlParse&lt;/span&gt;(tt)
&lt;span class=&quot;kw&quot;&gt;getNodeSet&lt;/span&gt;(doc, &lt;span class=&quot;st&quot;&gt;&amp;quot;//x:meta&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;namespace=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Validation requires &lt;code&gt;meta&lt;/code&gt; tags only appear in &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; and not &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; (but still do use &lt;code&gt;property&lt;/code&gt; and not &lt;code&gt;name&lt;/code&gt; for RDFa properties). Validation also requries all images have alt-text, which means I should remember to use anchor text om pandoc images (e.g. also name my graph knitr chunks intelligently). Otherwise the site validates as HTML5.&lt;/p&gt;
&lt;p&gt;Ignoring the declared content-type will nearly validate as XML. Had to make the attribute &lt;code&gt;onClick&lt;/code&gt; from the Google tracker javascript lowercase &lt;code&gt;onclick&lt;/code&gt;, like all other attributes. Now th only challenge is that HTML5 needs &lt;code&gt;lang=&lt;/code&gt; declared in &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt; tag, (while is tolerant of &lt;code&gt;xml:lang&lt;/code&gt;), but &lt;code&gt;XML&lt;/code&gt; doesn’t want to see &lt;code&gt;lang&lt;/code&gt; in the &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt; tag. Perhaps can go somewhere else and be valid HTML5? (Using a &lt;code&gt;meta&lt;/code&gt; tag for this is now &lt;a href=&quot;http://nimbupani.com/declaring-languages-in-html-5.html&quot;&gt;obsolete&lt;/a&gt;).&lt;/p&gt;
&lt;h3 id=&quot;mathml&quot;&gt;MathML&lt;/h3&gt;
&lt;p&gt;Mathml namespace is loaded by default in HTML5 (a native namespace). Currently using the javascript MathJax which has very nice display and interactive toggles (including getting the latex or mathml source). It looks like MathJax can take either latex input or mathml input, and Pandoc can render the latex source (much much nicer to type) into mathml. Just need to get pandoc to convert the source to mathml and then have the mathml rendered pretty by MathJax css, e.g. http://www.mathjax.org/demos/mathml-samples/. This may also load faster than javascript-based rendering of MathJax(?)&lt;/p&gt;
&lt;h2 id=&quot;alm-goals&quot;&gt;ALM goals&lt;/h2&gt;
&lt;p&gt;Headed to the PLOS ALM conference with ropensci next week. Should be a good chance to catch up on projects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;rfigshare to CRAN&lt;/li&gt;
&lt;li&gt;semantic knitcitations&lt;/li&gt;
&lt;li&gt;Mark Hahnel: figshare archiving of notebook – archive the markdown? archive code? archive git repos?&lt;/li&gt;
&lt;li&gt;Martin Fenner: Scholarly HTML standards, notebook standards (can we get John Kunze involved?)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Stochastic Dynamic Programming With Gaussian Process Approx</title>
   <link href="/2012/10/25/stochastic-dynamic-programming-with-gaussian-process-approx.html"/>
   <updated>2012-10-25T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/25/stochastic-dynamic-programming-with-gaussian-process-approx</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Here we work out an SDP solution of the Reed (1979) using a Gaussian process approximation. In this example the Gaussian process hyper-parameters haven’t been tuned, so in principle the solution would perform even better, but this is just for illustrative purposes.&lt;/p&gt;
&lt;p&gt;We simulate 40 points under a stochastic growth (lognormal multiplicative noise) Beverton-Holt model and infer the Gaussian process. We start the simulation from a low stock value, giving reasonable but not perfect coverage of the state-space. The prior still has a strong influence outside these regions, so the GP doesn’t quite match the Beverton-Holt curve, as seen in the first figure.&lt;/p&gt;
&lt;p&gt;We solve for the optimal policy function by discretizing the system and using the Gaussian process to fill out the stochastic transition matrix, which we pass to my little stochastic dynamic programming library to determine the policy function. We compare this policy function to the solution for the true F (Beverton-Holt) in the second figure, and note somewhat substantial differences (in particular a clear deviation from the constant escapement rule that emerges, which in itself is quite interesting, all though clearly non optimal in this case.&lt;/p&gt;
&lt;p&gt;The GP doesn’t learn during the actual test period when the management is being implemented, though of course it could easily do so (after accounting for the application of the control). A single replicate simulation compares the optimal management under the true model to the GP management, which does less well (obviously), but not by a dramatic amount.&lt;/p&gt;
&lt;p&gt;Code provides explicit statements of the models and should generate a reproducible example.&lt;/p&gt;
&lt;p&gt;Next steps should optimize the GP and compare against the more realistic test case where the parameterized model is estimated from the simulation data (possibly under different functional forms, etc).&lt;/p&gt;
&lt;h3 id=&quot;coded-example-below-from-reed-example.md&quot;&gt;Coded example below, from &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/a40d56af2e0f3be58e1b92347c96b829cadb130a/inst/examples/reed-example.md&quot;&gt;reed-example.md&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;load my libraries and plotting lib.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(nonparametricbayes)
&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(pdgControl)
&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(ggplot2)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(push images to flickr)&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;opts_knit$&lt;span class=&quot;kw&quot;&gt;set&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;upload.fun =&lt;/span&gt; socialR::flickr.url)&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;beverton-holt-function&quot;&gt;Beverton-Holt function&lt;/h3&gt;
&lt;p&gt;Simulate some training data under a stochastic growth function with standard parameterization,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;f &amp;lt;- BevHolt
p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;fl&quot;&gt;1.5&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.05&lt;/span&gt;)
K &amp;lt;- (p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] - &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)/p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Parameter definitions&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;x_grid = &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;1.5&lt;/span&gt; * K, &lt;span class=&quot;dt&quot;&gt;length =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;101&lt;/span&gt;)
T &amp;lt;- &lt;span class=&quot;dv&quot;&gt;40&lt;/span&gt;
sigma_g &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;
x &amp;lt;- &lt;span class=&quot;kw&quot;&gt;numeric&lt;/span&gt;(T)
x[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Noise function, profit function&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;z_g &amp;lt;- function() &lt;span class=&quot;kw&quot;&gt;rlnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, sigma_g)  &lt;span class=&quot;co&quot;&gt;#1+(2*runif(1, 0,  1)-1)*sigma_g #&lt;/span&gt;
profit &amp;lt;- &lt;span class=&quot;kw&quot;&gt;profit_harvest&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Simulation&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;for (t in &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:(T - &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)) x[t + &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] = &lt;span class=&quot;kw&quot;&gt;z_g&lt;/span&gt;() * &lt;span class=&quot;kw&quot;&gt;f&lt;/span&gt;(x[t], &lt;span class=&quot;dt&quot;&gt;h =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;p =&lt;/span&gt; p)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Predict the function over the target grid&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;obs &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; x[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:(T - &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)], &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; x[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;:T])
X &amp;lt;- x_grid
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(nonparametricbayes)
gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gp_fit&lt;/span&gt;(obs, X, &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;sigma_n =&lt;/span&gt; &lt;span class=&quot;fl&quot;&gt;0.5&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;l =&lt;/span&gt; &lt;span class=&quot;fl&quot;&gt;1.5&lt;/span&gt;))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Gaussian Process inference from this model. True model shown in red.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;df &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; X, &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; gp$Ef, &lt;span class=&quot;dt&quot;&gt;ymin =&lt;/span&gt; (gp$Ef - &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;abs&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(gp$Cf)))), 
    &lt;span class=&quot;dt&quot;&gt;ymax =&lt;/span&gt; (gp$Ef + &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;abs&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(gp$Cf)))))
true &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; X, &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(X, f, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, p))
&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(ggplot2)
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(df) + &lt;span class=&quot;kw&quot;&gt;geom_ribbon&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y, &lt;span class=&quot;dt&quot;&gt;ymin =&lt;/span&gt; ymin, &lt;span class=&quot;dt&quot;&gt;ymax =&lt;/span&gt; ymax), &lt;span class=&quot;dt&quot;&gt;fill =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;gray80&amp;quot;&lt;/span&gt;) + 
    &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y)) + &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data =&lt;/span&gt; obs, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y)) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data =&lt;/span&gt; true, 
    &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y), &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;lty =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8464/8123212898_904aa88749_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;stochastic-dynamic-programming-solution-based-on-the-posterior-gaussian-process&quot;&gt;Stochastic Dynamic programming solution based on the posterior Gaussian process:&lt;/h2&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;rownorm &amp;lt;- function(M) &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;apply&lt;/span&gt;(M, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, function(x) x/&lt;span class=&quot;kw&quot;&gt;sum&lt;/span&gt;(x)))
h_grid &amp;lt;- x_grid&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Define a transition matrix &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?F\inline&quot;/&gt;&lt;/span&gt; from the Gaussian process, giving the probability of going from state &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_t\inline&quot;/&gt;&lt;/span&gt; to &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_{t+1}\inline&quot;/&gt;&lt;/span&gt;. We already have the Gaussian process mean and variance predicted for each point &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt; on our grid, so this is simply:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;V &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(gp$Cf))
matrices_gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(h_grid, function(h) {
    F &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(x_grid, function(x) &lt;span class=&quot;kw&quot;&gt;dnorm&lt;/span&gt;(x, gp$Ef - h, V))
    F &amp;lt;- &lt;span class=&quot;kw&quot;&gt;rownorm&lt;/span&gt;(F)
})&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;True &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?f(x)\inline&quot;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;matrices_true &amp;lt;- &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(h_grid, function(h) {
    mu &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(x_grid, f, h, p)
    F_true &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(x_grid, function(x) &lt;span class=&quot;kw&quot;&gt;dnorm&lt;/span&gt;(x, mu, sigma_g))
    F_true &amp;lt;- &lt;span class=&quot;kw&quot;&gt;rownorm&lt;/span&gt;(F_true)
})&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Calculate the policy function using the true F:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;opt_true &amp;lt;- &lt;span class=&quot;kw&quot;&gt;find_dp_optim&lt;/span&gt;(matrices_true, x_grid, h_grid, &lt;span class=&quot;dv&quot;&gt;20&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, profit, 
    &lt;span class=&quot;dt&quot;&gt;delta =&lt;/span&gt; &lt;span class=&quot;fl&quot;&gt;0.01&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Calculate using the inferred GP&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;opt_gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;find_dp_optim&lt;/span&gt;(matrices_gp, x_grid, h_grid, &lt;span class=&quot;dv&quot;&gt;20&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, profit, 
    &lt;span class=&quot;dt&quot;&gt;delta =&lt;/span&gt; &lt;span class=&quot;fl&quot;&gt;0.01&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(reshape2)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;policies &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;stock =&lt;/span&gt; x_grid, &lt;span class=&quot;dt&quot;&gt;GP =&lt;/span&gt; x_grid[opt_gp$D[, 
    &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]], &lt;span class=&quot;dt&quot;&gt;Exact =&lt;/span&gt; x_grid[opt_true$D[, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]]), &lt;span class=&quot;dt&quot;&gt;id =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;stock&amp;quot;&lt;/span&gt;)
q1 &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(policies, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(stock, stock - value, &lt;span class=&quot;dt&quot;&gt;color =&lt;/span&gt; variable)) + 
    &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;() + &lt;span class=&quot;kw&quot;&gt;xlab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;stock size&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;ylab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;escapement&amp;quot;&lt;/span&gt;)
q1&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8053/8123196485_a3dc43986f_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;We can see what happens when we attempt to manage a stock using this:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;z_g &amp;lt;- function() &lt;span class=&quot;kw&quot;&gt;rlnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, sigma_g)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;set.seed&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)
sim_gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ForwardSimulate&lt;/span&gt;(f, p, x_grid, h_grid, K, opt_gp$D, z_g, 
    &lt;span class=&quot;dt&quot;&gt;profit =&lt;/span&gt; profit)
&lt;span class=&quot;kw&quot;&gt;set.seed&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)
sim_true &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ForwardSimulate&lt;/span&gt;(f, p, x_grid, h_grid, K, opt_true$D, 
    z_g, &lt;span class=&quot;dt&quot;&gt;profit =&lt;/span&gt; profit)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;df &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;time =&lt;/span&gt; sim_gp$time, &lt;span class=&quot;dt&quot;&gt;stock_gp =&lt;/span&gt; sim_gp$fishstock, 
    &lt;span class=&quot;dt&quot;&gt;stock_true =&lt;/span&gt; sim_true$fishstock, &lt;span class=&quot;dt&quot;&gt;harvest_gp =&lt;/span&gt; sim_gp$harvest, &lt;span class=&quot;dt&quot;&gt;havest_true =&lt;/span&gt; sim_true$harvest)
df &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(df, &lt;span class=&quot;dt&quot;&gt;id =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;time&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(df) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(time, value, &lt;span class=&quot;dt&quot;&gt;color =&lt;/span&gt; variable))&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8191/8123196619_5b8ab8d81d_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;Total Profits&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;sum&lt;/span&gt;(sim_gp$profit)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] 25.43&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;sum&lt;/span&gt;(sim_true$profit)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] 29.95&lt;/code&gt;&lt;/pre&gt;
</content>
 </entry>
 
 <entry>
   <title>Multiple Uncertainty Value Function Iteration</title>
   <link href="/2012/10/24/multiple-uncertainty-value-function-iteration.html"/>
   <updated>2012-10-24T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/24/multiple-uncertainty-value-function-iteration</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h3 id=&quot;multiple-uncertainty-algorithm&quot;&gt;Multiple Uncertainty algorithm&lt;/h3&gt;
&lt;p&gt;Define each of the transition matrices:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;    D &amp;lt;- &lt;span class=&quot;kw&quot;&gt;matrix&lt;/span&gt;(&lt;span class=&quot;ot&quot;&gt;NA&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;nrow=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(x_grid), &lt;span class=&quot;dt&quot;&gt;ncol=&lt;/span&gt;Tmax)  
    P &amp;lt;- &lt;span class=&quot;kw&quot;&gt;outer&lt;/span&gt;(x_grid, h_grid, profit)
    F &amp;lt;- &lt;span class=&quot;kw&quot;&gt;outer&lt;/span&gt;(x_grid, &lt;span class=&quot;kw&quot;&gt;f&lt;/span&gt;(x_grid, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, p), pdfn, sigma_g)
    M &amp;lt;- &lt;span class=&quot;kw&quot;&gt;outer&lt;/span&gt;(x_grid, x_grid, pdfn, sigma_m)
    I &amp;lt;- &lt;span class=&quot;kw&quot;&gt;outer&lt;/span&gt;(h_grid, h_grid, pdfn, sigma_i)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Probably row-normalize each:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;rownorm &amp;lt;- function(M) &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;apply&lt;/span&gt;(M, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, function(x) x/&lt;span class=&quot;kw&quot;&gt;sum&lt;/span&gt;(x))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(Note the transpose is needed since the silly function of a vector turns the column into a row. Not an issue of margin 2)&lt;/p&gt;
&lt;p&gt;If we have no uncertainty in measurement or implementation, then the algorithm is:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;    V &amp;lt;- P
    for(t in &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:Tmax){
      D[,(Tmax-t&lt;span class=&quot;dv&quot;&gt;+1&lt;/span&gt;)] &amp;lt;- &lt;span class=&quot;kw&quot;&gt;apply&lt;/span&gt;(V, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, which.max)
      V &amp;lt;- P + delta * F %*% V %*% D[, (Tmax-t&lt;span class=&quot;dv&quot;&gt;+1&lt;/span&gt;)]  
    }
    D&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With uncertainty&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;Ep &amp;lt;- M %*% P %*% I
U &amp;lt;- &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(M) %*% F %*% M 
V &amp;lt;- Ep
  for(t in &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:Tmax){
    D[,(Tmax-t&lt;span class=&quot;dv&quot;&gt;+1&lt;/span&gt;)] &amp;lt;- &lt;span class=&quot;kw&quot;&gt;apply&lt;/span&gt;(V, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, which.max)
    V &amp;lt;- Ep + delta * U %*% V %*% I %*% D[, (Tmax-t&lt;span class=&quot;dv&quot;&gt;+1&lt;/span&gt;)]  
  }&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;description&quot;&gt;Description&lt;/h3&gt;
&lt;p&gt;** rambling thinking while working out the above **&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;http://www.carlboettiger.info/2012/10/01/multiple-uncertainty.html&quot;&gt;October 1st entry&lt;/a&gt; derives the rule for updating the state (measured stock),&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?Y_{t+1} = \mathbb{F} \mathbb{M} \mathbb{I}_h \vec Y_t,&quot; alt=&quot;Y_{t+1} = \mathbb{F} \mathbb{M} \mathbb{I}_h \vec Y_t,&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;but this isn’t sufficient to complete the value iteration. Recall from the Bellman recursion,&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?V_t = \max_h \operatorname{E}\left( \Pi(Y_t, h_t) + V(Y_{t+1}, h_{t+1}) \right)&quot; alt=&quot;V_t = \max_h \operatorname{E}\left( \Pi(Y_t, h_t) + V(Y_{t+1}, h_{t+1}) \right)&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In the final timestep with no scrap value, we assert that the vector of values for each possible state, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\vec V_T = {0}\inline&quot;/&gt;&lt;/span&gt;. The previous year is then the first year that can have profits, given by &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\Pi(Y_{T-1}, h_{T-1})\inline&quot;/&gt;&lt;/span&gt;. Of course &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?Y_{T-1}\inline&quot;/&gt;&lt;/span&gt; is unknown, but is given by the recursion in (1).&lt;/p&gt;
&lt;p&gt;Our strategy in discrete space is to work backwards from &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?T\inline&quot;/&gt;&lt;/span&gt;, keeping track of the &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt; that maximizes the value-to-go for each possible state. So at &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?T-1\inline&quot;/&gt;&lt;/span&gt;, we put each possible state &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt; and each possible havest &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt; into &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\Pi(y,h)\inline&quot;/&gt;&lt;/span&gt; and select the &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt; that maximizes the profit. In the case of a deterministic harvest and a lack of measurement error this first iteration is trivial: harvest what you see &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h=y\inline&quot;/&gt;&lt;/span&gt; (unless &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt; is bounded or there is a cost on effort), yielding the value &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?V_{T-1}\inline&quot;/&gt;&lt;/span&gt; for each state &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt; is &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\Pi(y,y)\inline&quot;/&gt;&lt;/span&gt;. When profits are proportional to harvest, up to a constant this is simply &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;For a generic profit function that may have a cost on effort, we must store the map of which &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt; is optimal for each &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt;. In discrete space, call this the decision vector &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?D_{T-1}\inline&quot;/&gt;&lt;/span&gt; where the indices correspond to the states &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt; and the values correspond to the harvest (or harvest index) that is optimal for that state, and we write &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\Pi(y_{T-1}, D_{T-1}(y_{T-1}))\inline&quot;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;If there is uncertainty in either implementation of the harvest or measurement of the stock, or both, then we must integrate over this in determining the optimal &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt;. The expected profit derived from choosing a harvest quota &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q\inline&quot;/&gt;&lt;/span&gt; and having measured a stock at &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt; is given by&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\Pi(y,q) = \int \int \Pi(x,h) P(x) dx P(h) dh&quot; alt=&quot;\Pi(y,q) = \int \int \Pi(x,h) P(x) dx P(h) dh&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In matrix form, if &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbb{P}\inline&quot;/&gt;&lt;/span&gt; is the matrix of profits where element &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?p_{ij} = \Pi(x_i, h_j)\inline&quot;/&gt;&lt;/span&gt; and vector &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\vec H\inline&quot;/&gt;&lt;/span&gt; with elements &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?H_i\inline&quot;/&gt;&lt;/span&gt; give the probability of harvesting &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h_i\inline&quot;/&gt;&lt;/span&gt; fish given the quota &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q\inline&quot;/&gt;&lt;/span&gt;, then &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbb{P} \vec H\inline&quot;/&gt;&lt;/span&gt; is a vector of profits for each &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_i\inline&quot;/&gt;&lt;/span&gt;. Representing distribution in the measurement similarly as &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\vec X\inline&quot;/&gt;&lt;/span&gt;, the integration for the expected profit is &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\vec X^T \mathbb{P} \vec H\inline&quot;/&gt;&lt;/span&gt; (giving the scalar value &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\Pi(y,q)\inline&quot;/&gt;&lt;/span&gt;).&lt;/p&gt;
&lt;p&gt;We can store &amp;amp; lookup &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?X\inline&quot;/&gt;&lt;/span&gt; using a matrix whose columns give &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\vec X\inline&quot;/&gt;&lt;/span&gt; for each value &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt;, and similarly for &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?H\inline&quot;/&gt;&lt;/span&gt; given &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q\inline&quot;/&gt;&lt;/span&gt;. These are our matrices &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbb{M}\inline&quot;/&gt;&lt;/span&gt; (each row is a fixed observed &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt;, maps true &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt; into observed &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt;, elements &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?P_m(y, x)\inline&quot;/&gt;&lt;/span&gt;) &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbb{I}\inline&quot;/&gt;&lt;/span&gt; (mapping quota &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q\inline&quot;/&gt;&lt;/span&gt; (columns) to implemented harvest &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt;, elements &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?P_I(h_i, q_j)\inline&quot;/&gt;&lt;/span&gt;) from before. Then we can write &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\operatorname{E}(\Pi(x,h) | y,q)\inline&quot;/&gt;&lt;/span&gt; as a matrix resulting from the product of matrices:&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\tilde{\mathbb{P}} =  \mathbb{M} \mathbb{P} \mathbb{I}&quot; alt=&quot;\tilde{\mathbb{P}} =  \mathbb{M} \mathbb{P} \mathbb{I}&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In the next iteration, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?T-2\inline&quot;/&gt;&lt;/span&gt;, we realize that our choice of &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt; impacts the value we could get a time &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?T-1\inline&quot;/&gt;&lt;/span&gt; as well. In choosing the harvest quota in this interval we must also consider what value it introduces in the &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?T-1\inline&quot;/&gt;&lt;/span&gt; interval. We already have the matrix above giving the profits for each &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt; and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt;, we just need to transition from the space of the current &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt; to the future &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt; through application of the transition matrix &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?T: y_t \to y_{t+1}\inline&quot;/&gt;&lt;/span&gt;. &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?F: x_t \to x_{t+1}\inline&quot;/&gt;&lt;/span&gt;, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?F(x_{t+1}, x_t)\inline&quot;/&gt;&lt;/span&gt;, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?M: x \to y\inline&quot;/&gt;&lt;/span&gt;, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?I: q \to h\inline&quot;/&gt;&lt;/span&gt;, so&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbb{T} = M^T F M \tilde{P} I D_t&quot; alt=&quot;\mathbb{T} = M^T F M \tilde{P} I D_t&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Evolutionary Covariance</title>
   <link href="/2012/10/24/evolutionary-covariance.html"/>
   <updated>2012-10-24T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/24/evolutionary-covariance</id>
    
   <category term="//categories.html#evolution" label="evolution"/>
   
   <content type="html">&lt;p&gt;&lt;em&gt;Thinking through disparity measures while writing my thoughts in R…&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Load some sample data&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(geiger)
&lt;span class=&quot;kw&quot;&gt;data&lt;/span&gt;(geospiza)
dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;treedata&lt;/span&gt;(geospiza$geospiza.tree, geospiza$geospiza.data$wingL)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To find the disparity relative to a particular model, we must compute the variance-covariance matrix for that model&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;X &amp;lt;- dat$data
V_bm &amp;lt;- &lt;span class=&quot;kw&quot;&gt;vcv&lt;/span&gt;(dat$phy)
mean_X &amp;lt;- geiger:::&lt;span class=&quot;kw&quot;&gt;phylogMean&lt;/span&gt;(V_bm, X)
bm_disparity &amp;lt;- &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(X-mean_X) %*% V_bm %*% (X-mean_X)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I believe this needs to be scaled by the Brownian rate parameter of the trait, e.g.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;bm &amp;lt;- &lt;span class=&quot;kw&quot;&gt;fitContinuous&lt;/span&gt;(dat$phy, dat$data)
bm_disparity &amp;lt;- bm[[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]]$beta * bm_disparity
OU would be similar, but transform the tree&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;ou &amp;lt;- &lt;span class=&quot;kw&quot;&gt;fitContinuous&lt;/span&gt;(dat$phy, dat$data, &lt;span class=&quot;dt&quot;&gt;model=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;OU&amp;quot;&lt;/span&gt;)
alpha &amp;lt;-  ou[[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]]$alpha
V_ou &amp;lt;- &lt;span class=&quot;kw&quot;&gt;vcv&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;ouTree&lt;/span&gt;(dat$phy, alpha))
ou_var &amp;lt;- ou[[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]]$beta/(&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;*alpha)
X_mean &amp;lt;- &lt;span class=&quot;kw&quot;&gt;phylogMean&lt;/span&gt;(V_ou, X)
ou_disparity &amp;lt;- &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(X-X_mean) %*% V_ou %*% (X-X_mean) * ou_var&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There’s a few things I’m unsure about off the top of my head in this. I should double-check that &lt;code&gt;beta&lt;/code&gt; in geiger is the same as &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\sigma^2\inline&quot;/&gt;&lt;/span&gt;, and I should double check the ou variance-covariance formula (e.g. compare to the un-numbered equation after equation 5 in Butler &amp;amp; King). I also not sure I quite have the right &lt;code&gt;X_mean&lt;/code&gt; in the OU case.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Semantic Markup Examples For The Lab Notebook</title>
   <link href="/2012/10/23/semantic-markup-examples-for-the-lab-notebook.html"/>
   <updated>2012-10-23T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/23/semantic-markup-examples-for-the-lab-notebook</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;All notebook entries are formatted with XHTML compliant (polyglot) HTML5 semantic structure. This means that any entry can be parsed with a generic XML parser to extract the entry content in &lt;code&gt;&amp;lt;article&amp;gt;&lt;/code&gt;, the &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;footer&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt;, etc. The &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; section provides &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; and essential &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tags declaring the character encoding (which also sets the MIME type for HTML5).&lt;/p&gt;
&lt;h3 id=&quot;head&quot;&gt;Head&lt;/h3&gt;
&lt;p&gt;In &lt;code&gt;_includes/header.html&lt;/code&gt; we introduce some basic academic archive metadata using the Dublin Core ontology. The html5 &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; seems like a good place for &lt;code&gt;dc:title&lt;/code&gt;. Other metadata is added invisibly using &lt;code&gt;content&lt;/code&gt; in a &lt;code&gt;meta&lt;/code&gt; tag.&lt;/p&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;&lt;span class=&quot;kw&quot;&gt;&amp;lt;head&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; prefix=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc: http://purl.org/dc/terms/&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;&amp;lt;!-- HTML5 metadata --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; charset=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;utf-8&amp;quot;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt; &lt;span class=&quot;co&quot;&gt;&amp;lt;!--same as &amp;lt;meta http-equiv=&amp;#39;Content-Type&amp;#39; content=&amp;#39;Type=text/html; charset=utf-8&amp;#39;&amp;gt; --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;author&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;Carl Boettiger&amp;quot;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;keywords&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;Ecology, Evolution, Open Science, Reproducible Research&amp;quot;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;description&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;My open lab notebook: research in theoretical ecology and evolution&amp;quot;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;viewport&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;width=device-width, initial-scale=1.0&amp;quot;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;{{ page.title }}&lt;span class=&quot;kw&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;&amp;lt;!-- RDFa Metdata (in Dublin Core) --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:creator&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;Carl Boettiger&amp;quot;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:title&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;{{ page.title }}&amp;quot;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:type&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;Lab Notebook&amp;quot;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:format&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;text/html&amp;quot;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:language&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; content=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;en&amp;quot;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;sidebar&quot;&gt;Sidebar&lt;/h3&gt;
&lt;p&gt;More metadata is displayed in the sidebar (in an html5 &lt;code&gt;aside&lt;/code&gt; element), including date, tags and category. I’ve added the following RDFa to describe these (see examples with the Jekyll liquid code in &lt;code&gt;_includes/sidebar.html&lt;/code&gt;)&lt;/p&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;&lt;span class=&quot;kw&quot;&gt;&amp;lt;aside&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; prefix=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc: http://purl.org/dc/terms/&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;
Posted on
&lt;span class=&quot;kw&quot;&gt;&amp;lt;time&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; datetime=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;{{ page.date | date_to_xmlschema }}&amp;quot;&lt;/span&gt; 
&lt;span class=&quot;ot&quot;&gt;      property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:created&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;{{ page.date | date_to_string }}&lt;span class=&quot;kw&quot;&gt;&amp;lt;/time&amp;gt;&lt;/span&gt;.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This puts the date in an HTML5 time element described as the &lt;code&gt;dc.created&lt;/code&gt; time of the publication. Tags and categories use a little Liquid code so Jekyll can import them from the YAML header. The link to the tag page is described with the HTML &lt;code&gt;rel&lt;/code&gt; attribute for tag, while the tag itself is given the RDFa property of a blog keyword from schema.org. Categories are given the more formal &lt;code&gt;dc:subject&lt;/code&gt; property. (See &lt;code&gt;_includes/pagetags.html&lt;/code&gt; for Jekyll/Liquid code for looping over multiple tags, etc).&lt;/p&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;  &lt;span class=&quot;kw&quot;&gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; rel=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;tag&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; class=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;tag&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;/tags.html#{{ tag | cgi_escape }}&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;#&lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt; 
&lt;span class=&quot;ot&quot;&gt;  property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://schema.org/BlogPosting/keywords&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;{{ tag }}&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; rel=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;tag&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; class=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;category&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;/categories.html#{{ category | cgi_escape }}&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;dc:subject&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;{{ category }}&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The next and previous buttons get the HTML5 &lt;code&gt;rel&lt;/code&gt; values &lt;code&gt;next&lt;/code&gt; and &lt;code&gt;prev&lt;/code&gt; (see &lt;a href=&quot;http://diveintohtml5.info/semantics.html&quot;&gt;HTML5 semantics&lt;/a&gt;). Note that all the Dublin Core elements are properties of the page on which they occur.&lt;/p&gt;
&lt;h3 id=&quot;footer&quot;&gt;Footer&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;&amp;lt;footer&amp;gt;&lt;/code&gt; contains licenses and contact information through social media. I’ve used the FOAF vocabulary to indicate my membership to the various social networks provided in the links. The social networks are properties of a &lt;code&gt;FOAF:person&lt;/code&gt;, (me), which is indicated in the RDFa &lt;code&gt;resource&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;&lt;span class=&quot;kw&quot;&gt;&amp;lt;div&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; class=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;span4&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; vocab=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; typeof=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;Person&amp;quot;&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;resource=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://www.carlboettiger.info#me&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;account&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;mailto:cboettig@gmail.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&amp;lt;img&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;  src=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;/assets/img/icon-email.png&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; alt=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;email&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;account&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;https://twitter.com/cboettig&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&amp;lt;img&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;  src=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;/assets/img/icon-twitter.png&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; alt=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;twitter&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;account&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;https://github.com/cboettig&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&amp;lt;img&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;  src=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://www.carlboettiger.info/assets/img/icon-github.png&amp;quot;&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;  alt=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;github&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;account&amp;quot;&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;  href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://www.mendeley.com/profiles/carl-boettiger&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&amp;lt;img&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;  src=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;/assets/img/icon-mendeley.png&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; alt=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;mendeley&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;/atom.xml&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&amp;lt;img&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; src=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;/assets/img/icon-rss.png&amp;quot;&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;alt=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;feed&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&amp;lt;/a&amp;gt;&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It might be worth adding more FOAF terms describing the relationship of these networks (such as distinguishing my profile name and the base url) using meta elements to avoid adding clutter text. I use the Creative Commons namespace to identify my CC0 license. The license is a property of the page on which it is found, like the Dublin Core metadata.&lt;/p&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;&lt;span class=&quot;kw&quot;&gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://creativecommons.org/ns#license&amp;quot;&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://creativecommons.org/publicdomain/zero/1.0/&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&amp;lt;img&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://i.creativecommons.org/l/zero/1.0/88x31.png&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; alt=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;CC0&amp;quot;&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;style=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;float:right&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/post-rdfa.png&quot; alt=&quot;When these elements are combined in a given entry, the RDFa generates this structure&quot; /&gt;&lt;figcaption&gt;When these elements are combined in a given entry, the RDFa generates this structure&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h3 id=&quot;easily-entering-rdfa&quot;&gt;Easily entering RDFa&lt;/h3&gt;
&lt;p&gt;All of this markup content is either generally static or filled in programatically by Jekyll from the YAML headers (e.g. title, categories, tags, date), leaving me free to put the RDFa into the template files just once and forget about it. In this way I can continue to write everything in Markdown, rather than the more cumbersome HTML riddled by the addition of RDFa attributes. Unfortunately there is no easy way to escape this in writing the Homepage markup, described below, but a single case isn’t so bad.&lt;/p&gt;
&lt;p&gt;Another obvious candidate for linked data in the posts is the citation information. This markup can probably be automatically generated for each post using scripts (see &lt;a href=&quot;http://www.carlboettiger.info/2012/10/05/notes.html&quot;&gt;Automated feeds in notebook entries&lt;/a&gt;), so I plan to add this to my knitcitations package when I get a chance (including CiTO support!).&lt;/p&gt;
&lt;h3 id=&quot;homepage&quot;&gt;Homepage&lt;/h3&gt;
&lt;p&gt;My homepage contains a brief description about me that is ripe for FOAF and schema.org. While this content is reasonably static, it does mean writing directly in HTML+RDFa, with the markup making the source almost unreadable. (It might be possible to force more of this data into YAML header and have it added through the invisible &lt;code&gt;meta&lt;/code&gt; tags, but that seems rather convoluted). Capturing the “buisness card” information as well as the “social” information requires mixing ontologies, which can lead to some interesting complications. To make a long story short:&lt;/p&gt;
&lt;ol type=&quot;a&quot;&gt;
&lt;li&gt;Implicit logic &lt;em&gt;is possible&lt;/em&gt; with linked data: we can infer that &lt;code&gt;schema:jobTitle&lt;/code&gt; can be a property of a &lt;code&gt;foaf:Person&lt;/code&gt; because it is a property of a &lt;code&gt;schema:Person&lt;/code&gt; and someone declares them as &lt;code&gt;owl:equivalentProperty&lt;/code&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;In practice it may be most robust to explicitly declare the relation by exploiting the fact that we can give multiple arguments to attributes like &lt;code&gt;property&lt;/code&gt; and &lt;code&gt;typeof&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;&lt;span class=&quot;kw&quot;&gt;&amp;lt;div&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;me&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; prefix=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;foaf: http://xmlns.com/foaf/0.1/&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; prefix=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;schema:&lt;/span&gt;
&lt;span class=&quot;st&quot;&gt;http://schema.org/Person&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; typeof=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;foaf:Person schema:Person&amp;quot;&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;resource=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://www.carlboettiger.info#me&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt; 
I am  &lt;span class=&quot;kw&quot;&gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;foaf:homepage schema:url&amp;quot;&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://www.carlboettiger.info&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;foaf:name&lt;/span&gt;
&lt;span class=&quot;st&quot;&gt;schema:name&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;foaf:givenName schema:givenName&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;Carl&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;foaf:familyName schema:familyName&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;Boettiger&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;&amp;lt;span&lt;/span&gt;
&lt;span class=&quot;ot&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;schema:jobTitle&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;a graduate student&lt;span class=&quot;kw&quot;&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(This excerpt gives the general flavor, see the html source of &lt;a href=&quot;http://www.carlboettiger.info&quot;&gt;index.html&lt;/a&gt; for a full example.)&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/assets/figures/homepage-rdfa.png&quot; alt=&quot;The homepage generates this RDFa structured graph (from rdfa.info/play)&quot; /&gt;&lt;figcaption&gt;The homepage generates this RDFa structured graph (from rdfa.info/play)&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;notes&quot;&gt;Notes&lt;/h2&gt;
&lt;p&gt;Some background reading on semantics&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Nice &lt;a href=&quot;http://scholarlyhtml.org/faq/&quot;&gt;collection of posts on scholarly html&lt;/a&gt;, but too little mention of the serious linked data stuff coming out of biscol, ievobio/nescent, etc. In particular, Martin’s &lt;a href=&quot;http://blogs.plos.org/mfenner/2011/03/19/a-very-brief-history-of-scholarly-html/&quot;&gt;history&lt;/a&gt; gives some nice perspective.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;The war for schema. Which ontologies should we choose? (e.g. &lt;a href=&quot;http://blogs.plos.org/mfenner/2011/06/07/schema-org-for-scholarly-html/&quot;&gt;schema.org’s take&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;On &lt;a href=&quot;http://manu.sporny.org/2011/false-choice/&quot;&gt;the good &amp;amp; the bad of schema.org and the role of search giants&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Mixing ontologies had me very confused.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How do we &lt;a href=&quot;http://stackoverflow.com/questions/12983766&quot;&gt;mix ontologies&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;How do we meet &lt;a href=&quot;http://answers.semanticweb.com/questions/19200/satisfy-google-rich-snippets-person-standard-using-foaf&quot;&gt;Google Rich Snippets requirements using FOAF?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;How do we &lt;a href=&quot;http://answers.semanticweb.com/questions/19275/what-to-do-about-redundant-rdfa-or-machines-that-speak-only-one-language&quot;&gt;avoid redundant vocabulary terms?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;We can avoid the redundancy using implicit reasoning (exploiting the logic of linked data), but we may prefer to be explict. &lt;a href=&quot;http://vimeo.com/28667500&quot;&gt;This video&lt;/a&gt; does a nice job of explaining these concepts. If we do semantics right, we should be able to “dereference” an object away from a particular ontology.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;tools-and-resources&quot;&gt;Tools and Resources&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.google.com/webmasters/tools/richsnippets&quot;&gt;Google rich snippets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://getschema.org/rdfaliteextractor/about&quot;&gt;rdfa extractor&lt;/a&gt; (into RDF, JSON, n3). Also has validator, but doesn’t point to the &lt;code&gt;nu&lt;/code&gt; variant for html5.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://rdfa.info/play/&quot;&gt;RDFa Play&lt;/a&gt;. Wow, very nice.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://sameas.org&quot;&gt;sameAs.org&lt;/a&gt; – search onotologies for an existing term, identify identical terms in different ontologies, etc. Simply brilliant, what I’ve always wanted!&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;knitcitations-update-adding-formats-an-semantics.&quot;&gt;knitcitations update: adding formats an semantics.&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Looking at citeproc / &lt;a href=&quot;http://citationstyles.org/&quot;&gt;CSL&lt;/a&gt; &lt;a href=&quot;https://github.com/citation-style-language&quot;&gt;github page&lt;/a&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Raw citeproc is an XML stylesheet, XSLT, which can render XML into HTML (and much more). Possible other options are using something like citeproc-js or citeproc-ruby, or writing citeproc-R.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Not quite clear how to take a CSL and a set of references and generate HTML; aforementioned packages may address this.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;For the moment, probably easier to convert R &lt;code&gt;bibitem&lt;/code&gt; to display with RDFa with scholarlyhtml recommended ontology than to enter raw XML reference and format via citeproc. Should also support adding in the cito tags. With full addresses in property, should be able to avoid any need for namespace/header modifications.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Gaussian process inference on sample functions</title>
   <link href="/2012/10/23/notes.html"/>
   <updated>2012-10-23T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/23/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;ul&gt;
&lt;li&gt;This example uses the direct inversion of the covariance function. I have also been exploring the potentially faster Cholksy decomposition without success. Sometimes the match is very good, other times not, see &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/c0624f95ece642dbcfa7d7bbeb8fd43c84354a3a/inst/examples/compare-cholsky.md&quot;&gt;compare-cholsky.md&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;This example also on github as &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/c0624f95ece642dbcfa7d7bbeb8fd43c84354a3a/inst/examples/reed-example.md&quot;&gt;reed-example.md&lt;/a&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Basic likelihood optimization needs to be checked. See commits &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/e35135230f92c5ee646225cdb4b0c3fa47dd8ead&quot;&gt;estimating &lt;code&gt;sigma_n&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/commit/d03db9312f7bbdacb451022f1e83ed11c682841d&quot;&gt;estimating &lt;code&gt;l&lt;/code&gt;&lt;/a&gt;. Compare the example below to &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes/blob/11666fb029ef213854065d86d08f03723d2cd828/inst/examples/reed-example.md&quot;&gt;a different set of fixed hyperparameters here&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;/h2&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(pdgControl)
&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(ggplot2)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Simulate some training data under a stochastic growth function with standard parameterization,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;f &amp;lt;- BevHolt
p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;fl&quot;&gt;1.5&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.05&lt;/span&gt;)
K &amp;lt;- (p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] - &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)/p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Noise function&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;z_g &amp;lt;- function(sigma_g) &lt;span class=&quot;kw&quot;&gt;rlnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, sigma_g)  &lt;span class=&quot;co&quot;&gt;#1+(2*runif(1, 0,  1)-1)*sigma_g #&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Parameter definitions&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;x_grid = &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;1.5&lt;/span&gt; * K, &lt;span class=&quot;dt&quot;&gt;length =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;)
T &amp;lt;- &lt;span class=&quot;dv&quot;&gt;40&lt;/span&gt;
sigma_g &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;
x &amp;lt;- &lt;span class=&quot;kw&quot;&gt;numeric&lt;/span&gt;(T)
x[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Simulation&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;for (t in &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:(T - &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)) x[t + &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] = &lt;span class=&quot;kw&quot;&gt;z_g&lt;/span&gt;(sigma_g) * &lt;span class=&quot;kw&quot;&gt;f&lt;/span&gt;(x[t], &lt;span class=&quot;dt&quot;&gt;h =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;p =&lt;/span&gt; p)

&lt;span class=&quot;kw&quot;&gt;plot&lt;/span&gt;(x)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8190/8117649167_f5002b7024_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;Predict the function over the target grid&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;obs &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; x[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:(T - &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)], &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; x[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;:T])
X &amp;lt;- x_grid
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(nonparametricbayes)
gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gp_fit&lt;/span&gt;(obs, X, &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;sigma_n =&lt;/span&gt; &lt;span class=&quot;fl&quot;&gt;0.05&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;l =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Gaussian Process inference from this model. True model shown in red.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;df &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; X, &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; gp$Ef, &lt;span class=&quot;dt&quot;&gt;ymin =&lt;/span&gt; (gp$Ef - &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;abs&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(gp$Cf)))), 
    &lt;span class=&quot;dt&quot;&gt;ymax =&lt;/span&gt; (gp$Ef + &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;abs&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(gp$Cf)))))
true &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; X, &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(X, f, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, p))
&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(ggplot2)
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(df) + &lt;span class=&quot;kw&quot;&gt;geom_ribbon&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y, &lt;span class=&quot;dt&quot;&gt;ymin =&lt;/span&gt; ymin, &lt;span class=&quot;dt&quot;&gt;ymax =&lt;/span&gt; ymax), &lt;span class=&quot;dt&quot;&gt;fill =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;gray80&amp;quot;&lt;/span&gt;) + 
    &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y)) + &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data =&lt;/span&gt; obs, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y)) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data =&lt;/span&gt; true, 
    &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y), &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;lty =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8336/8117660178_beeca82760_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;another-example-using-the-may-model&quot;&gt;Another example using the May model&lt;/h2&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;f &amp;lt;- May
p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;r =&lt;/span&gt; &lt;span class=&quot;fl&quot;&gt;0.75&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;k =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;a =&lt;/span&gt; &lt;span class=&quot;fl&quot;&gt;1.2&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;H =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;Q =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;)
K &amp;lt;- &lt;span class=&quot;dv&quot;&gt;8&lt;/span&gt;  &lt;span class=&quot;co&quot;&gt;# approx&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Model dynamics look like this:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;birth &amp;lt;- function(x) p[&lt;span class=&quot;st&quot;&gt;&amp;quot;r&amp;quot;&lt;/span&gt;] * (&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt; - x/p[&lt;span class=&quot;st&quot;&gt;&amp;quot;k&amp;quot;&lt;/span&gt;])
death &amp;lt;- function(x) p[&lt;span class=&quot;st&quot;&gt;&amp;quot;a&amp;quot;&lt;/span&gt;] * x^(p[&lt;span class=&quot;st&quot;&gt;&amp;quot;Q&amp;quot;&lt;/span&gt;] - &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)/(x^p[&lt;span class=&quot;st&quot;&gt;&amp;quot;Q&amp;quot;&lt;/span&gt;] + p[&lt;span class=&quot;st&quot;&gt;&amp;quot;H&amp;quot;&lt;/span&gt;])
df &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; x_grid, &lt;span class=&quot;dt&quot;&gt;b =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(x_grid, birth), &lt;span class=&quot;dt&quot;&gt;d =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(x_grid, 
    death))
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(df) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, b), &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;blue&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, 
    d), &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8046/8117660240_31c8d052c4_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;Simulation&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;x[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] = &lt;span class=&quot;fl&quot;&gt;2.5&lt;/span&gt;
for (t in &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:(T - &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)) x[t + &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] = &lt;span class=&quot;kw&quot;&gt;z_g&lt;/span&gt;(sigma_g) * &lt;span class=&quot;kw&quot;&gt;f&lt;/span&gt;(x[t], &lt;span class=&quot;dt&quot;&gt;h =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;p =&lt;/span&gt; p)
&lt;span class=&quot;kw&quot;&gt;plot&lt;/span&gt;(x)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8330/8117649515_59c703d880_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;p&gt;Predict the function over the target grid&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;obs &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; x[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:(T - &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)], &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; x[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;:T])
X &amp;lt;- x_grid
&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(nonparametricbayes)
gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gp_fit&lt;/span&gt;(obs, X, &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;sigma_n =&lt;/span&gt; &lt;span class=&quot;fl&quot;&gt;0.05&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;l =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Gaussian Process inference from this model&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;df &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; X, &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; gp$Ef, &lt;span class=&quot;dt&quot;&gt;ymin =&lt;/span&gt; (gp$Ef - &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;abs&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(gp$Cf)))), 
    &lt;span class=&quot;dt&quot;&gt;ymax =&lt;/span&gt; (gp$Ef + &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;abs&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(gp$Cf)))))
true &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; X, &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(X, f, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, p))
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(df) + &lt;span class=&quot;kw&quot;&gt;geom_ribbon&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y, &lt;span class=&quot;dt&quot;&gt;ymin =&lt;/span&gt; ymin, &lt;span class=&quot;dt&quot;&gt;ymax =&lt;/span&gt; ymax), &lt;span class=&quot;dt&quot;&gt;fill =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;gray80&amp;quot;&lt;/span&gt;) + 
    &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y)) + &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data =&lt;/span&gt; obs, &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y)) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data =&lt;/span&gt; true, 
    &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y), &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;lty =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8325/8117660460_a53eb7c10c_o.png&quot; /&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>Comparing numerical methods</title>
   <link href="/2012/10/22/notes.html"/>
   <updated>2012-10-22T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/22/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(MASS)
&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(ggplot2)
&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(kernlab)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Parameterization-specific&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;X &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;dt&quot;&gt;len=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;50&lt;/span&gt;)
obs &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;, -&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;, -&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;),
                  &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, -&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;))
l &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;
sigma_n &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.8&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Radial basis function/Gaussian kernel:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;  SE &amp;lt;- function(Xi,Xj, l) &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(-&lt;span class=&quot;fl&quot;&gt;0.5&lt;/span&gt; * (Xi - Xj) ^ &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; / l ^ &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)
  cov &amp;lt;- function(X, Y) &lt;span class=&quot;kw&quot;&gt;outer&lt;/span&gt;(X, Y, SE, l) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Cholksy method&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;  n &amp;lt;- &lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(obs$x)
  K &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(obs$x, obs$x)
  I &amp;lt;-  &lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, n)

  L &amp;lt;- &lt;span class=&quot;kw&quot;&gt;chol&lt;/span&gt;(K + sigma_n^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * I)
  alpha &amp;lt;- &lt;span class=&quot;kw&quot;&gt;solve&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(L), &lt;span class=&quot;kw&quot;&gt;solve&lt;/span&gt;(L, obs$y))
  k_star &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(obs$x, X)
  Y &amp;lt;- &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(k_star) %*% alpha
  v &amp;lt;- &lt;span class=&quot;kw&quot;&gt;solve&lt;/span&gt;(L, k_star)
  Var &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(X,X) - &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(v) %*% v
  loglik &amp;lt;- -.&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(obs$y) %*% alpha - &lt;span class=&quot;kw&quot;&gt;sum&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(L))) - n * &lt;span class=&quot;kw&quot;&gt;log&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * pi) / &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Direct method&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;  cov_xx_inv &amp;lt;- &lt;span class=&quot;kw&quot;&gt;solve&lt;/span&gt;(K + sigma_n^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;*I)
  Ef &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(X, obs$x) %*% cov_xx_inv %*% obs$y
  Cf &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(X, X) - &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(X, obs$x)  %*% cov_xx_inv %*% &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(obs$x, X)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;gp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gausspr&lt;/span&gt;(obs$x, obs$y, &lt;span class=&quot;dt&quot;&gt;kernel=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;rbfdot&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;kpar=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;list&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;sigma=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;/(&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;*l^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)), &lt;span class=&quot;dt&quot;&gt;fit=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;scaled=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;var=&lt;/span&gt;&lt;span class=&quot;fl&quot;&gt;0.8&lt;/span&gt;)
y_p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;predict&lt;/span&gt;(gp, X)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Things that should be equivelent but aren’t quite:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;X, &lt;span class=&quot;dt&quot;&gt;Ef=&lt;/span&gt;Ef, &lt;span class=&quot;dt&quot;&gt;Y=&lt;/span&gt;Y, &lt;span class=&quot;dt&quot;&gt;y_p =&lt;/span&gt; y_p))+ &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x,Ef), &lt;span class=&quot;dt&quot;&gt;col=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;#39;red&amp;#39;&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x,Y)) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x,y_p))&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8391/8589945615_b107599da4_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-8&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-8&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;cov_xx_inv %*% obs$y&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;        [,1]
[1,] -1.4059
[2,]  0.5010
[3,]  0.1288
[4,]  1.2275
[5,] -0.7119&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;alpha&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;[1] -1.21293  0.46074  0.07548  1.44144 -0.73949&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;alpha&lt;/span&gt;(gp)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;        [,1]
[1,] -1.2475
[2,]  0.4011
[3,]  0.1661
[4,]  1.1010
[5,] -0.6394&lt;/code&gt;&lt;/pre&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/10/19/notes.html"/>
   <updated>2012-10-19T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/19/notes</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;h2 id=&quot;semantic-notebook-notes&quot;&gt;Semantic Notebook notes&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Reading&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Nice &lt;a href=&quot;http://scholarlyhtml.org/faq/&quot;&gt;collection of posts on scholarly html&lt;/a&gt;, but too little mention of the serious linked data stuff coming out of biscol, ievobio/nescent, etc. In particular, Martin’s [history] (http://blogs.plos.org/mfenner/2011/03/19/a-very-brief-history-of-scholarly-html/) gives some nice perspective.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;The war for schema. Which ontologies should we choose? (e.g. &lt;a href=&quot;http://blogs.plos.org/mfenner/2011/06/07/schema-org-for-scholarly-html/&quot;&gt;schema.org’s take&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Puzzles&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How do we &lt;a href=&quot;http://stackoverflow.com/questions/12983766&quot;&gt;mix ontologies&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;How do we meet &lt;a href=&quot;http://answers.semanticweb.com/questions/19200/satisfy-google-rich-snippets-person-standard-using-foaf&quot;&gt;Google Rich Snippets requirements using FOAF?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;How do we &lt;a href=&quot;http://answers.semanticweb.com/questions/19275/what-to-do-about-redundant-rdfa-or-machines-that-speak-only-one-language&quot;&gt;avoid redundant vocabulary terms?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Basically we can do this using implicit reasoning (exploiting the logic of linked data), but we may prefer to be explict. &lt;a href=&quot;http://vimeo.com/28667500&quot;&gt;This video&lt;/a&gt; does a nice job of explaining these concepts. Basically, if we do this right, we should be able to “dereference” an object away from a particular ontology.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;On &lt;a href=&quot;http://manu.sporny.org/2011/false-choice/&quot;&gt;the good &amp;amp; the bad of schema.org and the role of search giants&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;resources&quot;&gt;Resources&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://getschema.org/rdfaliteextractor/about&quot;&gt;rdfa extractor&lt;/a&gt; (into RDF, JSON, n3). Also has validator, but doesn’t point to the &lt;code&gt;nu&lt;/code&gt; variant for html5.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://rdfa.info/play/&quot;&gt;RDFa Play&lt;/a&gt;. Wow, very nice.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://sameas.org&quot;&gt;sameAs.org&lt;/a&gt; – search onotologies for an existing term, identify identical terms in different ontologies, etc. Simply brilliant, what I’ve always wanted!&lt;/li&gt;
&lt;li&gt;Still not clear on rdfa vs html5. Why in the world should &lt;code&gt;dc:title&lt;/code&gt; be preferable to &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; ?&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;knitcitations-update-adding-formats-an-semantics.&quot;&gt;knitcitations update: adding formats an semantics.&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Looking at citeproc / &lt;a href=&quot;http://citationstyles.org/&quot;&gt;CSL&lt;/a&gt; &lt;a href=&quot;https://github.com/citation-style-language&quot;&gt;github page&lt;/a&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Raw citeproc is an XML stylesheet, XSLT, which can render XML into HTML (and much more). Possible other options are using something like citeproc-js or citeproc-ruby, or writing citeproc-R.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Not quite clear how to take a CSL and a set of references and generate HTML; aforementioned packages may address this.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;For the moment, probably easier to convert R &lt;code&gt;bibitem&lt;/code&gt; to display with RDFa with scholarlyhtml recommended ontology than to enter raw XML reference and format via citeproc. Should also support adding in the cito tags. With full addresses in property, should be able to avoid any need for namespace/header modifications.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/10/17/talkingpoints.html"/>
   <updated>2012-10-17T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/17/talkingpoints</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;talking-points&quot;&gt;Talking points&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;for phone interview with Lucy&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Finding warning signals in the wild&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Gold standard – experimental group, control group&lt;/li&gt;
&lt;li&gt;Real world: We have no control group.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Would we know a warning signal when we saw it?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;From statistics to models: We fit a generalized models of the processes that &lt;em&gt;are&lt;/em&gt; and &lt;em&gt;aren’t&lt;/em&gt; approaching a tipping point, and compare the models. The modeling approach is also more sensitive than the simple statistics.&lt;/p&gt;
&lt;p&gt;In another recent paper we consider the alternative ground-truth approach – historical data. There’s a problem in using historical data though, which is a bit subtle. It has tricked juries, confounded medical doctors, and confused scientists. We call it the Prosecutor’s fallacy (Thompson &amp;amp; Schumann 87). We need the probability the “accused pattern” is “innocent” of heading for a critical transition, given the data. We calculate instead the probability of data, given that pattern is innocent, is small. By itself, that is not enough to “convict” our data of being a warning signal.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Critical transitions in networks vs early warning signals – more must be done to map the connections.&lt;/li&gt;
&lt;li&gt;Be careful not to mistate generality – we know systems can collapse without transition, and warning signals can be seen without transitions&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Basic regression in Gaussian processes</title>
   <link href="/2012/10/17/basic-regression-in-gaussian-processes.html"/>
   <updated>2012-10-17T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/17/basic-regression-in-gaussian-processes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Working out coded examples for basic Gaussian process regression using R. I’ve just read through the first few chapters of &lt;a href=&quot;http://www.GaussianProcess.org/gpml&quot;&gt;Rasmussen &amp;amp; Williams (2006)&lt;/a&gt;, this implements the examples discussed in Chapter 2.1-2.5.&lt;/p&gt;
&lt;!-- Also motivated by [James Keirstead](http://www.jameskeirstead.ca/r/gaussian-process-regression-with-r/), with cleaner code.  --&gt;

&lt;p&gt;Required R libraries (for multivariate normal, also for plotting):&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(MASS)
&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(reshape2)
&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(ggplot2)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Set a seed for repeatable plots&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;set.seed&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;12345&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Define the points at which we want to compute the function values (x values of the prediction points or test points), and the scale parameter for the covariance function &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\ell=1\inline&quot;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;x_predict &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;5&lt;/span&gt;,&lt;span class=&quot;dt&quot;&gt;len=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;50&lt;/span&gt;)
l &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We will use the squared exponential (also called radial basis or Gaussian, though it is not this that gives Gaussian process it’s name; any covariance function would do) as the covariance function, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\operatorname{cov}(X_i, X_j) = \exp\left(-\frac{(X_i - X_j)^2}{2 \ell ^ 2}\right)\inline&quot;/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;SE &amp;lt;- function(Xi,Xj, l) &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(-&lt;span class=&quot;fl&quot;&gt;0.5&lt;/span&gt; * (Xi - Xj) ^ &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; / l ^ &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)
cov &amp;lt;- function(X, Y) &lt;span class=&quot;kw&quot;&gt;outer&lt;/span&gt;(X, Y, SE, l)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;COV &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x_predict, x_predict)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Generate a number of functions from the process&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;values &amp;lt;- &lt;span class=&quot;kw&quot;&gt;mvrnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;rep&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;length=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(x_predict)), COV)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Reshape the data into long (tidy) form, listing x value, y value, and sample number&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x_predict, &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(values))
dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(dat, &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;kw&quot;&gt;head&lt;/span&gt;(dat)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;       x variable   value
1 -5.000       X1 -0.6450
2 -4.796       X1 -0.9227
3 -4.592       X1 -1.1587
4 -4.388       X1 -1.3277
5 -4.184       X1 -1.4139
6 -3.980       X1 -1.4103&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Plot the result&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;fig2a &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dat,&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x,&lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;value)) +
  &lt;span class=&quot;kw&quot;&gt;geom_rect&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;xmin=&lt;/span&gt;-&lt;span class=&quot;ot&quot;&gt;Inf&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;xmax=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;Inf&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ymin=&lt;/span&gt;-&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;ymax=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;fill=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;grey80&amp;quot;&lt;/span&gt;) +
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;group=&lt;/span&gt;variable)) +   &lt;span class=&quot;kw&quot;&gt;theme_bw&lt;/span&gt;() +
  &lt;span class=&quot;kw&quot;&gt;scale_y_continuous&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;lim=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;output, f(x)&amp;quot;&lt;/span&gt;) +
  &lt;span class=&quot;kw&quot;&gt;xlab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;input, x&amp;quot;&lt;/span&gt;)
fig2a&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8377/8591045456_0f9f7191d5_o.png&quot; alt=&quot;plot of draws from the null distribution&quot; /&gt;&lt;figcaption&gt;plot of draws from the null distribution&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h3 id=&quot;posterior-distribution-given-the-data&quot;&gt;Posterior distribution given the data&lt;/h3&gt;
&lt;p&gt;Imagine we have some data,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;obs &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;, -&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;, -&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;),
                  &lt;span class=&quot;dt&quot;&gt;y =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;,  &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;, -&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In general we aren’t interested in drawing from the prior, but want to include information from the data as well. We want the joint distribution of the observed values and the prior is:&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\begin{pmatrix} y_{\textrm{obs}} \\ y_{\textrm{pred}} \end{pmatrix} \sim \mathcal{N}\left( \mathbf{0}, \begin{bmatrix} cov(X_o,X_o) &amp;amp; cov(X_o, X_p) \\ cov(X_p,X_o) &amp;amp; cov(X_p, X_p) \end{bmatrix} \right)&quot; alt=&quot;\begin{pmatrix} y_{\textrm{obs}} \\ y_{\textrm{pred}} \end{pmatrix} \sim \mathcal{N}\left( \mathbf{0}, \begin{bmatrix} cov(X_o,X_o) &amp;amp; cov(X_o, X_p) \\ cov(X_p,X_o) &amp;amp; cov(X_p, X_p) \end{bmatrix} \right)&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;no-observation-noise&quot;&gt;No observation noise&lt;/h2&gt;
&lt;p&gt;Assuming the data are known without error and conditioning on the data, and given &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x \sim \mathcal{N}(0, cov(X_o, X_o))\inline&quot;/&gt;&lt;/span&gt;, then the conditional probability of observing our data is easily solved by exploiting the nice properties of Gaussians,&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x|y \sim \mathcal{N}\left(E,C\right)&quot; alt=&quot;x|y \sim \mathcal{N}\left(E,C\right)&quot; /&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?E = cov(X_p, X_o) cov(X_o,X_o)^{-1} y&quot; alt=&quot;E = cov(X_p, X_o) cov(X_o,X_o)^{-1} y&quot; /&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?C= cov(X_p, X_p) - cov(X_p, X_o) cov(X_o,X_o)^{-1} cov(X_o, X_p)&quot; alt=&quot;C= cov(X_p, X_p) - cov(X_p, X_o) cov(X_o,X_o)^{-1} cov(X_o, X_p)&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;(We use &lt;code&gt;solve(M)&lt;/code&gt; which with no second argument will simply invert the matrix &lt;code&gt;M&lt;/code&gt;, but should use the Cholsky decomposition instead for better numerical stability)&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;cov_xx_inv &amp;lt;- &lt;span class=&quot;kw&quot;&gt;solve&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(obs$x, obs$x))
Ef &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x_predict, obs$x) %*% cov_xx_inv %*% obs$y
Cf &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x_predict, x_predict) - &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x_predict, obs$x)  %*% cov_xx_inv %*% &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(obs$x, x_predict)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now lets take 3 random samples from the posterior distribution,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;values &amp;lt;- &lt;span class=&quot;kw&quot;&gt;mvrnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;, Ef, Cf)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and plot our solution (mean, 2 standard deviations, and the ranom samples.)&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x_predict, &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(values))
dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(dat, &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;)

fig2b &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dat,&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x,&lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;value)) +
  &lt;span class=&quot;kw&quot;&gt;geom_ribbon&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;NULL&lt;/span&gt;, 
              &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x_predict, &lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;Ef, &lt;span class=&quot;dt&quot;&gt;ymin=&lt;/span&gt;(Ef&lt;span class=&quot;dv&quot;&gt;-2&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(Cf))), &lt;span class=&quot;dt&quot;&gt;ymax=&lt;/span&gt;(Ef&lt;span class=&quot;dv&quot;&gt;+2&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(Cf)))),
              &lt;span class=&quot;dt&quot;&gt;fill=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;grey80&amp;quot;&lt;/span&gt;) +
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;color=&lt;/span&gt;variable)) + &lt;span class=&quot;co&quot;&gt;#REPLICATES&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;NULL&lt;/span&gt;,&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x_predict,&lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;Ef), &lt;span class=&quot;dt&quot;&gt;size=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) + &lt;span class=&quot;co&quot;&gt;#MEAN&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;obs,&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x,&lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;y)) +  &lt;span class=&quot;co&quot;&gt;#OBSERVED DATA&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;scale_y_continuous&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;lim=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;output, f(x)&amp;quot;&lt;/span&gt;) +
  &lt;span class=&quot;kw&quot;&gt;xlab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;input, x&amp;quot;&lt;/span&gt;)
fig2b&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8237/8591045344_918138a53a_o.png&quot; alt=&quot;plot of draws from the posterior, with no proces noise&quot; /&gt;&lt;figcaption&gt;plot of draws from the posterior, with no proces noise&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;additive-noise&quot;&gt;Additive noise&lt;/h2&gt;
&lt;p&gt;In general the model may have process error, and rather than observe the deterministic map &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?f(x)\inline&quot;/&gt;&lt;/span&gt; we only observe &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y = f(x) + \varepsilon\inline&quot;/&gt;&lt;/span&gt;. Let us assume for the moment that &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\varepsilon\inline&quot;/&gt;&lt;/span&gt; are independent, normally distributed random variables with variance &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\sigma_n^2\inline&quot;/&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;sigma.n &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.25&lt;/span&gt;
cov_xx_inv &amp;lt;- &lt;span class=&quot;kw&quot;&gt;solve&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(obs$x, obs$x) + sigma.n^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt; * &lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(obs$x)))
Ef &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x_predict, obs$x) %*% cov_xx_inv %*% obs$y
Cf &amp;lt;- &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x_predict, x_predict) - &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(x_predict, obs$x)  %*% cov_xx_inv %*% &lt;span class=&quot;kw&quot;&gt;cov&lt;/span&gt;(obs$x, x_predict)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now lets take 3 random samples from the posterior distribution,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;values &amp;lt;- &lt;span class=&quot;kw&quot;&gt;mvrnorm&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;, Ef, Cf)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and plot&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x_predict, &lt;span class=&quot;kw&quot;&gt;t&lt;/span&gt;(values))
dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(dat, &lt;span class=&quot;dt&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;)

fig2c &amp;lt;- &lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(dat,&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x,&lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;value)) +
  &lt;span class=&quot;kw&quot;&gt;geom_ribbon&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;NULL&lt;/span&gt;, 
              &lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x_predict, &lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;Ef, &lt;span class=&quot;dt&quot;&gt;ymin=&lt;/span&gt;(Ef&lt;span class=&quot;dv&quot;&gt;-2&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(Cf))), &lt;span class=&quot;dt&quot;&gt;ymax=&lt;/span&gt;(Ef&lt;span class=&quot;dv&quot;&gt;+2&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;sqrt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;diag&lt;/span&gt;(Cf)))),
              &lt;span class=&quot;dt&quot;&gt;fill=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;grey80&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;co&quot;&gt;# Var&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;color=&lt;/span&gt;variable)) + &lt;span class=&quot;co&quot;&gt;#REPLICATES&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;NULL&lt;/span&gt;,&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x_predict,&lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;Ef), &lt;span class=&quot;dt&quot;&gt;size=&lt;/span&gt;&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) + &lt;span class=&quot;co&quot;&gt;#MEAN&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;geom_point&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;data=&lt;/span&gt;obs,&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x=&lt;/span&gt;x,&lt;span class=&quot;dt&quot;&gt;y=&lt;/span&gt;y)) +  &lt;span class=&quot;co&quot;&gt;#OBSERVED DATA&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;scale_y_continuous&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;lim=&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(-&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;,&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;output, f(x)&amp;quot;&lt;/span&gt;) +
  &lt;span class=&quot;kw&quot;&gt;xlab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;input, x&amp;quot;&lt;/span&gt;)
fig2c&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8380/8589945565_174d4ac88a_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-16&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-16&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Note that unlike the previous case, the posterior no longer collapses completely around the neighborhood of the test points.&lt;/p&gt;
&lt;p&gt;We can also compute the likelihood (and marginal likelihood over the prior) of the data directly from the inferred multivariate normal distribution, which can allow us to tune the hyperparameters such as the characteristic length scale &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\ell\inline&quot;/&gt;&lt;/span&gt; and the observation noise &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\sigma_n\inline&quot;/&gt;&lt;/span&gt;. The most obvious approach would be to do so by maximum likelihood, giving point estimates of the hyper-parameters, though presumably we could be Bayesian about these as well.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Gaussian processes</title>
   <link href="/2012/10/16/gaussian-processes.html"/>
   <updated>2012-10-16T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/16/gaussian-processes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;ul&gt;
&lt;li&gt;Great methods tutorial/overview with Steve. Now getting up to speed on background reading in both Gaussian processes and embedding dimensions.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Will also want to look into basis approximations for SDP acceleration.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;gaussian-processes&quot;&gt;Gaussian Processes&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;New project, New tag: nonparametric-bayes, and &lt;a href=&quot;https://github.com/cboettig/nonparametric-bayes&quot;&gt;associated github repostitory&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;reading&quot;&gt;Reading&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Rasmussen &amp;amp; Williams (2006) 2nd ed, &lt;a href=&quot;http://www.GaussianProcess.org/gpml&quot;&gt;full text avialable online&lt;/a&gt;. read Ch 1 &amp;amp; 2.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Can be thought of as a Bayesian version of Support Vector Machines&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Who knew? Working through basic regression scenarios.&lt;/p&gt;
&lt;p&gt;Also reading:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Deisenroth, M. P., Rasmussen, C. E., &amp;amp; Peters, J. (2009). Gaussian process dynamic programming. Neurocomputing, 72(7-9), 1508–1524. doi:10.1016/j.neucom.2008.12.019&lt;/li&gt;
&lt;li&gt;Kocijan, J., &amp;amp; Girard, A. (2005). Dynamic systems identification with Gaussian processes. … of Dynamical Systems. doi:10.1080/13873950500068567&lt;/li&gt;
&lt;li&gt;Turner, R. (2010). State-space inference and learning with Gaussian processes. Proceedings of 13th …, 868–875.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;r-support&quot;&gt;R support:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://rss.acs.unt.edu/Rdoc/library/kernlab/html/gausspr.html&quot;&gt;gausspr&lt;/a&gt;, see also the &lt;a href=&quot;http://cran.at.r-project.org/web/packages/kernlab/vignettes/kernlab.pdf&quot;&gt;package vignette&lt;/a&gt; (From the core team, probably a reasonable starting point).&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://cran.r-project.org/web/packages/gptk/&quot;&gt;gptk&lt;/a&gt; (crude choice, poor software development practices)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://cran.r-project.org/web/packages/mlegp/vignettes/mlegp.pdf&quot;&gt;mlegp&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.r-bloggers.com/gaussian-process-regression-with-r/&quot;&gt;manually&lt;/a&gt; (e.g. for learning rather than performance)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;embedding-dimensions&quot;&gt;Embedding dimensions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;[Taken’s Theorem](http://en.wikipedia.org/wiki/Takens’_theorem) But how about the stochastic case?&lt;/li&gt;
&lt;li&gt;Convergent cross-mapping paper, &lt;a href=&quot;http://dx.doi.org/10.1126/science.1227079&quot;&gt;Sugihara et al. 2012&lt;/a&gt;, recently in &lt;em&gt;Science&lt;/em&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Stochastic Takens: perhaps see &lt;a href=&quot;http://www.ucl.ac.uk/cnda/about/papers/Random_Embed.pdf&quot;&gt;Stark et al 2003&lt;/a&gt;, doi:10.1007/s00332-003-0534-4&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;ropensci&quot;&gt;rOpenSci&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Checked &lt;code&gt;ritis&lt;/code&gt;, Scott submitted to CRAN&lt;/li&gt;
&lt;li&gt;More requests for increased functionality on &lt;code&gt;rfishbase&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Contact with Roy about developing an API for FishBase. Contacted Deng&lt;/li&gt;
&lt;li&gt;&lt;code&gt;httr&lt;/code&gt; 0.2 is on CRAN! Updated &lt;code&gt;rfigshare&lt;/code&gt; dependency, plan to release soon.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;notebook&quot;&gt;Notebook&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Contacted Ben about documentation and use of EML.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Posted updated semantic notebook&lt;/li&gt;
&lt;li&gt;Hmm, FOAF person types don’t seem to contain enough data to be valid Person objects according to Google Rich Snippets. Unfortunately this cannot be easily solved by &lt;a href=&quot;http://answers.semanticweb.com/questions/19200&quot;&gt;mixing “Person” types&lt;/a&gt;. Note that &lt;a href=&quot;http://answers.semanticweb.com/questions/3667/can-dctermsrightsholder-be-used-with-foafperson&quot;&gt;Dublin Core and FOAF agree&lt;/a&gt; on what a person/agent is, but it seems data-vocabulary.org rdf does not?&lt;/li&gt;
&lt;li&gt;Tools for discovery and navigating ontologies? http://www.ebi.ac.uk/ontology-lookup/&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Semantic Lab Notebook</title>
   <link href="/2012/10/14/semantic-lab-notebook.html"/>
   <updated>2012-10-14T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/14/semantic-lab-notebook</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;As the lab notebook grows, to make the maximum use of content it would be particularly useful to maximize the ability for a computer to understand the content, allowing us to identify, manipulate, and connect data using scripts and software. This is the concept of &lt;em&gt;linked data&lt;/em&gt;, or a &lt;em&gt;semantic notebook&lt;/em&gt;. I have explored this this idea before in the context of a &lt;a href=&quot;2011/05/08/building-a-semantic-notebook.html&quot;&gt;wordpress-based platform&lt;/a&gt;, but now that Jekyll has let me strip away some of the abstraction of Wordpress it seems a good time to revisit this idea.&lt;/p&gt;
&lt;h2 id=&quot;semantics-in-html5&quot;&gt;Semantics in HTML5&lt;/h2&gt;
&lt;p&gt;Already the notebook is written in HTML5, which has considerable semantic structure compared to it’s predecessors. HTML5 introduces the structural elements&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;article&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;footer&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;that intuitively define the organization of an page, setting off the important content from the window-dressing. HTML5 also defines inline elements &lt;code&gt;&amp;lt;time&amp;gt;&lt;/code&gt; (see the links in Caveats), and &lt;code&gt;&amp;lt;mark&amp;gt;&lt;/code&gt;, and the existing tags for metadata, which let us specify &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt;, and basic &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tags for metadata such as author, &lt;code&gt;&amp;lt;meta name=&amp;quot;author&amp;quot; content=&amp;quot;Author Name&amp;quot;&amp;gt;&lt;/code&gt;, encoding, description, and keywords. Links &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; use the &lt;code&gt;rel&lt;/code&gt; attribute to describe the link target. Though one can write anything at all in this text, HTML5 defines a small vocabulary with recognized meaning, some old, some new, such as &lt;code&gt;&amp;lt;a rel=&amp;quot;tag&amp;quot;&lt;/code&gt;, &lt;code&gt;rel=&amp;quot;license&amp;quot;&lt;/code&gt; as well as the older &lt;code&gt;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;style.css&amp;quot;&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot;&lt;/code&gt;. &lt;a href=&quot;http://diveintohtml5.info/semantics.html&quot;&gt;Here is a great overview of the semantics in HTML5&lt;/a&gt;, with a bit more about the available . To expand our vocabulary beyond these elements, however, we will need more tools.&lt;/p&gt;
&lt;h2 id=&quot;linked-data&quot;&gt;Linked Data&lt;/h2&gt;
&lt;p&gt;W3C confusingly provides two standards for formally defining semantic content using an external vocabulary or ontology. The first is microdata, introduced as a simpler alternative to the second, RDFa, an HTML-adaptation of the RDF XML standard (originally developed for the now-defunct XHTML 2.0).&lt;/p&gt;
&lt;h3 id=&quot;microdata&quot;&gt;Microdata&lt;/h3&gt;
&lt;p&gt;Microdata introduces new attributes into HTML tags like &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;. The first of these is &lt;code&gt;itemtype&lt;/code&gt;, which points to an external resource such as schema.org to define the vocabulary. To have this vocabulary apply to child elements, we just add the attribute &lt;code&gt;itemscope&lt;/code&gt;. Then we can set the value of attribute &lt;code&gt;itemprop&lt;/code&gt; in this or following elements to give it semantically defined meaning, such as&lt;/p&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;&lt;span class=&quot;kw&quot;&gt;&amp;lt;div&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; itemscope itemtype=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://data-vocabulary.org/Person&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;&amp;lt;h1&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; itemprop=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;Carl Boettiger&lt;span class=&quot;kw&quot;&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; itemprop=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;url&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://www.carlboettiger.info&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;http://carlboettiger.info&lt;span class=&quot;kw&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;&amp;lt;img&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; itemprop=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;photo&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; src=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;https://en.gravatar.com/userimage/12904315/7edea703b826fbbe07f2ae4d95b8416b.jpg?16&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;where the terms such as &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;url&lt;/code&gt; have precise meanings attached to “Person”, as specified at the “http://data-vocabulary.org/Address”. This ability to point to an external vocabulary is really the key concept of linked data. In the spirit of HTML5, microdata is much simpler than RDFa, but also more limited. &lt;a href=&quot;http://manu.sporny.org/2011/uber-comparison-rdfa-md-uf/&quot;&gt;Here is an excellent comparison&lt;/a&gt;, but for our purposes we will use RDFa as it is more common in academic use and will more seamlessly allow us to use academic ontologies. (While microdata has a clear mapping to RDF, it is not clear that any ontology that can be expressed in RDF can also be expressed in microdata).&lt;/p&gt;
&lt;h3 id=&quot;rdfa&quot;&gt;RDFa&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;http://www.w3.org/TR/xhtml-rdfa-primer/&quot;&gt;RDFa&lt;/a&gt; can be written in a very similar manner. The &lt;code&gt;itemprop&lt;/code&gt; attribute is replaced by the &lt;code&gt;property&lt;/code&gt; attribute, and &lt;code&gt;vocab&lt;/code&gt; replaces &lt;code&gt;itemtype&lt;/code&gt; and automatically implies &lt;code&gt;itemscope&lt;/code&gt; to child nodes.&lt;/p&gt;
&lt;pre class=&quot;sourceCode html&quot;&gt;&lt;code class=&quot;sourceCode html&quot;&gt;&lt;span class=&quot;kw&quot;&gt;&amp;lt;div&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; vocab=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://xmlns.com/foaf/0.1/&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; typeof=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;Person&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;&amp;lt;h1&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;Carl Boettiger&lt;span class=&quot;kw&quot;&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;&amp;lt;a&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;homepage&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; href=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;http://www.carlboettiger.info&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;&amp;gt;&lt;/span&gt;http://carlboettiger.info&lt;span class=&quot;kw&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;kw&quot;&gt;&amp;lt;img&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; property=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;depiction&amp;quot;&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt; src=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;https://en.gravatar.com/userimage/12904315/7edea703b826fbbe07f2ae4d95b8416b.jpg?16&amp;quot;&lt;/span&gt;&lt;span class=&quot;kw&quot;&gt;/&amp;gt;&lt;/span&gt;
 &lt;span class=&quot;kw&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We could have used only the &lt;code&gt;property&lt;/code&gt; attribute along with the complete URI to the term definition instead of this structure. &lt;code&gt;typeof&lt;/code&gt; indicates that the child elements are all of the same type (in this case, all belong to the same “Person”). If we were omitting &lt;code&gt;vocab&lt;/code&gt; and writing out all URIs, we would have had &lt;code&gt;&amp;lt;div typeof=&amp;quot;http://xmlns.com/foaf/0.1/Person&amp;quot;&amp;gt;&lt;/code&gt; as well. In RDFa, we also have the &lt;code&gt;resource&lt;/code&gt; attribute, which allows us to specify a URI for the element being described. This could be a relative or absolute URL. If the object is a link, using &lt;code&gt;resource&lt;/code&gt; is not necessary, and the property is taken to describe the URL given in &lt;code&gt;href&lt;/code&gt; or &lt;code&gt;src&lt;/code&gt; rather than the anchor text.&lt;/p&gt;
&lt;p&gt;Two older options lie at either extreme: the most basic is the older technique of &lt;a href=&quot;http://microformats.org/wiki/html5&quot;&gt;microformatting&lt;/a&gt;, basically relying on standard &lt;code&gt;class&lt;/code&gt; and &lt;code&gt;rel&lt;/code&gt; attributes to convey semantic information. Simple and without new attributes, but probably too limited for our purposes so we won’t concern ourselves with it further. The other venerable approach is serve the page as XHTML, which renders in the browser in much the same way but can be parsed by a machine as XML, with all the power and extensibility that presents. Unlike earlier HTML standards, HTML5 is already valid XML (already “serialized”), so the same page can be served in either format (earlier specs were SGML, standardized general markup languages, of which XML is just a subset). To allow parsing of the HTML5 pages as either type (see &lt;a href=&quot;http://en.wikipedia.org/wiki/Polyglot_markup&quot;&gt;polyglot&lt;/a&gt;), we need only add the language and namespace to the opening &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt; tag,&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;html lang=&amp;quot;en&amp;quot; xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot; xml:lang=&amp;quot;en&amp;quot;&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;caveats&quot;&gt;Caveats&lt;/h3&gt;
&lt;p&gt;An essential caveat is that these are all new approaches which may not render well in legacy browsers, particularly Windows Internet Explorer. Some of these, like recognizing and styling the HTML5 semantic elements in IE, can be addressed in CSS, for which Twitter Bootstrap does a decent job. Another caveat The HTML5 spec has not been finalized, and some things are still in flux, as the &lt;a href=&quot;http://html5doctor.com/time-and-data-element/&quot;&gt;removal&lt;/a&gt; and &lt;a href=&quot;http://www.brucelawson.co.uk/2012/best-of-time/&quot;&gt;reinstatement&lt;/a&gt; of the &lt;code&gt;&amp;lt;time&amp;gt;&lt;/code&gt; element illustrates.&lt;/p&gt;
&lt;h3 id=&quot;useful-tools-for-checking-implementation&quot;&gt;Useful tools for checking implementation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://validator.w3.org/nu&quot;&gt;W3C HTML5 Validator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.google.com/webmasters/tools/richsnippets&quot;&gt;Google rich snippets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://sparql.captsolo.net/browser/browser.py?url=http://www.w3.org/2007/08/pyRdfa/extract?uri=http://www.carlboettiger.info&quot;&gt;RDF extraction tool&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;scholarly-semantic-markup-for-the-notebook&quot;&gt;Scholarly Semantic Markup for the Notebook&lt;/h1&gt;
&lt;p&gt;Now that we’ve familiarized ourselves with the options, it’s time to see what semantic content we can implement.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr class=&quot;header&quot;&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;Content/Data&lt;/th&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;Example types&lt;/th&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;Links to Potential vocabularies&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Page structure&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://diveintohtml5.info/semantics.html&quot;&gt;HTML5&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Post metadata&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;keywords, timestamps&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://schema.org/BlogPosting&quot;&gt;Schema.org microdata&lt;/a&gt; or &lt;a href=&quot;http://purl.org/terms/dc&quot;&gt;Dublin Core&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Author metadata&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Name, contact, networks,&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://xmlns.com/foaf/0.1/&quot;&gt;FOAF&lt;/a&gt;, &lt;a href=&quot;http://purl.org/terms/dc&quot;&gt;Dublin Core&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;interests, publications)&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Licenses&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;CC0&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://creativecommons.org/ns&quot;&gt;CreativeCommons&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Citations&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;bib info, reason for citing&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://purl.org/spar/cito&quot;&gt;CiTO&lt;/a&gt;, &lt;a href=&quot;http://purl.org/spar/biro&quot;&gt;BiRO&lt;/a&gt;,&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://purl.org/ontologies/bibo&quot;&gt;bibo&lt;/a&gt;, &lt;a href=&quot;http://purl.org/terms/dc&quot;&gt;Dublin Core&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Taxonomic data&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;species names&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://rs.tdwg.org/dwc/terms/index.htm&quot;&gt;Darwin Core&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;Ecological data&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;measurements, units, etc&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;del&gt;&lt;a href=&quot;http://knb.ecoinformatics.org/software/eml/&quot;&gt;EML&lt;/a&gt;&lt;/del&gt; &lt;a href=&quot;http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl&quot;&gt;OBOE&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;In another entry I will try and highlight where and what semantic content I have added (work in progress), with examples of each vocabulary. The first four types are relatively static content that can be easily woven into the Jekyll template files. Using Jekyll &amp;amp; Liquid to pull in template information from the &lt;code&gt;_config.yaml&lt;/code&gt; should help avoid repetitive entry and make updating the linked data easier. The last three are entry-specific content, and will be more challenging. I hope to add semantic support to &lt;a href=&quot;https://github.com/cboettig/knitcitations&quot;&gt;knitcitations&lt;/a&gt;, including the option for CiTO types, which should make entry of citation data quick and easy (&lt;a href=&quot;http://stackoverflow.com/questions/12867586&quot;&gt;SO question illustrating semantic citation&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;The last two are much richer, specific vocabularies. For the moment, it might be best to use these to give more precise meaning to tags, which are already used as metadata on posts. This would allow posts to be still created in simple markdown without the burden of adding in lines of RDFa and cluttering the markup. Meanwhile full datasets provided in EML are likely to live as separate files, rather than as a random table in the middle of a notebook entry.&lt;/p&gt;
&lt;p&gt;As always, feedback, corrections or suggestions are appreciated!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/10/11/notes.html"/>
   <updated>2012-10-11T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/11/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;ews-review&quot;&gt;EWS review&lt;/h2&gt;
&lt;p&gt;Composing a simple EWS review highlighting where signals are and are not expected and what this means for the system dynamics. With Alan and Noam. See manuscript repository, &lt;a href=&quot;https://github.com/cboettig/ews-review&quot;&gt;cboettig/ews-review&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;pdg-control&quot;&gt;pdg control&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Does the matrix formulation fail to account for the treating profits as a function of realized harvest and true stock size rather than quota and measured size?&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;notebook&quot;&gt;notebook&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;fixing some inline equations &lt;a href=&quot;https://github.com/cboettig/labnotebook/commit/262b8d284b34162780ab5e62402a2763aa4e6a09&quot;&gt;04:34 pm 2012/10/09&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Updated Readme &lt;a href=&quot;https://github.com/cboettig/labnotebook/commit/789ba68b31a87e2427a67bab58312de162e9bc96&quot;&gt;02:57 pm 2012/10/09&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;scicomp-discussions-on-reproducibility&quot;&gt;scicomp discussions on reproducibility&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Asked about &lt;a href=&quot;http://scicomp.stackexchange.com/questions/3462/increasing-the-archival-longevity-of-code&quot;&gt;longevity of code&lt;/a&gt; (re: data managment plan)&lt;/li&gt;
&lt;li&gt;Replied to best practices for &lt;a href=&quot;http://scicomp.stackexchange.com/questions/661/how-to-link-code-to-publications/3463#3463&quot;&gt;linking code to publications&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;discussionstweets&quot;&gt;discussions/tweets&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;@hylopsar @mwpennell thanks - I always find it tricky to explain conditional probabilities clearly, so that’s nice to hear&lt;img src=&quot;http://twitter.com/cboettig/statuses/256208169267785731&quot; alt=&quot;06:42 2012/10/10&quot; /&gt;&lt;/li&gt;
&lt;li&gt;Nice paper by +Matt Pennell, Saver &amp;amp;@lukejharmon on biases in inferring early bursts of evolution. http://t.co/ltRAQcCM&lt;a href=&quot;http://twitter.com/cboettig/statuses/256119709290860546&quot;&gt;12:51 2012/10/10&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;@figshare thoughts on supporting code and relevant licenses? http://t.co/042Zreni&lt;a href=&quot;http://twitter.com/cboettig/statuses/256096537367674880&quot;&gt;11:19 2012/10/10&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;my answer to: How to link code to publications http://t.co/9bsazYSj&lt;a href=&quot;http://twitter.com/cboettig/statuses/256080435346546688&quot;&gt;10:15 2012/10/10&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Know any tips for increasing the archival longevity of scientific code? http://t.co/PPdzsxfK&lt;a href=&quot;http://twitter.com/cboettig/statuses/256068512227926016&quot;&gt;09:27 2012/10/10&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Thanks! RT @noamross Out now in PRSB: Early warning signals and the prosecutor’s fallacy, by @cboettig &amp;amp; Alan Hastings http://t.co/dAq6tlmC&lt;a href=&quot;http://twitter.com/cboettig/statuses/256067344357548032&quot;&gt;09:23 2012/10/10&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>My Prosecutor's Fallacy paper and other recent warning signals literature</title>
   <link href="/2012/10/10/prosecutors-fallacy.html"/>
   <updated>2012-10-10T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/10/prosecutors-fallacy</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;My recent paper with Alan Hastings, “Early warning signals and the prosecutor’s fallacy”, is now &lt;a href=&quot;http://dx.doi.org/10.1098/rspb.2012.2085&quot;&gt;out in PRSB&lt;/a&gt;. An open access preprint can be found on the (&lt;a href=&quot;http://arxiv.org/abs/1210.1204&quot;&gt;arXiv&lt;/a&gt;) and accompanying (&lt;a href=&quot;https://github.com/cboettig/earlywarning/blob/prosecutor/inst/examples/fallacy.md&quot;&gt;source code&lt;/a&gt;) for the analysis can be found on Github.&lt;/p&gt;
&lt;h2 id=&quot;recent-papers-in-early-warning-signals&quot;&gt;Recent papers in early warning signals&lt;/h2&gt;
&lt;p&gt;This invistigation is in a very similar spirit to two other recent papers on the subject. Kéfi et al. addresses a different kind of false positive for early warning signals, arising in systems approaching other transitions or bifurcations than the intended culprit, the saddle-node bifurcation. Peretti and Munch address the flip side, in which detection fails when it should work due to commonly-observed levels of noise.&lt;/p&gt;
&lt;p&gt;Model-based approaches are clearly on the rise (following my own 2012 paper in PRSI and Lade and Gross 2012), with Brock and Carpenter (2012) putting forward a very similar model, and Ives &amp;amp; Dakos (2012) bringing in temporally heterogenous ARMA models.&lt;/p&gt;
&lt;p&gt;Unfortunately such model-based approaches are too new to make it into either of the recent review-like comparisons of existing approaches to a common set of simulated data (Dakos et al. 2012) or empirical data (Lindegren et al. 2012).&lt;/p&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Boettiger, C., &amp;amp; Hastings, A. (2012). Early warning signals and the prosecutor’s fallacy. Proceedings of the Royal Society B: Biological Sciences, (October). doi:10.1098/rspb.2012.2085&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Kéfi, S., Dakos, V., Scheffer, M., Van Nes, E. H., &amp;amp; Rietkerk, M. (2012). Early warning signals also precede non-catastrophic transitions. Oikos, (June), no–no. doi:10.1111/j.1600-0706.2012.20838.x&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Perretti, C. T., &amp;amp; Munch, S. B. (2012). Regime shift indicators fail under noise levels commonly observed in ecological systems. Ecological Applications, 22(6), 1772–1779. doi:10.1890/11-0161.1&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Boettiger, Carl, &amp;amp; Hastings, A. (2012). Quantifying limits to detection of early warning for critical transitions. Journal of The Royal Society Interface, 9(75), 2527 – 2539. doi:10.1098/rsif.2012.0125&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lade, S. J., &amp;amp; Gross, T. (2012). Early Warning Signals for Critical Transitions: A Generalized Modeling Approach. (M. Pascual, Ed.)PLoS Computational Biology, 8(2), e1002360. doi:10.1371/journal.pcbi.1002360* Brock, W. A., &amp;amp; Carpenter, S. R. (2012). Early Warnings of Regime Shift When the Ecosystem Structure Is Unknown. (R. V. Solé, Ed.)PLoS ONE, 7(9), e45586. doi:10.1371/journal.pone.0045586&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ives, A., &amp;amp; Dakos, V. (2012). Detecting dynamical changes in nonlinear time series using locally linear state-space models. Ecosphere, 3(June). Retrieved from http://www.esajournals.org/doi/abs/10.1890/ES11-00347.1&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dakos, V., Carpenter, S. R., Brock, W. a., Ellison, A. M., Guttal, V., Ives, A. R., Kéfi, S., et al. (2012). Methods for Detecting Early Warnings of Critical Transitions in Time Series Illustrated Using Simulated Ecological Data. (B. Yener, Ed.)PLoS ONE, 7(7), e41010. doi:10.1371/journal.pone.0041010&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lindegren, M., Dakos, V., Gröger, J. P., Gårdmark, A., Kornilovs, G., Otto, S. a., &amp;amp; Möllmann, C. (2012). Early Detection of Ecosystem Regime Shifts: A Multiple Method Evaluation for Management Application. (S. Thrush, Ed.)PLoS ONE, 7(7), e38410. doi:10.1371/journal.pone.0038410&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Data Management Plan</title>
   <link href="/2012/10/09/data-management-plan.html"/>
   <updated>2012-10-09T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/09/data-management-plan</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;Writing out a &lt;a href=&quot;#&quot; rel=&quot;http://purl.org/spar/fabio/DataMangementPlan&quot;&gt;data management plan&lt;/a&gt; for myself. Suggestions and feedback welcome.&lt;/p&gt;
&lt;h2 id=&quot;data-types-and-structure&quot;&gt;Data Types and Structure&lt;/h2&gt;
&lt;p&gt;All source code, documentation, scripts and data for the analyses performed in the course of this research shall be maintained in a digital compendium using the &lt;a href=&quot;http://cran.r-project.org/doc/manuals/R-exts.html#Package-structure&quot;&gt;R package structure&lt;/a&gt; as recommended in Gentleman and Lang (2007). The progress and results of this research shall be regularly chronicled in an electronic lab notebook, maintained openly at &lt;a href=&quot;http://www.carlboettiger.info/lab-notebook.html&quot;&gt;carlboettiger.info/lab-notebook.html&lt;/a&gt;. Figures and other results are maintained with the source-code required to reproduce them by writing these analyses using &lt;a href=&quot;http://yihui.name/knitr&quot;&gt;knitr&lt;/a&gt; dynamic documentation.&lt;/p&gt;
&lt;h2 id=&quot;data-acquisition-integrity-and-quality&quot;&gt;Data Acquisition, Integrity and Quality&lt;/h2&gt;
&lt;p&gt;The lab notebook is written and maintained in plain text (UTF-8) and rendered in HTML5. Likewise, the R package compendium will maintain all source code, scripts and documentation in plain-text (UTF-8) files. Plain-text files with standard encodings help retain compatibility independent of software. Both the notebook entries and the compendium will be maintained in unique &lt;a href=&quot;http://git-scm.com/&quot;&gt;git&lt;/a&gt; repositories.&lt;/p&gt;
&lt;p&gt;Git repositories use unique SHA hashes to protect against corruption. Synchronized backups of the git repositories are maintained on local and remote servers (RAID 6) to protect against hardware failures, as well as on the public international software repository, Github &lt;a href=&quot;https://github.com/cboettig&quot;&gt;github.com/cboettig&lt;/a&gt;. Version history preserves a time-line of changes and protects against user error.&lt;/p&gt;
&lt;p&gt;Archival copies of notebook entries shall be published annually to &lt;a href=&quot;http://figshare.com&quot;&gt;figshare&lt;/a&gt; where they are assigned DOIs and preserved by the &lt;a href=&quot;http://www.clockss.org/clockss/Home&quot;&gt;CLOCKSS&lt;/a&gt; geopolitically distributed 12 node global archive. Likewise an archival copy of the R compendium shall be published to figshare at the time of each peer-reviewed publication.&lt;/p&gt;
&lt;p&gt;Any data produced by simulations used in these analyses will be archived accordingly in the compendium. Any data associated with a peer-reviewed publication will be deposited in plain text csv files in the &lt;a href=&quot;http://datadryad.org/&quot;&gt;Dryad digital repository&lt;/a&gt; for the biosciences, unless provided by a third party whose terms of use forbid this. No generation of empirical data is anticipated.&lt;/p&gt;
&lt;h2 id=&quot;rights-management-dissemination&quot;&gt;Rights Management &amp;amp; Dissemination&lt;/h2&gt;
&lt;p&gt;All products generated by this research will be licensed under permissive licenses supporting reuse, re-distribution, and derivatives for free for any purpose without request from a major online repository; Table 1.&lt;/p&gt;
&lt;table&gt;
&lt;caption&gt;Licenses reflect the &lt;a href=&quot;http://pantonprinciples.org/&quot;&gt;Panton Principles&lt;/a&gt; for open data and the &lt;a href=&quot;http://sciencecodemanifesto.org/&quot;&gt;Science Code Manifesto&lt;/a&gt;. Distribution uses internationally recognized and freely accessible public repositories best suited for the dissemination of each product.&lt;/caption&gt;
&lt;thead&gt;
&lt;tr class=&quot;header&quot;&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;Product&lt;/th&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;License&lt;/th&gt;
&lt;th style=&quot;text-align: left;&quot;&gt;Distribution&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;publications&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://creativecommons.org/licenses/by/3.0/&quot;&gt;cc-by&lt;/a&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://arxiv.org&quot;&gt;arXiv&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;software&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/BSD_licenses&quot;&gt;FreeBSD&lt;/a&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://github.com/cboettig&quot;&gt;Github&lt;/a&gt;, &lt;a href=&quot;http://figshare.com&quot;&gt;figshare&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;data&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://creativecommons.org/publicdomain/zero/1.0/&quot;&gt;cc-zero&lt;/a&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://datadryad.org&quot;&gt;Dryad&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;research notebook&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://creativecommons.org/publicdomain/zero/1.0/&quot;&gt;cc-zero&lt;/a&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://github.com/cboettig/labnotebook&quot;&gt;Github&lt;/a&gt;, &lt;a href=&quot;http://figshare.com&quot;&gt;figshare&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Peer-reviewed publications will target preprint-friendly publishers and an author’s preprint will be posted on the arXiv under a Creative Commons Attribution license to facilitate access and distribution.&lt;/p&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;p&gt;Gentleman R and Temple Lang D (2007). “Statistical Analyses And Reproducible Research.” &lt;em&gt;Journal of Computational And Graphical Statistics&lt;/em&gt;, &lt;em&gt;16&lt;/em&gt;. ISSN 1061-8600, doi: 10.1198/106186007X178663&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Automated feeds in notebook entries</title>
   <link href="/2012/10/05/notes.html"/>
   <updated>2012-10-05T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/05/notes</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;Exploring the use of automated feeds in my notebook entries, which would make writing posts both faster and more complete. I had recently modified my Jekyll plugins to include commits on the day of the post. Consequently, I could add a bit of liquid code to any post, such as:&lt;/p&gt;
&lt;pre class=&quot;liquid&quot;&gt;&lt;code&gt;  {% octokit_commits pdg_control%}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(or even to the post template) and have the commit log for the specified repository automatically imported. While such liquid tags are very handy for pages that are otherwise static and generate their updated content on compile (e.g. my &lt;a href=&quot;lab-notebook.html&quot;&gt;lab-notebook homepage&lt;/a&gt;, this approach makes less sense for day-to-day entries (as Noam points out to me). For such entries, the content is already being composed from scratch, but is designed to be fixed once written. (In fact, that was one of the challenges in updating the plugin to pull in the commit log from the day of the post instead of the most recent updates to the repository). Generating this content for every post every time the site is build would be unnecessarily intensive, since it does not change. Further, I like to keep the post entries in pure markdown as much as possible. This makes the actual content not dependent on Jekyll (or on outside databases), which means the content displays fine by browsing the markdown, or using pandoc to compile to pdf or some other format.&lt;/p&gt;
&lt;p&gt;To get the same time-savings from automatic imports, I followed Noam’s suggestion and added a little wrapper around my ruby scripts that would import the text of a commit log using a few vi commands. vi, my editor of choice, makes calling arbitrary scripts really easy. In fact one can just write out the bash script command as a line on the editor, and hit &lt;code&gt;!!sh&lt;/code&gt;, which replaces the command with its output. So for this purpose I just type the command out into the entry like so,&lt;/p&gt;
&lt;pre class=&quot;sourceCode bash&quot;&gt;&lt;code class=&quot;sourceCode bash&quot;&gt;   commits.rb pdg_control today&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I get a listing the commits for that day (defaults to the current day if no day is given). Thanks to the &lt;code&gt;Chronic&lt;/code&gt; gem, the script recognizes a variety of &lt;a href=&quot;https://github.com/mojombo/chronic&quot;&gt;natural language commands&lt;/a&gt; for the time, such as “3 days ago”. This pulls in all commits made at any point on the day given. For more background, see my vim &lt;a href=&quot;http://stackoverflow.com/questions/12753302&quot;&gt;SO question&lt;/a&gt; to pass visual blocks to a function.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Solarized Colors with Twitter-Bootstrap?</title>
   <link href="/2012/10/02/solarized-colors.html"/>
   <updated>2012-10-02T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/02/solarized-colors</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;Trying out rendering my notebook using Ethan Schoonover’s Solarized color scheme. The solarized palette has been selected according to Ethan’s exacting &lt;a href=&quot;http://ethanschoonover.com/solarized#features&quot;&gt;standards&lt;/a&gt; for contrast, symmetry, and readability.&lt;/p&gt;
&lt;p&gt;My site CSS is built with &lt;a href=&quot;http://twitter.github.com/bootstrap/&quot;&gt;Twitter-Bootstrap&lt;/a&gt;, which uses LESS to generate CSS files. Normal CSS is valid LESS code too, but doesn’t have the concept of a variable. So changing colors in CSS requires changing each and every occurance of some hex colorcode. LESS just lets you define the color as a variable, such as &lt;code&gt;@red: #dc322f;&lt;/code&gt; or &lt;code&gt;@background: #fdf6e3;&lt;/code&gt;, and then use &lt;code&gt;@red&lt;/code&gt; or &lt;code&gt;@background&lt;/code&gt; throughout the CSS. It helps you avoid repetition in lots of other ways too, but having variables was enough to get me going.&lt;/p&gt;
&lt;p&gt;I mapped all the twitter-bootstrap color variables to the 16-color Solarized palette in my &lt;a href=&quot;https://github.com/cboettig/labnotebook/blob/master/assets/less/variables.less&quot;&gt;variables.less&lt;/a&gt; file. I wanted the ability to render the site with either the dark or light background schemes, which required customizing quite a few of the other Twitter Bootstrap LESS files – it seems Bootstrap was build with exclusively light backgrounds in mind. Solarized accent colors are chosen to provide identical contrast on either background, but the base gray colors are slightly different for light and dark. The Solarized palette indicates which colors are designed for body text, comments and secondary text, background highlights, and optionally, for emphasized content, as described in the &lt;a href=&quot;http://ethanschoonover.com/solarized#usage-development&quot;&gt;usage and development documentation&lt;/a&gt;. Overall it’s nice to have a new look to the site, but it has raised a couple questions on which I’d be happy to hear more opinions.&lt;/p&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Links in blue? yellow? Or a more subtle base color?&lt;/li&gt;
&lt;li&gt;Light or dark background prefered?&lt;/li&gt;
&lt;li&gt;Should code blocks be rendered in the inverse background scheme, or a matching one?&lt;/li&gt;
&lt;li&gt;Do the navbar colors work? should they come from the inverse scheme?&lt;/li&gt;
&lt;li&gt;Would a stronger contrast in colors be more readable?&lt;/li&gt;
&lt;li&gt;other reactions?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here are a few screenshots in the different themes, varying the codeblock colors as well:&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8182/8049035809_cbd35a6a8f_n.jpg&quot; /&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8455/8049041504_ef37c20a8d_n.jpg&quot; /&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8311/8049041556_c6c454b7b1_n.jpg&quot; /&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8315/8049041400_8de7a9ba94_n.jpg&quot; /&gt;
&lt;/figure&gt;
&lt;h3 id=&quot;challenges&quot;&gt;Challenges&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;My black icons in the footer and lab-notebook homepage do not render well in the dark theme.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Button text doesn’t render well in the dark theme&lt;/li&gt;
&lt;li&gt;My flickr-hosted figures render with a white background even if I generate transparent-background pngs, since flickr converts them to jpg.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;updates&quot;&gt;Updates&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;I have added a little javascript to allow the user to toggle the theme between dark and light (see &lt;a href=&quot;https://github.com/cboettig/labnotebook/blob/master/assets/js/switch-css.js&quot;&gt;switch-css.js&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Multiple Uncertainty</title>
   <link href="/2012/10/01/multiple-uncertainty.html"/>
   <updated>2012-10-01T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/10/01/multiple-uncertainty</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Let&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;y&lt;/code&gt; be measured stock size, subject to measurement error from true stock &lt;code&gt;x&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;q&lt;/code&gt; be harvest quota, subject to implementation error from actual harvest, &lt;code&gt;h&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Stock next year is also subject to stochastic growth shock &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?z_g\inline&quot;/&gt;&lt;/span&gt;, (note that &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?f\inline&quot;/&gt;&lt;/span&gt; will also depend on the harvest, &lt;code&gt;h&lt;/code&gt;, unless &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_t\inline&quot;/&gt;&lt;/span&gt; is taken as the escapement population, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x-h\inline&quot;/&gt;&lt;/span&gt;).&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_{t+1} = z_g f(x_t)&quot; alt=&quot;x_{t+1} = z_g f(x_t)&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In discrete space, let &lt;code&gt;X&lt;/code&gt; be a vector representing the probability distribution of having stock &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt; at time &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?t\inline&quot;/&gt;&lt;/span&gt;, restricted to some finite grid of dimension &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n\inline&quot;/&gt;&lt;/span&gt;. Let &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?P_g(x | \mu, \sigma_g)\inline&quot;/&gt;&lt;/span&gt; be the probability density function of the shock &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?z_g\inline&quot;/&gt;&lt;/span&gt; over states &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt;, given parameter &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\sigma\inline&quot;/&gt;&lt;/span&gt; and mean &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mu\inline&quot;/&gt;&lt;/span&gt;. We can write the distribution &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?X_{t+1}\inline&quot;/&gt;&lt;/span&gt; as the result of a matrix-vector product, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?X_{t+1} = \mathbb{F} X_t\inline&quot;/&gt;&lt;/span&gt; where the elements of F are given by&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?F_{ij} = P_g(x_i, f(x_j), \sigma_g)&quot; alt=&quot;F_{ij} = P_g(x_i, f(x_j), \sigma_g)&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbb{F}\inline&quot;/&gt;&lt;/span&gt; is also a function of the harvest level, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbb{F_h}\inline&quot;/&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;When we consider measurement uncertainty, we allow the vector &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\vec Y\inline&quot;/&gt;&lt;/span&gt; to represent the measured stock size, and the true stock size &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\vec X\inline&quot;/&gt;&lt;/span&gt; is a random variable distributed around it. In the discrete space we may represent this as &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?X = \mathbb{M} \vec Y\inline&quot;/&gt;&lt;/span&gt;, where &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?M\inline&quot;/&gt;&lt;/span&gt; is an &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n\inline&quot;/&gt;&lt;/span&gt; by &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?n\inline&quot;/&gt;&lt;/span&gt; grid representing the role of measurement uncertainty, &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?M_{ij} = P_m(x_i, x_j, \sigma_m)\inline&quot;/&gt;&lt;/span&gt;. The state equation now evolves in belief space,&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?Y_{t+1} = \mathbb{F}_h \mathbb{M} \vec Y_t&quot; alt=&quot;Y_{t+1} = \mathbb{F}_h \mathbb{M} \vec Y_t&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;If there is implementation uncertainty as well and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?f\inline&quot;/&gt;&lt;/span&gt; is a function of the escapement population (those remaining after a harvest &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt;), we can impliment this as an additional transition matrix &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?I_{ij} = P_i(x_i, x_j-h, \sigma_i)\inline&quot;/&gt;&lt;/span&gt;, and the state equation becomes&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?Y_{t+1} = \mathbb{F} \mathbb{M} \mathbb{I}_h \vec Y_t&quot; alt=&quot;Y_{t+1} = \mathbb{F} \mathbb{M} \mathbb{I}_h \vec Y_t&quot; /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Note that the implementation matrix is a function of the harvest level, so that we need a different matrix for each &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt;, whether or not we introduce measurement uncertainty (instead of a different &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\mathbb{F}\inline&quot;/&gt;&lt;/span&gt; matrix for each harvest as before.)&lt;/p&gt;
&lt;h2 id=&quot;results&quot;&gt;Results&lt;/h2&gt;
&lt;p&gt;Linked in the automatically generated commit log:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;
render table &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/582cc266eeda686ac42c9e1e652cc809b2f861f0&quot;&gt;10:43 pm 2013/05/18&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
farm run on writeup using the 50% NPV comparison level note that the asymmetric cases still not working, prossibly NAs induced by non-vector max/min functions… &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/7df3d5d6d1032ce549b5137e25ac3e29a88466b2&quot;&gt;10:41 pm 2013/05/18&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
&lt;p&gt;Provide a table of c2 values&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;also allow varying the comparison point. set to 50% npv &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/f8669a3267ecb61f28c66b1667fba4ac7161c23d&quot;&gt;09:21 pm 2013/05/18&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
writeup run using NPV apples-to-apples #35 &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/59dca5fc085b93c4f9f833562267b6bdc5a10a55&quot;&gt;06:23 pm 2013/05/17&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
Working out the Apples-to-Apples case based on total costs, #35 &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/84f59f6f9c271219c7f8f43d9d51153a2d87ffbe&quot;&gt;05:34 pm 2013/05/17&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
attempt to convert tex and comments to markdown &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/80a8169d55369e578d8955779eb3834846f8a24b&quot;&gt;09:34 pm 2013/05/13&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
Tex version with comments from Paul &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/fe204f0a3c15e1327abb010923710844dca71857&quot;&gt;09:33 pm 2013/05/13&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
generalize par uncertainty f &lt;a href=&quot;https://github.com/cboettig/pdg_control/commit/4a239336fd9f77fbff5b30bf1018d558052a7b74&quot;&gt;07:57 pm 2013/05/07&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Welcome to my Lab Notebook - Reloaded</title>
   <link href="/2012/09/28/Welcome-to-my-lab-notebook.html"/>
   <updated>2012-09-28T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/09/28/Welcome-to-my-lab-notebook</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;Welcome to my lab notebook, version 3.0. My &lt;a href=&quot;http://openwetware.org/wiki/User:Carl_Boettiger/Notebook&quot;&gt;original open lab notebooks&lt;/a&gt; began on the wiki platform &lt;a href=&quot;http://openwetware.org&quot;&gt;OpenWetWare&lt;/a&gt;, moved to a personally hosted Wordpress platform, and now run on a Jekyll-powered platform (&lt;a href=&quot;http://www.carlboettiger.info/README.html&quot;&gt;site-config&lt;/a&gt;), but the basic idea remains the same. For completeness, earlier entries from both platforms have been migrated here. Quoting from &lt;a href=&quot;http://www.carlboettiger.info/archives/211&quot;&gt;my original introduction&lt;/a&gt; to the Wordpress notebook:&lt;/p&gt;
&lt;blockquote&gt;
&lt;h2&gt;Disclaimer: Not a Blog&lt;/h2&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;http://www.flickr.com/photos/twid/3013680713/in/faves-cboettig/&quot;&gt;&lt;img src=&quot;http://farm4.staticflickr.com/3053/3013680713_cfcebbd403_t.jpg&quot; alt=&quot;floatright&quot; /&gt;&lt;/a&gt; Welcome to my open lab notebook. This is the active, permanent record of my scientific research, standing in place of the traditional paper bound lab notebook. The notebook is primarily a tool for me to &lt;em&gt;do&lt;/em&gt; science, not communicate it. I write my entries with the hope that they are intelligible to my future self; and maybe my collaborators and experts in my field. Only the occasional entry will be written for a more general audience. […] In these pages you will find not only thoughts and ideas, but references to the literature I read, the codes or manuscripts I write, derivations I scribble and graphs I create and mistakes I make. &lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;why-an-open-notebook-is-it-working&quot;&gt;Why an open notebook? Is it working?&lt;/h2&gt;
&lt;p&gt;My original introduction to the notebook from November 2010 dodged this question by suggesting the exercise was merely an experiment to see if any of the purported benefits or supposed risks were well-founded. Nearly three years in, can I draw any conclusions from this open notebook experiment?&lt;/p&gt;
&lt;p&gt;In that time, the notebook has seen six projects go from conception to &lt;a href=&quot;http://www.carlboettiger.info/vita.html&quot;&gt;publication&lt;/a&gt;, and a seventh founder on a null result (see &lt;a href=&quot;http://carlboettiger.info/tags.html#tribolium&quot;&gt;#tribolium&lt;/a&gt;). Several more projects continue to unfold. I have often worked on several projects simultaneously, and some projects branch off while others merge, making it difficult to capture all the posts associated with a single paper into a single tag or category. Of course not all ideas make it into the paper, but they remain captured in the notebook. I often return to my earlier posts for my own reference, and frequently pass links to particular entries to collaborators or other colleagues. On occasion I have pointed reviewers of my papers to certain entries discussing why we did &lt;code&gt;y&lt;/code&gt; instead of &lt;code&gt;x&lt;/code&gt;, and so forth. Both close colleagues and researchers I’ve never met have emailed me to follow up on something they had read in my notebook. This evidence suggests that the practice of open notebook science can faciliate both the performance and dissemination of research while remaining compatible and even synergistic with academic publishing.&lt;/p&gt;
&lt;p&gt;I am both proud and nervous to know of a half dozen other researchers who have credited me for inspiring them to adopt open or partially open lab notebooks online. I am particularly grateful for the examples, interactions, and ideas from established practitioners of open notebook science in other fields. My collaborators have been largely been somewhere between favorable and agnostic towards the idea, with the occasional request for delayed or off-line notes. More often gaps arise from my own lapses in writing (or at least being intelligible), though the automated records from Github in particular, as well as Flickr (image log), Mendeley (reading log), and Twitter and the like help make up for some of the gaps.&lt;/p&gt;
&lt;p&gt;&lt;!-- Liam Revell, Scott Chamberlain, Alistair Boettiger, Noam Ross, Nick Fabina, Lee Worden, Mario Pineda-Krch--&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-integrated-notebook-becomes-the-knitted-notebook&quot;&gt;The Integrated Notebook becomes the Knitted Notebook&lt;/h2&gt;
&lt;p&gt;In creating my wordpress lab notebook, &lt;a href=&quot;http://www.carlboettiger.info/archives/211&quot;&gt;I put forward the idea of an “Integrated Lab Notebook”&lt;/a&gt;, a somewhat convoluted scheme in which I would describe my ideas and analyses in Wordpress posts, embed figures from Flickr, and link them to code on Github. &lt;a href=&quot;http://yihui.name/knitr/&quot;&gt;Knitr&lt;/a&gt; simplified all that. I can now write code, analysis, figures, equations, citations, etc, into a single &lt;code&gt;Rmarkdown&lt;/code&gt; format and track it’s evolution through git version control. The &lt;code&gt;knitr&lt;/code&gt; markdown format goes smoothly on Github, the lab notebook, and even into generating pdf or word documents for publication, never seperating the code from the results. For details, see “&lt;a href=&quot;http://www.carlboettiger.info/2012/04/07/writing-reproducibly-in-the-open-with-knitr.html&quot;&gt;writing reproducibly in the open with knitr&lt;/a&gt;.”&lt;/p&gt;
&lt;h2 id=&quot;navigating-the-open-notebook&quot;&gt;Navigating the Open Notebook&lt;/h2&gt;
&lt;p&gt;You can page through the notebook chronologically just like any paper notebook using the “Next” and “Previous” buttons on the sidebar. The notebook also leverages all of the standard features of a blog:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the ability to search,&lt;/li&gt;
&lt;li&gt;browse the archives &lt;a href=&quot;http://www.carlboettiger.info/archives.html&quot;&gt;by date&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;browse by &lt;a href=&quot;http://www.carlboettiger.info/tags.html&quot;&gt;tag&lt;/a&gt; or&lt;/li&gt;
&lt;li&gt;browse by &lt;a href=&quot;http://www.carlboettiger.info/categories.html&quot;&gt;category&lt;/a&gt;.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;follow the &lt;a href=&quot;http://www.carlboettiger.info/atom.xml&quot;&gt;RSS feed&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;add and share comments in Disqus&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I use categories as the electronic equivalent of separate paper notebooks, dividing out my ecological research projects, evolutionary research topics, my teaching notebook, and a few others. As such, each entry is (usually) made into exactly one category. I use tags for more flexible topics, usually refecting particular projects or methods, and entries can have zero or multiple tags.&lt;/p&gt;
&lt;p&gt;It can be difficult to get the big picture of a project by merely flipping through entries. The chronological flow of a notebook is a poor fit to the very nonlinear nature of research. Reproducing particular results frequently requires additional information (also data and software) that are not part of the daily entries. Github repositories have been the perfect answer to these challenges.&lt;/p&gt;
&lt;h2 id=&quot;the-real-notebook-is-github&quot;&gt;(The real notebook is Github)&lt;/h2&gt;
&lt;p&gt;My Github repositories offer a kind of inverted version of the lab notebook, grouped by project (tag) rather than chronology. Each of my research projects is now is given it’s own public Github repository. I work primarily in R because it is widely used by ecologists and statisicians, and has a strong emphasis on reproducible research. The “R package” structure turns out to be brilliantly designed for research projects, which specifies particular files for essential metadata (title, description, authors, software dependencies, etc), data, documentation, and source code (see &lt;a href=&quot;http://www.carlboettiger.info/2012/05/06/research-workflow.html&quot;&gt;my workflow&lt;/a&gt; for details). Rather than have each analysis described in full in my notebook, they live as seperate &lt;code&gt;knitr&lt;/code&gt; markdown files in the &lt;a href=&quot;https://github.com/cboettig/pdg_control/tree/master/inst/examples&quot;&gt;&lt;code&gt;inst/examples&lt;/code&gt;&lt;/a&gt; directory of the R package, where their &lt;a href=&quot;https://github.com/cboettig/pdg_control/commits/master/inst/examples&quot;&gt;history&lt;/a&gt; can be browsed on Github, complete with their commit logs. Long or frequently used blocks of code are written into functions with proper documentation in the package source-code directory &lt;code&gt;/R&lt;/code&gt;, keeping the analysis files cleaner and consistent.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;https://github.com/cboettig/pdg_control/issues?state=closed&quot;&gt;issues tracker&lt;/a&gt; connected to each Github repository provides a rich TO DO list for the project. Progress on any issue often takes the form of subsequent commits of a particular analysis file, and that commit log can automatically be appended to the issue.&lt;/p&gt;
&lt;h2 id=&quot;the-social-lab-notebook&quot;&gt;The social lab notebook&lt;/h2&gt;
&lt;p&gt;When scripting analyses or writing papers, pretty much everything can be captured on Github. I have recently added a short &lt;a href=&quot;https://github.com/cboettig/jekyll-labnotebook-plugins&quot;&gt;script&lt;/a&gt; to Jekyll which will pull the relevant commit logs into that day’s post automatically. Other activities fit less neatly into this mold (reading, math, notes from seminars and conferences), so these things get traditional notebook entries. I’m exploring automated integration for other activities, such as pulling my current reading from Mendeley or my recent discussions from Twitter into the notebook as well. For now, feed for each of these appear at the top of my &lt;a href=&quot;http://www.carlboettiger.info/lab-notebook.html&quot;&gt;notebook homepage&lt;/a&gt;, with links to the associated sites.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Migrating Oww Posts To Jekyll</title>
   <link href="/2012/09/27/Migrating-OWW-posts-to-Jekyll.html"/>
   <updated>2012-09-27T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/09/27/Migrating-OWW-posts-to-Jekyll</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;This Open Lab Notebook started on a public MediaWiki-based site, &lt;a href=&quot;http://openwetware.org&quot;&gt;OpenWetWare&lt;/a&gt; (OWW), which was created with the ambitious vision of having a single wiki for biological sciences (or at least, synthetic microbiology, since such the wiki grew out of a collection of such labs). Users could have their own pages that served as a personal website or lab group site, contribute pages on specific protocols, host course websites, and most interestingly, were encouraged to create open lab notebooks using specially designed templates for the purpose. From January through October of 2010, I kept all my notes in two separate OWW notebooks: one for entries on my &lt;a href=&quot;http://openwetware.org/wiki/User:Carl_Boettiger/Notebook/Comparative_Phylogenetics&quot;&gt;Comparative Phylogenetics&lt;/a&gt; research, and a seperate one for entries in &lt;a href=&quot;http://openwetware.org/wiki/User:Carl_Boettiger/Notebook/Stochastic_Population_Dynamics&quot;&gt;Stochastic Population Dynamics&lt;/a&gt;. Each notebook had a cover page and then entries by day, linked by the calendar box on the cover page. This was a neat idea an excellent introduction into the world of open lab notebooks.&lt;/p&gt;
&lt;p&gt;In September of 2010 I began to leave the OpenWetWare platform to start my own lab notebook based on a privately hosted copy Wordpress. The benefits of being on a shared community platform were minimized by the relatively small number of active users mostly belonging to a different field. Downtime on the site and a lack of any easy way to access my content off-line or back up content also made me increasingly nervous, while the difficulty in adding additional tools or functionality (such as RSS feeds to new entries, personal tags, improved search) collectively spurred my decision to move to Wordpress. At the time I had knew of no easy way to migrate my OWW posts, so I allowed them to remain where they were while I continued further notes in my newly minted Wordpress installation.&lt;/p&gt;
&lt;p&gt;In April of 2012 I began to experiment with the static-blogging engine, Jekyll. My adoption of markdown, facilitated by my discovery of pandoc and the advent of &lt;code&gt;knitr&lt;/code&gt;, together with my complete submersion into a Github-based workflow led me to first consider Jekyll. Wordpress was slow and heavy, both for creating entries in the online editor (though I did start pushing markdown-based entries to Wordpress through it’s API and the associated R package). Though Jekyll has a slightly steeper learning curve to start, once you have the basics down complicated things aren’t any harder than easy ones, whereas on Wordpress the basics are trivial but complex customization becomes a full-time web-developer challenge. In Jekyll, it was rather easy to migrate all my old entries from the previous platforms onto the new one.&lt;/p&gt;
&lt;p&gt;In the &lt;a href=&quot;http://www.carlboettiger.info/2012/09/19/migrating-from-wordpress-to-jekyll.html&quot;&gt;previous post&lt;/a&gt; I describe exporting my Wordpress-based entries using a python script from Thomas Frossman. To export my OpenWetWare entries I relied on the rather excellent MediaWiki API. While I began by grabbing the content of each post in MediaWiki syntax, I soon realized it was easier to grab the content already parsed as HTML (using a different API call) and then parse the HTML into markdown using Pandoc. (Pandoc’s developmental version does have experimental support for reading MediaWiki syntax now). I then added a few substitutions to standardize my tags and categories. Here’s my R call to the MediaWiki API (see &lt;a href=&quot;https://github.com/cboettig/sandbox/blob/1efa80e913006051083544275f6af9b5ab9ccb0a/wiki_get.R&quot;&gt;wiki_get.R&lt;/a&gt;):&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;wiki_parse &amp;lt;- function(page, baseurl, &lt;span class=&quot;dt&quot;&gt;format=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;json&amp;quot;&lt;/span&gt;, ...){
  &lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(httr)
  action = &lt;span class=&quot;st&quot;&gt;&amp;quot;parse&amp;quot;&lt;/span&gt;
  addr &amp;lt;- &lt;span class=&quot;kw&quot;&gt;paste&lt;/span&gt;(baseurl, &lt;span class=&quot;st&quot;&gt;&amp;quot;/api.php?format=&amp;quot;&lt;/span&gt;, format, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;amp;action=&amp;quot;&lt;/span&gt;, action, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;amp;page=&amp;quot;&lt;/span&gt;, page, &lt;span class=&quot;dt&quot;&gt;sep=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;)
  config &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;add_headers&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;User-Agent&amp;quot;&lt;/span&gt; = &lt;span class=&quot;st&quot;&gt;&amp;quot;rwiki&amp;quot;&lt;/span&gt;), ...)
  out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;GET&lt;/span&gt;(addr, &lt;span class=&quot;dt&quot;&gt;config=&lt;/span&gt;config)
  &lt;span class=&quot;kw&quot;&gt;parsed_content&lt;/span&gt;(out)
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I create a few helper functions for parsing the html into markdown, and also extracting and adding the metadata into Jekyll’s YAML headers (see &lt;a href=&quot;https://github.com/cboettig/sandbox/blob/1efa80e913006051083544275f6af9b5ab9ccb0a/export_oww.R&quot;&gt;export_oww.R&lt;/a&gt;)&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(httr)
&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(gsubfn)

oww_to_md &amp;lt;- function(pages, &lt;span class=&quot;dt&quot;&gt;user=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;Carl_Boettiger&amp;quot;&lt;/span&gt;,  &lt;span class=&quot;dt&quot;&gt;baseurl =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;http://openwetware.org&amp;quot;&lt;/span&gt;){
  &lt;span class=&quot;co&quot;&gt;# Store filenames (with dates) and categories for each page, for reference later&lt;/span&gt;
  filenames &amp;lt;- &lt;span class=&quot;kw&quot;&gt;get_filenames&lt;/span&gt;(pages)
  categories &amp;lt;- &lt;span class=&quot;kw&quot;&gt;get_categories&lt;/span&gt;(pages)
  ## Use the API function to extract the content
  parsed &amp;lt;- &lt;span class=&quot;kw&quot;&gt;export_oww&lt;/span&gt;(pages, user, baseurl)
  ## Add the baseurl back into all the links
  htmls &amp;lt;- &lt;span class=&quot;kw&quot;&gt;add_baseurl&lt;/span&gt;(parsed)
  ## Create YAML header text
  headers &amp;lt;- &lt;span class=&quot;kw&quot;&gt;add_header_txt&lt;/span&gt;(parsed, categories)
  ## Use pandoc to convert the html to markdown
  mds &amp;lt;- &lt;span class=&quot;kw&quot;&gt;html_to_md&lt;/span&gt;(htmls, filenames) 
  ## Delete the OWW header info we don&amp;#39;t want in the markdown
  mds &amp;lt;- &lt;span class=&quot;kw&quot;&gt;clean_md&lt;/span&gt;(mds)
  ## Stick headers onto markdown files and name them according to filenames
  &lt;span class=&quot;kw&quot;&gt;write_mds&lt;/span&gt;(mds, headers, filenames) 
}

get_filenames &amp;lt;- function(pages){
  &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(pages, function(p){
    p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot; &amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;_&amp;quot;&lt;/span&gt;, p)
    filename &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;/&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;-&amp;quot;&lt;/span&gt;, p)
    filename &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;(.*)-(&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;d+-&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;d+-&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;d+)&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;2-&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;1&amp;quot;&lt;/span&gt;, filename)
  })
}

&lt;span class=&quot;co&quot;&gt;#&amp;#39; Take a list of page titles to a user&amp;#39;s OWW notebooks and export them as Jekyll markdown entries.  &lt;/span&gt;
get_categories &amp;lt;- function(pages){
  &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(pages, function(p){
    p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;_&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot; &amp;quot;&lt;/span&gt;, p)
    filename &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;/&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;-&amp;quot;&lt;/span&gt;, p)
    category &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;(.*)-(&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;d+-&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;d+-&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;d+)&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;1&amp;quot;&lt;/span&gt;, filename)
  })
}


&lt;span class=&quot;co&quot;&gt;#&amp;#39; Take a list of page titles to a user&amp;#39;s OWW notebooks and export them as Jekyll markdown entries.  &lt;/span&gt;
export_oww &amp;lt;- function(pages, &lt;span class=&quot;dt&quot;&gt;user=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;Carl_Boettiger&amp;quot;&lt;/span&gt;,  &lt;span class=&quot;dt&quot;&gt;baseurl=&lt;/span&gt;  &lt;span class=&quot;st&quot;&gt;&amp;quot;http://openwetware.org&amp;quot;&lt;/span&gt;){
  &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(pages, function(p){
    p &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot; &amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;_&amp;quot;&lt;/span&gt;, p)
    page &amp;lt;- &lt;span class=&quot;kw&quot;&gt;paste&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;User:&amp;quot;&lt;/span&gt;, user, &lt;span class=&quot;st&quot;&gt;&amp;quot;/Notebook/&amp;quot;&lt;/span&gt;, p, &lt;span class=&quot;dt&quot;&gt;sep=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;)
    out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;wiki_parse&lt;/span&gt;(page, &lt;span class=&quot;dt&quot;&gt;baseurl=&lt;/span&gt;baseurl)
  })
}

add_baseurl &amp;lt;- function(parsed,  &lt;span class=&quot;dt&quot;&gt;baseurl =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;http://openwetware.org&amp;quot;&lt;/span&gt;){
  &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(parsed, function(out){
    html &amp;lt;- out$parse$text[[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]]
    html &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsubfn&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;src=&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;/images/&amp;quot;&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;paste&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;src=&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt;, 
                   baseurl,&lt;span class=&quot;st&quot;&gt;&amp;quot;/images/&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;sep=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;), html)
    html &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsubfn&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;href=&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;/wiki/&amp;quot;&lt;/span&gt;, &lt;span class=&quot;kw&quot;&gt;paste&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;src=&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt;, 
                   baseurl,&lt;span class=&quot;st&quot;&gt;&amp;quot;/wiki/&amp;quot;&lt;/span&gt;, 
                    &lt;span class=&quot;dt&quot;&gt;sep=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;), html)
  })
}

add_header_txt &amp;lt;- function(parsed, mycategories){
  &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(parsed), function(i){
    out &amp;lt;- parsed[[i]]
    category &amp;lt;- mycategories[[i]]
    if(&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(out$parse$categories)&amp;gt;&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;){
      categories &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(out$parse$categories, function(x) x$&lt;span class=&quot;st&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;dt&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;`&lt;/span&gt;)
      &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;_&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot; &amp;quot;&lt;/span&gt;, categories)
      ## Standarize some of my tags, called &amp;quot;categories&amp;quot; on OWW
      tags &amp;lt;- &lt;span class=&quot;kw&quot;&gt;paste&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;tags: &amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;[&amp;quot;&lt;/span&gt;, 
                          &lt;span class=&quot;kw&quot;&gt;paste0&lt;/span&gt;(categories, &lt;span class=&quot;dt&quot;&gt;collapse =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;),
                          &lt;span class=&quot;st&quot;&gt;&amp;quot;]&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;sep=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;)  
    } else {
      tags &amp;lt;- &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;
    }
    
    header &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;---&amp;quot;&lt;/span&gt;, 
                &lt;span class=&quot;st&quot;&gt;&amp;quot;layout: post&amp;quot;&lt;/span&gt;,
                tags, 
                &lt;span class=&quot;kw&quot;&gt;paste&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;categories: &amp;quot;&lt;/span&gt;, category),
                &lt;span class=&quot;st&quot;&gt;&amp;quot;---&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\n\n&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt;)
  })
}


html_to_md &amp;lt;- function(htmls, filenames){
  &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(htmls), function(html){
    &lt;span class=&quot;kw&quot;&gt;writeLines&lt;/span&gt;(htmls[[i]], &lt;span class=&quot;kw&quot;&gt;paste&lt;/span&gt;(filenames[i], &lt;span class=&quot;st&quot;&gt;&amp;quot;.html&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;sep=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;))
    md &amp;lt;- &lt;span class=&quot;kw&quot;&gt;system&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;paste&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;pandoc &amp;quot;&lt;/span&gt;, filenames[i], &lt;span class=&quot;st&quot;&gt;&amp;quot;.html -w markdown&amp;quot;&lt;/span&gt;, 
                       &lt;span class=&quot;dt&quot;&gt;sep=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;), &lt;span class=&quot;dt&quot;&gt;intern=&lt;/span&gt;&lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;)
  })
}


clean_md &amp;lt;- function(mds){
  &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(mds, function(md){
    ## Remove OWW header
    md &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;!&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;[image&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;(http://openwetware.org/images/f/f8/Owwnotebook_icon.png&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;)&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;, md)
    md &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;!&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;[image&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;(http://openwetware.org/images/9/94/Report.png&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;)&amp;quot;&lt;/span&gt;,  &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;, md)
    md &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;Main project&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;, md)
    md &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;page&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;, md)
    md &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;!&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;[image&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;(http://openwetware.org/images/c/c3/Resultset_previous.png&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;)&amp;quot;&lt;/span&gt;,  &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;, md)
    md &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;Previous$&amp;quot;&lt;/span&gt;,  &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;, md)
    md &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;^entry Next$&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;, md)
    md &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;!&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;[image&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;(http://openwetware.org/images/5/5c/Resultset_next.png&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;)&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;, md)
    md &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;^entry$&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;, md)
    md &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;^Stochastic Population Dynamics&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;, md)
    md &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;^Comparative Phylogenetics$&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;, md)
    md &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;^Teaching$&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;, md)
  })
}



write_md &amp;lt;- function(mds, headers, filenames){
  &lt;span class=&quot;kw&quot;&gt;lapply&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(mds), function(i){
    &lt;span class=&quot;kw&quot;&gt;writeLines&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(headers[[i]], mds[[i]]), &lt;span class=&quot;kw&quot;&gt;paste&lt;/span&gt;(filenames[i], &lt;span class=&quot;st&quot;&gt;&amp;quot;.markdown&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;sep=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;)) 
  })
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If or when I change platform again, it should be even easier. With all my posts in markdown, I can easily move them into an ebook or pdf using Pandoc (currently requires stripping the YAML headers first, though it would be great if Pandoc eventually supported metadata headers in YAML). Github renders the markdown of each post automatically, so the content of most posts can be read directly from the Github repository, &lt;a href=&quot;https://github.com/cboettig/labnotebook/tree/master/_posts&quot;&gt;cboettig/labnotebook&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;misc-tricks&quot;&gt;Misc tricks&lt;/h2&gt;
&lt;p&gt;The unix &lt;code&gt;rename&lt;/code&gt; utility comes in handy:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;rename &amp;#39;s/Comparative_Phylogenetics/Comparative-Phylogenetics-Notebook-(from-OWW)/&amp;#39; *Comparative_Phylogenetics.markdown
rename &amp;#39;s/Stochastic_Population_Dynamics/Stochastic-Population-Dynamics-Notebook-(from-OWW)/&amp;#39; *Stochastic_Population_Dynamics.markdown&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And a vim mapping to flip through 100s of source files quickly:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:map &amp;lt;F2&amp;gt; :N&amp;lt;CR&amp;gt;
:map &amp;lt;F3&amp;gt; :n&amp;lt;CR&amp;gt;&lt;/code&gt;&lt;/pre&gt;
</content>
 </entry>
 
 <entry>
   <title>Migrating From Wordpress To Jekyll</title>
   <link href="/2012/09/19/migrating-from-wordpress-to-jekyll.html"/>
   <updated>2012-09-19T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/09/19/migrating-from-wordpress-to-jekyll</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;Thanks to a recent bugfix in the &lt;a href=&quot;https://github.com/thomasf/exitwp&quot;&gt;exitwp&lt;/a&gt; scripts I was able to export all my Wordpress entries. The script pulls the entries from the Wordpress database and formats them in markdown, along with extracting all metadata such as timestamp, tags, categories, publication status, and Wordpress id number, which are all embedded as YAML header information.&lt;/p&gt;
&lt;h3 id=&quot;why-migrate-the-old-entries&quot;&gt;Why migrate the old entries?&lt;/h3&gt;
&lt;p&gt;When I moved to the Jekyll notebook, I left the Wordpress site standing with all its existing content and simply remapped the home pages. While it was nice to have the Wordpress system as a fall back while I got used to Jekyll, it meant that I couldn’t benefit from the faster and lighter nature of Jekyll while much of my traffic occurred on the Wordpress pages. I was running a dedicated virtual private server for the Wordpress hosting, and still the site wasn’t very responsive. To get an idea, try “flipping through the pages” of the new Jekyll notebook using the “next” and “previous” post buttons. The new pages load immediately, making it easy to flip through looking for some word or image I can’t find with tags or searches. Flipping through pages is the time-honored way of interacting with paper notebooks, so I’m glad that the new system is responsive enough to imitate this well.&lt;/p&gt;
&lt;h3 id=&quot;converting-shortcodes-from-wordpress-plugins&quot;&gt;Converting shortcodes from Wordpress Plugins&lt;/h3&gt;
&lt;p&gt;Migrating files using &lt;code&gt;exitwp&lt;/code&gt; is a relatively seamless affair. Unfortunately, my Wordpress posts make rather heavy use of plugins, which work through shortcodes that still appear in the converted files, such as &lt;code&gt;[flickr]&lt;/code&gt;, &lt;code&gt;[latex]&lt;/code&gt;, &lt;code&gt;[code lang=&amp;quot;r&amp;quot;]&lt;/code&gt;, and &lt;code&gt;[cite]&lt;/code&gt;, for image embedding, equation embedding, syntax highlighting, and citations by DOI, respectively. While a suite of Jekyll plugins exist for each of these tasks, I’d like my regular posts to be pure markdown (other than the YAML header), making it easy to migrate or reuse the content in the future in different platforms. Here is the &lt;a href=&quot;https://github.com/cboettig/sandbox/blob/c489da83ca7a78345b7981be4de5933ae7d63ac0/shortcodes.R&quot;&gt;R script I used for converting my shortcodes&lt;/a&gt;, as described below.&lt;/p&gt;
&lt;h4 id=&quot;syntax-highlighting-short-codes&quot;&gt;Syntax Highlighting short-codes&lt;/h4&gt;
&lt;p&gt;For instance, several markdown extension languages including, Github-flavored markdown, already allow for syntax-highlighting with fenced code blocks. I wrote a short script to replace all (most) of the shortcodes in use on my Wordpress site. (Over the years, I’d actually used a variety of different syntax highlighting plugins, making it necessary to match a variety of different shortcodes). Other than matching a lot of patterns, this was pretty straight forward.&lt;/p&gt;
&lt;h4 id=&quot;flickr-images&quot;&gt;flickr images&lt;/h4&gt;
&lt;p&gt;My workflow pushes all the images and graphs I create to flickr when the script runs. (I could also automatically push the images to Wordpress, or simply to my own site, but started using flickr pretty early on for this. The SOAP API is excellent, as is the Rflickr R package) Images were embedded into my Wordpress site using the shortcode and image ID number. To generate stand-alone markdown, I wanted tp replace all the image codes with the flickr URLs to the images, which is a trivial task with the API and Rflickr.&lt;/p&gt;
&lt;h4 id=&quot;latexmathjax-equations&quot;&gt;LaTeX/Mathjax Equations&lt;/h4&gt;
&lt;p&gt;Again I had used a variety of shortcodes for latex plugins before discovering MathJax, so I had to handle a variety of syntaxes here. Previously I’ve tried to write equations in a manner compatible with the redcarpet markdown parser that powers Github-Flavored Markdown (see the &lt;a href=&quot;https://github.com/nono/Jekyll-plugins&quot;&gt;corresponding Jekyll plugin&lt;/a&gt;), e.g. surrounding equations with &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; blocks to avoid the parser mangling them. Instead, I’ve found it easier now to switch to pandoc for my markdown parser (and &lt;a href=&quot;https://github.com/dsanson/jekyll-pandoc-plugin&quot;&gt;corresponding Jekyll Plugin&lt;/a&gt;). Pandoc uses the basic TeX &lt;code&gt;$&lt;/code&gt; and &lt;code&gt;$$&lt;/code&gt; for inline and display equations, rendering it into the MathJax (and modern LaTeX standard) &lt;code&gt;\(&lt;/code&gt; and &lt;code&gt;\[&lt;/code&gt; on conversion. Being pandoc-compatible is quite nice, making it easy to create an e-book, epub, or latex-based pdf of my notebook. I hate having to use a markdown syntax that isn’t compatible with most other extended markdown parsers, but with so many different, inconsistent parsers this cannot be easily avoided. Regardless, replacing the various shortcodes to the Pandoc syntax is just a simple regexpr step.&lt;/p&gt;
&lt;h4 id=&quot;citations&quot;&gt;Citations&lt;/h4&gt;
&lt;p&gt;Many of my posts relied on kcite to generate bibliographies for the post using DOIs. A short call to my &lt;a href=&quot;http://www.carlboettiger.info/2012/05/30/knitcitations.html&quot;&gt;knitcitations&lt;/a&gt; package allowed me to generate the parenthetical citations and bibliographies instead. In principle this step could be run at the time I compile the site with Jekyll. Pages would be valid &lt;code&gt;.Rmd&lt;/code&gt;, needing knitr as “markdown” interpreter. This is an intriguing way to go, but probably too complicated for the moment. Running additional R code would be nice, but could slow the time needed to build the site, even with knitr’s caching. Meanwhile, converted pages simply have the citations already processed and the bibliography added in as HTML at the end of the post.&lt;/p&gt;
&lt;h3 id=&quot;url-redirects&quot;&gt;URL Redirects&lt;/h3&gt;
&lt;p&gt;My Jekyll site uses the SEO recommended structure of year/month/day/page-title for URLs, while my Wordpress site used simple random id numbers. To ensure that links to the old Wordpress pages resolve to the newly migrated pages, I added a little Jekyll plugin, &lt;a href=&quot;https://github.com/cboettig/labnotebook/blob/master/_plugins/redirects.rb&quot;&gt;redirects.rb&lt;/a&gt;. One of the elegant things about Jekyll is the ability to create such plugins that do this just the way you would image doing so – creating auxiliary pages at each of the redirect URLs with a simple redirect command. To install, place &lt;code&gt;redirects.rb&lt;/code&gt; in &lt;code&gt;_plugins&lt;/code&gt;, &lt;code&gt;redirects.html&lt;/code&gt; in &lt;code&gt;_layouts&lt;/code&gt;, and in &lt;code&gt;_config.yml&lt;/code&gt; add the line &lt;code&gt;redirects: yes&lt;/code&gt; (see &lt;a href=&quot;https://github.com/cboettig/labnotebook&quot;&gt;site source&lt;/a&gt;).&lt;/p&gt;
&lt;h3 id=&quot;comments&quot;&gt;Comments&lt;/h3&gt;
&lt;p&gt;I am using Disqus as the comment engine for entries. Since URLs change in the above step and I do not provide a unique disqus code to each page, I am attempting to migrate comments using the &lt;a href=&quot;http://help.disqus.com/customer/portal/articles/286778-using-the-migration-tools&quot;&gt;Disqus “migrate threads” tool&lt;/a&gt;, which simply takes a csv file listing old and new urls in consecutive columns. Will have to wait and see if this works.&lt;/p&gt;
&lt;h3 id=&quot;private-entries&quot;&gt;Private entries&lt;/h3&gt;
&lt;p&gt;Several entries on the Wordpress site were marked private, and only visible after administrative login. Most of these entries are actually solicited journal reviews of various manuscripts which I cannot make public. &lt;code&gt;exitwp&lt;/code&gt; marks these posts as &lt;code&gt;published: false&lt;/code&gt; in the metadata, so it is easy to remove them from the Jekyll source site. They can be managed in a separate Github-excluded directory (so that they cannot be seen on the website source pages on Github either) that can be &lt;code&gt;.htaccess&lt;/code&gt; password protected.&lt;/p&gt;
&lt;h3 id=&quot;categories-and-tags&quot;&gt;Categories and Tags&lt;/h3&gt;
&lt;p&gt;Categories and tags are handled automatically in the conversion. One of the greatest things about having all the content on a common system is the ability to share a common tag-pool.&lt;/p&gt;
&lt;h3 id=&quot;rss&quot;&gt;RSS&lt;/h3&gt;
&lt;p&gt;If you follow the notebook through RSS feeds, all the migrated posts will be showing up as new unread entries, as the atom feed dates entries by when they appear, not the stated post date. My apologies!&lt;/p&gt;
&lt;h3 id=&quot;rough-edges&quot;&gt;Rough edges&lt;/h3&gt;
&lt;p&gt;A couple posts have rare shortcodes which are probably easier to correct by hand. My apologies for any rough edges resulting from the conversion (or the exchange of markdown parsers). Hopefully I’ll get these ironed out in the near future, but feel free to leave a comment on the page or the issues tracker on any such errors.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Analytic Solution To Multiple Uncertainty</title>
   <link href="/2012/09/14/analytic-solution-to-multiple-uncertainty.html"/>
   <updated>2012-09-14T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/09/14/analytic-solution-to-multiple-uncertainty</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;&lt;em&gt;No idea where I went wrong, but the final graphs are not what I expected&lt;/em&gt; &lt;em&gt;Update: Integrated out some uncertainty in the expectation step, need to preserve full set of transtions&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;We consider adding additional sources of noise through observation error and implementation error to the orginal model of Reed (1979), which considers only growth error. This follows in the line of exploration taken by Clark and Kirkwood (1987), Roughgarden (1996) and Sethi (2006).&lt;/p&gt;
&lt;p&gt;In adding these two sources of error, our state variable becomes our &lt;em&gt;measured&lt;/em&gt; (or believed) stock &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt;, rather than the true stock size &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt;, and our control variable becomes the quota &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q\inline&quot;/&gt;&lt;/span&gt; set, rather than the realized harvest &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;h2 id=&quot;analytical-integrals&quot;&gt;Analytical integrals&lt;/h2&gt;
&lt;p&gt;The central calculation to accomodating additional sources of uncertainty is the determination of the transition matrix; the probability of going from state &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_t\inline&quot;/&gt;&lt;/span&gt; at time &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?t\inline&quot;/&gt;&lt;/span&gt; to state &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_{t+1}\inline&quot;/&gt;&lt;/span&gt; in the next interval, for each possible value of the control variable (quota). We discritize the statespace onto a fine grid of values &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt; and &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt; to seek a stochastic dynamic programming solution.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;xmin &amp;lt;- &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;
xmax &amp;lt;- &lt;span class=&quot;dv&quot;&gt;150&lt;/span&gt;
grid_n &amp;lt;- &lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We seek a harvest policy which maximizes the discounted profit from the fishery using a stochastic dynamic programming approach over a discrete grid of stock sizes from &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;150&lt;/code&gt; on a grid of &lt;code&gt;100&lt;/code&gt; points, and over an identical discrete grid of possible harvest values.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;x_grid &amp;lt;- &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(xmin, xmax, &lt;span class=&quot;dt&quot;&gt;length =&lt;/span&gt; grid_n)
h_grid &amp;lt;- x_grid&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With purely growth noise, a row of the matrix is given by the probability density of the growth noise with mean &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?f(x,h)\inline&quot;/&gt;&lt;/span&gt;, that is, the probability of tranistion from &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt; to &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x_{t+1}\inline&quot;/&gt;&lt;/span&gt; at harvest &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt; is given by the function &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?P(x_t+1, f(x,h))\inline&quot;/&gt;&lt;/span&gt; for some probability density function &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?P\inline&quot;/&gt;&lt;/span&gt;. In the case of uncertainty in stock &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?y\inline&quot;/&gt;&lt;/span&gt; and harvest &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?h\inline&quot;/&gt;&lt;/span&gt;, we must integrate over the probability distributions for possible harvests and possible stock sizes,&lt;/p&gt;
&lt;div&gt; 
&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\int dh \int dy P(x_{t+1}, f(y, h))P(y)P(h)&quot; alt=&quot;\int dh \int dy P(x_{t+1}, f(y, h))P(y)P(h)&quot; /&gt;&lt;/div&gt;&lt;/span&gt;
&lt;/div&gt;

&lt;p&gt;In general this convolution can be non-trivial to compute, but in the case of uniformly distributed harvest error of &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\pm \sigma_i\inline&quot;/&gt;&lt;/span&gt; around some quota &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?q\inline&quot;/&gt;&lt;/span&gt;, and uniform measurement error of &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\pm \sigma_m\inline&quot;/&gt;&lt;/span&gt; around the true stock size &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?x\inline&quot;/&gt;&lt;/span&gt;, the integrals can be written as,&lt;/p&gt;
&lt;div&gt; 
&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?\frac{\int_{\max(q-\sigma_i,0)}^{q+\sigma_i} dh \int_{\max(y-\sigma_h,0)}^{y+\sigma_h} dy P(x_{t+1}, f(y, h))}{\left((q+\sigma_i) - \max(q-\sigma_i,0)\right) \left((x+\sigma_m) - \max(x-\sigma_m,0)\right)}&quot; alt=&quot;\frac{\int_{\max(q-\sigma_i,0)}^{q+\sigma_i} dh \int_{\max(y-\sigma_h,0)}^{y+\sigma_h} dy P(x_{t+1}, f(y, h))}{\left((q+\sigma_i) - \max(q-\sigma_i,0)\right) \left((x+\sigma_m) - \max(x-\sigma_m,0)\right)}&quot; /&gt;&lt;/div&gt;&lt;/span&gt;
&lt;/div&gt;

&lt;p&gt;Note we enforce the simple non-negative boundary on stock and harvest.&lt;/p&gt;
&lt;p&gt;So now we are left to merely integrate the &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?f(y,h)\inline&quot;/&gt;&lt;/span&gt; over these finite intervals. We can do this for arbitrary &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?f\inline&quot;/&gt;&lt;/span&gt; through multidimensional numerical integration (In fact we could have done this in the first place, but it is too slow for the convolutions of arbitrary probability densities)&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;int_f&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;function(f, x, q, sigma_m, sigma_i, pars){
  K &amp;lt;- pars[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]
  sigma_m &amp;lt;- K*sigma_m
  sigma_i &amp;lt;- K*sigma_i &lt;span class=&quot;co&quot;&gt;# scale noise into units of K&lt;/span&gt;
  
  if(sigma_m &amp;gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; sigma_i &amp;gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;){
    g &amp;lt;- function(X) &lt;span class=&quot;kw&quot;&gt;f&lt;/span&gt;(X[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], X[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;], pars)
    lower &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(x - sigma_m, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;), &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(q - sigma_i, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;))
    upper &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(x + sigma_m, q + sigma_i)
    A &amp;lt;- &lt;span class=&quot;kw&quot;&gt;adaptIntegrate&lt;/span&gt;(g, lower, upper)
    out &amp;lt;- A$integral/((q+sigma_i-&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(q-sigma_i, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;))*(x+sigma_m-&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(x-sigma_m, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)))
  } else if(sigma_m == &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; sigma_i &amp;gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;){ 
    g &amp;lt;- function(h) &lt;span class=&quot;kw&quot;&gt;f&lt;/span&gt;(x, h, pars)
    lower &amp;lt;- &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(q - sigma_i, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)
    upper &amp;lt;- q + sigma_i
    A &amp;lt;- &lt;span class=&quot;kw&quot;&gt;adaptIntegrate&lt;/span&gt;(g, lower, upper)
    out &amp;lt;- A$integral/(q+sigma_i-&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(q-sigma_i, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;))
  } else if(sigma_i == &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; sigma_m &amp;gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;){ 
    g &amp;lt;- function(y) &lt;span class=&quot;kw&quot;&gt;f&lt;/span&gt;(y, q, pars)
    lower &amp;lt;- &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(x - sigma_m, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)
    upper &amp;lt;- x + sigma_m
    A &amp;lt;- &lt;span class=&quot;kw&quot;&gt;adaptIntegrate&lt;/span&gt;(g, lower, upper)
    out &amp;lt;- A$integral/(x+sigma_m-&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(x-sigma_m, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;))
  } else if (m == &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; n == &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;){
    out &amp;lt;- &lt;span class=&quot;kw&quot;&gt;f&lt;/span&gt;(x,q,pars)
  } else {
    &lt;span class=&quot;kw&quot;&gt;stop&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;distribution widths cannot be negative&amp;quot;&lt;/span&gt;)
  }
  out
}
&amp;lt;environment: namespace:pdgControl&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If we assume a simple function like logistic growth, &lt;img src=&quot;http://latex.codecogs.com/png.latex?f(s) = r s (1-s/K) + s\inline&quot;/&gt;, where &lt;img src=&quot;http://latex.codecogs.com/png.latex?s = x - h\inline&quot;/&gt;,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;f &amp;lt;- function(x, h, p) {
    &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(x, function(x) {
        S = &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(x - h, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)
        p[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] * S * (&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt; - S/p[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]) + S
    })
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With parameters&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;r &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;
K &amp;lt;- &lt;span class=&quot;dv&quot;&gt;100&lt;/span&gt;
pars &amp;lt;- &lt;span class=&quot;kw&quot;&gt;c&lt;/span&gt;(r, K)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;r&lt;/code&gt; = &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;K&lt;/code&gt; = &lt;code&gt;100&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Following Sethi et al, we can do this in closed form,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;function(x,q, m, n, pars){
  K &amp;lt;- pars[&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;]
  m &amp;lt;- K*m
  n &amp;lt;- K*n &lt;span class=&quot;co&quot;&gt;# scale noise by K&lt;/span&gt;
  if(m &amp;gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; n &amp;gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;){
  out &amp;lt;- ((q+n-&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,q-n))*(x+m-&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,x-m))*(&lt;span class=&quot;dv&quot;&gt;6&lt;/span&gt;*x*K&lt;span class=&quot;dv&quot;&gt;-6&lt;/span&gt;*q*K&lt;span class=&quot;dv&quot;&gt;-6&lt;/span&gt;*n*K&lt;span class=&quot;dv&quot;&gt;+6&lt;/span&gt;*m*K&lt;span class=&quot;dv&quot;&gt;+6&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,x-m)*K&lt;span class=&quot;dv&quot;&gt;-6&lt;/span&gt;*
    &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,q-n)*K&lt;span class=&quot;dv&quot;&gt;-2&lt;/span&gt;*x^&lt;span class=&quot;dv&quot;&gt;2+3&lt;/span&gt;*q*x&lt;span class=&quot;dv&quot;&gt;+3&lt;/span&gt;*n*x&lt;span class=&quot;dv&quot;&gt;-4&lt;/span&gt;*m*x&lt;span class=&quot;dv&quot;&gt;-2&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,x-m)*x&lt;span class=&quot;dv&quot;&gt;+3&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,q-n)*x&lt;span class=&quot;dv&quot;&gt;-2&lt;/span&gt;*q^&lt;span class=&quot;dv&quot;&gt;2-4&lt;/span&gt;*n*q&lt;span class=&quot;dv&quot;&gt;+3&lt;/span&gt;*m*q&lt;span class=&quot;dv&quot;&gt;+3&lt;/span&gt;*
    &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,x-m)*q&lt;span class=&quot;dv&quot;&gt;-2&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,q-n)*q&lt;span class=&quot;dv&quot;&gt;-2&lt;/span&gt;*n^&lt;span class=&quot;dv&quot;&gt;2+3&lt;/span&gt;*m*n&lt;span class=&quot;dv&quot;&gt;+3&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,x-m)*n&lt;span class=&quot;dv&quot;&gt;-2&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,q-n)*n&lt;span class=&quot;dv&quot;&gt;-2&lt;/span&gt;*m^&lt;span class=&quot;dv&quot;&gt;2-2&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,x-m)*m&lt;span class=&quot;dv&quot;&gt;+3&lt;/span&gt;*
    &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,q-n)*m&lt;span class=&quot;dv&quot;&gt;-2&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,x-m)^&lt;span class=&quot;dv&quot;&gt;2+3&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,q-n)*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,x-m)-&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,q-n)^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;))/(&lt;span class=&quot;dv&quot;&gt;6&lt;/span&gt;*K)/((q+n-&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(q-n, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;))*(x+m-&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(x-m, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)))
  } else if(m == &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; n &amp;gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;) {
    y &amp;lt;- x
    out &amp;lt;- (((&lt;span class=&quot;dv&quot;&gt;6&lt;/span&gt;*q&lt;span class=&quot;dv&quot;&gt;+6&lt;/span&gt;*n&lt;span class=&quot;dv&quot;&gt;-6&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,q-n))*y&lt;span class=&quot;dv&quot;&gt;-3&lt;/span&gt;*q^&lt;span class=&quot;dv&quot;&gt;2-6&lt;/span&gt;*n*q&lt;span class=&quot;dv&quot;&gt;-3&lt;/span&gt;*n^&lt;span class=&quot;dv&quot;&gt;2+3&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,q-n)^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)*K+(-&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;*q&lt;span class=&quot;dv&quot;&gt;-3&lt;/span&gt;*n&lt;span class=&quot;dv&quot;&gt;+3&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,q-n))*
      y^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;+(&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;*q^&lt;span class=&quot;dv&quot;&gt;2+6&lt;/span&gt;*n*q&lt;span class=&quot;dv&quot;&gt;+3&lt;/span&gt;*n^&lt;span class=&quot;dv&quot;&gt;2-3&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,q-n)^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)*y-q^&lt;span class=&quot;dv&quot;&gt;3-3&lt;/span&gt;*n*q^&lt;span class=&quot;dv&quot;&gt;2-3&lt;/span&gt;*n^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;*q-n^&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;+&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,q-n)^&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;)/(&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;*K*(q+n-&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(q-n, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)))
  } else if(n == &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; m &amp;gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;){
    h &amp;lt;- q
    out &amp;lt;- ((&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;*x^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;+(&lt;span class=&quot;dv&quot;&gt;6&lt;/span&gt;*m&lt;span class=&quot;dv&quot;&gt;-6&lt;/span&gt;*h)*x&lt;span class=&quot;dv&quot;&gt;+3&lt;/span&gt;*m^&lt;span class=&quot;dv&quot;&gt;2-6&lt;/span&gt;*h*m&lt;span class=&quot;dv&quot;&gt;+6&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,x-m)*h&lt;span class=&quot;dv&quot;&gt;-3&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,x-m)^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)*K-x^&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;+(&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;*h&lt;span class=&quot;dv&quot;&gt;-3&lt;/span&gt;*m)*x^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;+
      (-&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;*m^&lt;span class=&quot;dv&quot;&gt;2+6&lt;/span&gt;*h*m&lt;span class=&quot;dv&quot;&gt;-3&lt;/span&gt;*h^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)*x-m^&lt;span class=&quot;dv&quot;&gt;3+3&lt;/span&gt;*h*m^&lt;span class=&quot;dv&quot;&gt;2-3&lt;/span&gt;*h^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;*m&lt;span class=&quot;dv&quot;&gt;+3&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,x-m)*h^&lt;span class=&quot;dv&quot;&gt;2-3&lt;/span&gt;*&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,x-m)^&lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;*h+&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;,x-m)^&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;)/(&lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;*K*(x+m-&lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(x-m, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)))
  } else if (m == &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt; &amp;amp;&amp;amp; n == &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;){
    S &amp;lt;- &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(x - q, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)
    out &amp;lt;- S * (&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt; - S/K) + S
  } else {
    &lt;span class=&quot;kw&quot;&gt;stop&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;distribution widths cannot be negative&amp;quot;&lt;/span&gt;)
  }
  &lt;span class=&quot;kw&quot;&gt;max&lt;/span&gt;(out,&lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)
}
&amp;lt;environment: namespace:pdgControl&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can compare timing and equivalence of these two expressions:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(cubature)
&lt;span class=&quot;co&quot;&gt;# Confirm that these give the same value, and time performance&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;system.time&lt;/span&gt;(a &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(x_grid, function(x) &lt;span class=&quot;kw&quot;&gt;int_f&lt;/span&gt;(f, x, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;, 
    pars)))&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;   user  system elapsed 
  7.444   0.000   7.394 &lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;system.time&lt;/span&gt;(b &amp;lt;- &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(x_grid, function(x) &lt;span class=&quot;kw&quot;&gt;F&lt;/span&gt;(x, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;, pars)))&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;   user  system elapsed 
  0.012   0.000   0.015 &lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;x =&lt;/span&gt; x_grid, &lt;span class=&quot;dt&quot;&gt;a =&lt;/span&gt; a, &lt;span class=&quot;dt&quot;&gt;b =&lt;/span&gt; b)) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, a), 
    &lt;span class=&quot;dt&quot;&gt;col =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;geom_line&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, b), &lt;span class=&quot;dt&quot;&gt;lty =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8443/7986666475_3fce0b9e96_o.png&quot; alt=&quot;plot of chunk unnamed-chunk-6&quot; /&gt;&lt;figcaption&gt;plot of chunk unnamed-chunk-6&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Note that as the uncertainy gets small, we recover the original transition probability &lt;span class=&quot;math&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?f\inline&quot;/&gt;&lt;/span&gt;:&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;F&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;50&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;, pars)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;[1] 67.01&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;F&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;50&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;1e-04&lt;/span&gt;, &lt;span class=&quot;fl&quot;&gt;1e-04&lt;/span&gt;, pars)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;[1] 70.84&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;f&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;50&lt;/span&gt;, &lt;span class=&quot;dv&quot;&gt;4&lt;/span&gt;, pars)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;[1] 70.84&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When the noise width is much smaller than the bin width we may have trouble, particularly with the uniform distribution, since part of the bin corresponds to zero density, part to high density.&lt;/p&gt;
&lt;h2 id=&quot;numerical-implementation&quot;&gt;Numerical implementation&lt;/h2&gt;
&lt;p&gt;We consider a profits from fishing to be a function of harvest &lt;code&gt;h&lt;/code&gt; and stock size &lt;code&gt;x&lt;/code&gt;, &lt;img src=&quot;http://latex.codecogs.com/png.latex?(x,h) = h - ( c_0 + c_1  )\inline&quot;/&gt;, conditioned on &lt;img src=&quot;http://latex.codecogs.com/png.latex?h &amp;gt; x\inline&quot;/&gt; and &lt;img src=&quot;http://latex.codecogs.com/png.latex?x &amp;gt; 0\inline&quot;/&gt;,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;price &amp;lt;- &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;
c0 &amp;lt;- &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;
c1 &amp;lt;- &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;
profit &amp;lt;- &lt;span class=&quot;kw&quot;&gt;profit_harvest&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;price =&lt;/span&gt; price, &lt;span class=&quot;dt&quot;&gt;c0 =&lt;/span&gt; c0, &lt;span class=&quot;dt&quot;&gt;c1 =&lt;/span&gt; c1)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;with price = &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;c0&lt;/code&gt; = &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;c1&lt;/code&gt; = &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Additional parameters&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;delta &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.05&lt;/span&gt;
xT &amp;lt;- &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;
OptTime &amp;lt;- &lt;span class=&quot;dv&quot;&gt;25&lt;/span&gt;
sigma_g &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.1&lt;/span&gt;
sigma_m &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.5&lt;/span&gt;
sigma_i &amp;lt;- &lt;span class=&quot;fl&quot;&gt;0.5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The uniform distribution must be careful for noise sizes smaller than binwidth&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;pdfn &amp;lt;- function(P, s) &lt;span class=&quot;kw&quot;&gt;dunif&lt;/span&gt;(P, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt; - s, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt; + s)
&lt;span class=&quot;co&quot;&gt;# pdfn &amp;lt;- function(P, s) dlnorm(P, 0, s)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We will determine the optimal solution over a &lt;code&gt;25&lt;/code&gt; time step window with boundary condition for stock at &lt;code&gt;0&lt;/code&gt; and discounting rate of &lt;code&gt;0.05&lt;/code&gt;.&lt;/p&gt;
&lt;h1 id=&quot;scenarios&quot;&gt;Scenarios:&lt;/h1&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;sdp &amp;lt;- &lt;span class=&quot;kw&quot;&gt;SDP_uniform&lt;/span&gt;(f, pars, x_grid, h_grid, &lt;span class=&quot;dt&quot;&gt;sigma_g =&lt;/span&gt; sigma_g, pdfn, 
    &lt;span class=&quot;dt&quot;&gt;sigma_m =&lt;/span&gt; sigma_m, &lt;span class=&quot;dt&quot;&gt;sigma_i =&lt;/span&gt; sigma_i, F)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;uniform &amp;lt;- &lt;span class=&quot;kw&quot;&gt;find_dp_optim&lt;/span&gt;(sdp, x_grid, h_grid, OptTime, xT, profit, 
    delta, &lt;span class=&quot;dt&quot;&gt;reward =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Do the deterministic exactly,&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;
SDP_Mat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;determine_SDP_matrix&lt;/span&gt;(f, pars, x_grid, h_grid, &lt;span class=&quot;dt&quot;&gt;sigma_g =&lt;/span&gt; sigma_g, 
    pdfn)
det &amp;lt;- &lt;span class=&quot;kw&quot;&gt;find_dp_optim&lt;/span&gt;(SDP_Mat, x_grid, h_grid, OptTime, xT, profit, 
    delta, &lt;span class=&quot;dt&quot;&gt;reward =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Determine the policies for each of the scenarios (noise combinations).&lt;/p&gt;
&lt;h3 id=&quot;plots&quot;&gt;plots&lt;/h3&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;require&lt;/span&gt;(reshape2)
&lt;span class=&quot;co&quot;&gt;# policy &amp;lt;- melt(data.frame(stock = x_grid, deterministic=det$D[,1],&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;# uniform = uniform$D[,1], mc=opt$D[,1]), id = &amp;#39;stock&amp;#39;)&lt;/span&gt;
policy &amp;lt;- &lt;span class=&quot;kw&quot;&gt;melt&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;data.frame&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;stock =&lt;/span&gt; x_grid, &lt;span class=&quot;dt&quot;&gt;deterministic =&lt;/span&gt; det$D[, 
    &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;], &lt;span class=&quot;dt&quot;&gt;uniform =&lt;/span&gt; uniform$D[, &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;]), &lt;span class=&quot;dt&quot;&gt;id =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;stock&amp;quot;&lt;/span&gt;)

&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(policy) + &lt;span class=&quot;kw&quot;&gt;geom_jitter&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(stock, stock - x_grid[value], &lt;span class=&quot;dt&quot;&gt;color =&lt;/span&gt; variable), 
    &lt;span class=&quot;dt&quot;&gt;shape =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;+&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8456/7986667113_28574bc620_o.png&quot; /&gt;
&lt;/figure&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;dat &amp;lt;- &lt;span class=&quot;kw&quot;&gt;subset&lt;/span&gt;(policy, stock &amp;lt; &lt;span class=&quot;dv&quot;&gt;140&lt;/span&gt;)
dt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;data.table&lt;/span&gt;(dat)
linear &amp;lt;- dt[, &lt;span class=&quot;kw&quot;&gt;approx&lt;/span&gt;(stock, stock - x_grid[value], &lt;span class=&quot;dt&quot;&gt;xout =&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;seq&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, 
    &lt;span class=&quot;dv&quot;&gt;150&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;length =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;15&lt;/span&gt;)), by = variable]
&lt;span class=&quot;kw&quot;&gt;ggplot&lt;/span&gt;(linear) + &lt;span class=&quot;kw&quot;&gt;stat_smooth&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;aes&lt;/span&gt;(x, y, &lt;span class=&quot;dt&quot;&gt;color =&lt;/span&gt; variable), &lt;span class=&quot;dt&quot;&gt;degree =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;, 
    &lt;span class=&quot;dt&quot;&gt;se =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;FALSE&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;span =&lt;/span&gt; &lt;span class=&quot;fl&quot;&gt;0.3&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;xlab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;Measured Stock&amp;quot;&lt;/span&gt;) + &lt;span class=&quot;kw&quot;&gt;ylab&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;Optimal Expected Escapement&amp;quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8031/7986675144_095fd50f94_o.png&quot; /&gt;
&lt;/figure&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/09/12/notes.html"/>
   <updated>2012-09-12T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/09/12/notes</id>
   
   <content type="html">&lt;p&gt;{% octokit_commits pdg_control%}&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Esa Changes Arxiv Policy Following Community Comments</title>
   <link href="/2012/09/05/ESA-changes-ArXiv-policy-following-community-comments.html"/>
   <updated>2012-09-05T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/09/05/ESA-changes-ArXiv-policy-following-community-comments</id>
    
   <category term="//categories.html#open-science" label="open-science"/>
   
   <content type="html">&lt;p&gt;Earlier today, Scott Collins, the president of the Ecological Society of America has &lt;a href=&quot;https://twitter.com/ESA_Prez2013/status/243335363693797376&quot;&gt;announced&lt;/a&gt; that the society will now accept articles that have previously been posted on preprint servers. This comes on the heels of a growing discussion in our community. Ethan White has a good summary over on &lt;a href=&quot;http://jabberwocky.weecology.org/2012/09/05/esa-journals-will-now-allow-papers-with-preprints/&quot;&gt;Jabberwocky Ecology&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Many voices have joined the discussion over the past month, and it is exciting and vindicating to see the Society engage and discuss these questions. With this announcement out, I thought I might share my original letter. Here’s the text of an email I sent on August 1st to Don Strong, editor-in-chief of Ecology and a friend to open science known for his bottom-up view that ecologists should show their publication preferences by their actions. Don kindly forwarded this email to other members of the board.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Dear Don,&lt;/p&gt;
&lt;p&gt;Perhaps you have already seen the perspective appearing in Nature this week, “&lt;a href=&quot;http://www.nature.com/news/geneticists-eye-the-potential-of-arxiv-1.11091&quot;&gt;Geneticists eye the potential of Arxiv&lt;/a&gt;.” I must say it is particularly saddening to see the Ecological Society of America being singled out in the discussion as a professional society that opposes pre-prints, particularly given that ESA is not beholden to corporate publishers, and in the face a rising swell of interest in pre-print server capacity, as evidenced by the Nature article (which quotes our own Graham Coop), the emergence of an NCEAS working group to bring about a preprint server, and the extensive online discussions about ESA’s stance against pre-prints which was no doubt responsible for bringing ESA into the negative limelight of this perspective.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;The &lt;a href=&quot;http://jabberwocky.weecology.org/2012/07/18/esa-journals-do-not-allow-papers-with-preprints/&quot;&gt;discussion launched by Professor Ethan White&lt;/a&gt; on his blog suggests that ESA has in fact only recently removed a clause in the policies explicitly permitting the use of the arXiv. Meanwhile members of the &lt;a href=&quot;http://www.nceas.ucsb.edu/projects/12651&quot;&gt;NCEAS working group&lt;/a&gt; had considered approaching ESA to partner in their efforts to bring about a preprint server and culture, hoping to take advantage of the agility ESA has as a respected and independent society publisher. Ecology as a field has been a leading example of pushing for innovative and open publishing practices such as mandatory data archiving, and ESA has led this front for decades with innovations such as Ecological Archives and more recent Ecosphere. It shames me to see our society and our field painted as a backwater of regressive policies in such prominent magazines when even journals such as Nature, Science, &amp;amp; PNAS permit and encourage the use of preprint servers such as the arXiv. I would hate to see our most innovative research migrate away from the Society at a time when ESA could be leading our field through this academic publishing transition that is now discussed broadly in the NY Times, Guardian, Economist, &amp;amp; USA Today. This is a chance for the Ecological Society to both lead and flourish.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;I hope that these issues can be discussed in some fashion with the input of our community at the annual meeting in Portland. The British Ecological Society already plans to use the meeting to discuss a digital future of their journals, surely ESA will be doing as much at it’s own meeting, formally or informally?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Thank you for your time and consideration. Please let me know if there is anything I can do to help.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Carl&lt;/p&gt;
&lt;/blockquote&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/09/04/notes.html"/>
   <updated>2012-09-04T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/09/04/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;ul&gt;
&lt;li&gt;Fallacy paper done&lt;/li&gt;
&lt;li&gt;Dissertation filing&lt;/li&gt;
&lt;li&gt;Decision theory from the ROC curve.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Working group paper&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Jim/Mike paper&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;wrightscape paper?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Signature page two copies, archival paper?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;ropensci emails: Position paper: Goals&lt;/li&gt;
&lt;li&gt;&lt;p&gt;misc emails&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;fallacy-paper-finalizing-appendices&quot;&gt;Fallacy paper finalizing appendices&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Commit images and runs from yesterday (ibm simulation still running…)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;clean up appendix code&lt;/li&gt;
&lt;li&gt;&lt;p&gt;clean up appendix text&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;code-tricks-for-today&quot;&gt;Code tricks for today&lt;/h2&gt;
&lt;p&gt;vim set sytnax language, useful for getting R highlighting in &lt;code&gt;.Rmd&lt;/code&gt; files: &lt;code&gt;setf r&lt;/code&gt;, or equivalently, &lt;code&gt;set filetype=r&lt;/code&gt; (must be lowercase r). &lt;code&gt;set filetype&lt;/code&gt; with no argument gives the current filetype.&lt;/p&gt;
&lt;h3 id=&quot;coding&quot;&gt;Coding&lt;/h3&gt;
&lt;ul&gt;&lt;li&gt;
cboettig opened issue SChamberlain/isqaltms#8: &lt;em&gt;section: technical barriers to use&lt;/em&gt; &lt;a href=&quot;https://github.com/SChamberlain/isqaltms/issues/8&quot;&gt;11:14 2013/05/21&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
cboettig opened issue SChamberlain/isqaltms#7: &lt;em&gt;Section: Provenance&lt;/em&gt; &lt;a href=&quot;https://github.com/SChamberlain/isqaltms/issues/7&quot;&gt;11:07 2013/05/21&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
cboettig opened issue SChamberlain/isqaltms#6: &lt;em&gt;Section: Putting in context&lt;/em&gt; &lt;a href=&quot;https://github.com/SChamberlain/isqaltms/issues/6&quot;&gt;11:04 2013/05/21&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
cboettig opened issue SChamberlain/isqaltms#5: &lt;em&gt;Section: Open metrics&lt;/em&gt; &lt;a href=&quot;https://github.com/SChamberlain/isqaltms/issues/5&quot;&gt;11:00 2013/05/21&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
cboettig opened issue SChamberlain/isqaltms#4: &lt;em&gt;Section: standards and consistency&lt;/em&gt; &lt;a href=&quot;https://github.com/SChamberlain/isqaltms/issues/4&quot;&gt;10:56 2013/05/21&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
cboettig opened issue SChamberlain/isqaltms#3: &lt;em&gt;Altmetrics data providers section&lt;/em&gt; &lt;a href=&quot;https://github.com/SChamberlain/isqaltms/issues/3&quot;&gt;10:45 2013/05/21&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
cboettig opened issue SChamberlain/isqaltms#2: &lt;em&gt;cite wherever Jason coined the term altmetrics&lt;/em&gt; &lt;a href=&quot;https://github.com/SChamberlain/isqaltms/issues/2&quot;&gt;10:40 2013/05/21&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
cboettig opened issue SChamberlain/isqaltms#1: &lt;em&gt;intro doesn’t mention time-lag issue&lt;/em&gt; &lt;a href=&quot;https://github.com/SChamberlain/isqaltms/issues/1&quot;&gt;10:40 2013/05/21&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;


&lt;h3 id=&quot;reading&quot;&gt;Reading&lt;/h3&gt;
&lt;ul&gt;&lt;li&gt;
Signature of ocean warming in global fisheries catch: Nature (2013). Volume: 497, Issue: 7449. Pages: 365-368. William W. L. Cheung, Reg Watson, Daniel Pauly et al. &lt;a href=&quot;http://www.mendeley.com/research/signature-ocean-warming-global-fisheries-catch-7/&quot;&gt;04:38 2013/05/18&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
Incorporating uncertainty associated with habitat data in marine reserve design: Biological Conservation (2013). Pages: 41-51. Vivitskaia J. Tulloch, Hugh P. Possingham, Stacy D. Jupiter, Chris Roelfsema, Ayesha I.T. Tulloch, Carissa J. Klein et al. &lt;a href=&quot;http://www.mendeley.com/research/author-s-personal-copy-incorporating-uncertainty-associated-habitat-data-marine-reserve-design/&quot;&gt;04:38 2013/05/18&lt;/a&gt;
&lt;/li&gt;&lt;li&gt;
Innovations in capture fisheries are an imperative for nutrition security in the developing world: Proceedings of the National Academy of Sciences (2013). Pages: 1-6. S. J. Hall, R. Hilborn, N. L. Andrew, E. H. Allison et al. &lt;a href=&quot;http://www.mendeley.com/research/innovations-capture-fisheries-imperative-nutrition-security-developing-world/&quot;&gt;04:38 2013/05/18&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;



</content>
 </entry>
 
 <entry>
   <title>Santa Cruz Postdoc</title>
   <link href="/2012/08/29/Santa-Cruz-Postdoc.html"/>
   <updated>2012-08-29T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/08/29/Santa-Cruz-Postdoc</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Spent Monday and Tuesday visiting Santa Cruz, where I have recently accepted a post-doctoral position with &lt;a href=&quot;http://www.somas.stonybrook.edu/people/munch.html&quot;&gt;Steve Munch&lt;/a&gt;, &lt;a href=&quot;http://users.soe.ucsc.edu/~msmangel/&quot;&gt;Marc Mangel&lt;/a&gt;, and &lt;a href=&quot;http://swfsc.noaa.gov/staff.aspx?id=689&quot;&gt;Alec MacCall&lt;/a&gt;. I will be based primarily at the National Marine Fisheries Service building, here: ` &lt;img src=&quot;https://lh4.googleusercontent.com/-hOqjhixOLYA/UD5hoCJu7LI/AAAAAAAACLc/JitBtQAjADg/s1158/2012-08-28_14-53-14_598.jpg&quot; alt=&quot;A view of my new office: NMFS&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Five fantastic years of graduate school are coming to an end: I will start officially later this fall, where I will&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;join an exciting team of ecologists and applied mathematicians who work collaboratively on cutting-edge problems in ecological and evolutionary modeling through the &lt;a href=&quot;http://www.soe.ucsc.edu/~msmangel/CSTAR.html&quot;&gt;Center for Stock Assessment Research&lt;/a&gt;. I will work with us to develop non-parametric approaches to ecosystem-based management based on semi-parametric Bayesian methods for nonlinear time-series modeling …&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;or so the job description goes. I am looking forward to it.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/08/23/notes.html"/>
   <updated>2012-08-23T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/08/23/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;&lt;a href=&quot;https://github.com/cboettig/earlywarning/issues/5&quot;&gt;Fallacy with May model runs&lt;/a&gt;&lt;/p&gt;
&lt;div&gt;
&lt;span class=&quot;math&quot;&gt;&lt;div style=&quot;text-align:center;&quot;&gt;&lt;img src=&quot;http://latex.codecogs.com/png.latex?X_{t+1} = X_t \exp\left( r \left(1 - \frac{ X_t }{ K } \right) - \frac{ a * X_t ^ {Q - 1} }{s ^ Q + H ^ Q} \right)&quot; alt=&quot;X_{t+1} = X_t \exp\left( r \left(1 - \frac{ X_t }{ K } \right) - \frac{ a * X_t ^ {Q - 1} }{s ^ Q + H ^ Q} \right)&quot; /&gt;&lt;/div&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;figure&gt;
&lt;img src=&quot;http://farm9.staticflickr.com/8435/7846795570_87ac2e71fd_o.png&quot; alt=&quot;plot of chunk figure2&quot; /&gt;&lt;figcaption&gt;plot of chunk figure2&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Working on unmanaged warning. (see &lt;a href=&quot;https://github.com/cboettig/pdg_control/issues/21&quot;&gt;#21&lt;/a&gt;)&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Warning Signals In Management</title>
   <link href="/2012/08/22/warning-signals-in-management.html"/>
   <updated>2012-08-22T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/08/22/warning-signals-in-management</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;p&gt;Tour of existing files (version stable links)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/blob/e6aaf0ba27e4280cbbb04d5ecfeb9b18f158ca77/inst/examples/managed_warning.md&quot;&gt;managed warning&lt;/a&gt; is the current direct test of this, but needs decently ranged input example where detection has a good chance to succeed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/blob/e6aaf0ba27e4280cbbb04d5ecfeb9b18f158ca77/inst/examples/criticaltransition.md&quot;&gt;criticaltransition&lt;/a&gt; Statistics across replicate crashes that don’t show much promise for detection.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A heuristic implementation in response to the detection of a signal might use a simple rule like a fraction of the optimal harvest of a stable system. &lt;a href=&quot;&quot;&gt;cautious.md&lt;/a&gt; simply shows the economic cost associated with this fractional harvest.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/blob/e6aaf0ba27e4280cbbb04d5ecfeb9b18f158ca77/inst/examples/resilience_assessment.Rmd&quot;&gt;resilience_assessment&lt;/a&gt; not run&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Also compare to&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cboettig/pdg_control/blob/e6aaf0ba27e4280cbbb04d5ecfeb9b18f158ca77/inst/examples/stability.md&quot;&gt;Stability assessment&lt;/a&gt;, estimating coefficient &lt;img src=&quot;http://latex.codecogs.com/png.latex?\inline&quot;/&gt;; surprisingly difficult to distinguish the fished from the unfished by this metric.&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Revisions on Prosecutors Fallacy</title>
   <link href="/2012/08/22/notes.html"/>
   <updated>2012-08-22T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/08/22/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Email Alan re: Prosecutor’s fallacy manuscript. Schedule meeting.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Proof corrections for rfishbase manuscript. Done.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fallacy simulations: calibration range for May model: expect small fraction of runs to transition by chance from stable state.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here we’re getting a bit less than 2% chance transitions in 5000 steps.&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&amp;gt;   sn &amp;lt;- 
+   &lt;span class=&quot;kw&quot;&gt;sapply&lt;/span&gt;(&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:&lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;, function(rep){
  +     x &amp;lt;- &lt;span class=&quot;kw&quot;&gt;vector&lt;/span&gt;(&lt;span class=&quot;dt&quot;&gt;mode=&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;quot;double&amp;quot;&lt;/span&gt;, &lt;span class=&quot;dt&quot;&gt;length=&lt;/span&gt;n)
  +     x[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] &amp;lt;- &lt;span class=&quot;dv&quot;&gt;8&lt;/span&gt; &lt;span class=&quot;co&quot;&gt;# positive equilibrium&lt;/span&gt;
  +     z &amp;lt;- &lt;span class=&quot;kw&quot;&gt;rlnorm&lt;/span&gt;(n, &lt;span class=&quot;dv&quot;&gt;0&lt;/span&gt;, .&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;)
  +     r = .&lt;span class=&quot;dv&quot;&gt;75&lt;/span&gt;; k = &lt;span class=&quot;dv&quot;&gt;10&lt;/span&gt;; a=&lt;span class=&quot;fl&quot;&gt;1.55&lt;/span&gt;; H=&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;; Q = &lt;span class=&quot;dv&quot;&gt;3&lt;/span&gt;
  +     for(t in &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;:n){
    +       x[t&lt;span class=&quot;dv&quot;&gt;+1&lt;/span&gt;] = z[t] *  x[t] * &lt;span class=&quot;kw&quot;&gt;exp&lt;/span&gt;(r * (&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt; - x[t] / k) - a * x[t] ^ (Q - &lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;) / (x[t] ^ Q + H ^ Q)) 
    +     }
    +     x
    +   })
&amp;gt; crashed &amp;lt;- &lt;span class=&quot;kw&quot;&gt;which&lt;/span&gt;(sn[n,] &amp;lt; &lt;span class=&quot;dv&quot;&gt;2&lt;/span&gt;)
&amp;gt;   &lt;span class=&quot;kw&quot;&gt;length&lt;/span&gt;(crashed)/&lt;span class=&quot;dv&quot;&gt;1000&lt;/span&gt;
[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] &lt;span class=&quot;fl&quot;&gt;0.017&lt;/span&gt;
&amp;gt; 
&amp;gt; n
[&lt;span class=&quot;dv&quot;&gt;1&lt;/span&gt;] &lt;span class=&quot;dv&quot;&gt;5000&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Fallacy simulation analysis running on farm using May model. &lt;a href=&quot;https://github.com/cboettig/earlywarning/blob/prosecutor/inst/examples/fallacy.Rmd&quot;&gt;See fallacy.Rmd, prosecutor branch&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;rerun using different point to indicate transition. Tracking runs on &lt;a href=&quot;https://github.com/cboettig/earlywarning/issues/5&quot;&gt;Issue 5&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;add figure plotting b and d curves, or at least b-d curve. Likewise for May model.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;misc&quot;&gt;Misc&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/emhart/ImpacTwit/issues/2&quot;&gt;Exploring&lt;/a&gt; twitteR finding publications under discussion&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Migrated labnotebook plugins to &lt;a href=&quot;https://github.com/cboettig/jekyll-labnotebook-plugins&quot;&gt;separate repository&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Updated vimrc to preview pandoc:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;map \md : call PreviewMarkdown()&amp;lt;CR&amp;gt;
func! PreviewMarkdown()
exec &amp;quot;w&amp;quot;
exec &amp;quot;! pandoc -s % -o .temp.html&amp;quot;
exec &amp;quot;! google-chrome .temp.html&amp;quot;
endfunc&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Should add css templates from my notebook or github.&lt;br /&gt;Could also parse with github’s own API instead of pandoc, e.g. with ruby:&lt;/p&gt;
&lt;pre class=&quot;sourceCode ruby&quot;&gt;&lt;code class=&quot;sourceCode ruby&quot;&gt;&lt;span class=&quot;kw&quot;&gt;#!/usr/bin/env ruby&lt;/span&gt;

&lt;span class=&quot;co&quot;&gt;# Example usage &lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;# ./render_gfm.rb input.md &amp;gt; output.html&lt;/span&gt;
&lt;span class=&quot;co&quot;&gt;# &lt;/span&gt;

require &lt;span class=&quot;st&quot;&gt;&amp;#39;octokit&amp;#39;&lt;/span&gt;
puts &lt;span class=&quot;dt&quot;&gt;Octokit&lt;/span&gt;.markdown(&lt;span class=&quot;dt&quot;&gt;File&lt;/span&gt;.read(&lt;span class=&quot;dt&quot;&gt;ARGV&lt;/span&gt;.first))&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;twitteR authentication keys configured in .Rprofile&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Pdg Control Updates</title>
   <link href="/2012/08/21/pdg-control-updates.html"/>
   <updated>2012-08-21T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/08/21/pdg-control-updates</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;resolving-s-d&quot;&gt;Resolving S &amp;lt; D&lt;/h2&gt;
&lt;h2 id=&quot;code-updates&quot;&gt;Code updates&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/pengwynn/octokit/issues/127&quot;&gt;octokit&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Macksamie, K., Cockburn, J., &amp;amp; Wagner, J. (2012). Robust control amidst stock and flow benefits: The case of wolf-elk-hunting dynamics in the US Mountain West. 2012 AERE Summer Conference, Asheville, NC (pp. 1–33). Retrieved from http://www.webmeets.com/files/papers/AERE/2012/3/AEREConfPaper05172012.pdf&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;The Linear parameter varying (LPV) approach which allows this problem to leverage a standard LMI (linear matrix inequality) solver seeems like a clever route, but unclear if this would be restricted to the additive noise models such as they consider?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Some background on LPV:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Becker, G., &amp;amp; Packard, A. (1994). Robust performance of linear parametrically varying systems using parametrically-dependent linear feedback. Systems &amp;amp; Control Letters, 23(3), 205–215. doi:10.1016/0167-6911(94)90006-X&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Brock, W. a., &amp;amp; Durlauf, S. N. (2005). Local robustness analysis: Theory and application. Journal of Economic Dynamics and Control, 29(11), 2067–2092. doi:10.1016/j.jedc.2005.06.001&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;An interesting example handling Knightian uncertainty about the model directly:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Athanassoglou, S., &amp;amp; Xepapadeas, A. (2012). Pollution control with uncertain stock dynamics: When, and how, to be precautious. Journal of Environmental Economics and Management, 63(3), 304–320. doi:10.1016/j.jeem.2011.11.001&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="/2012/08/20/notes.html"/>
   <updated>2012-08-20T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/08/20/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h2 id=&quot;writing&quot;&gt;Writing&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Draft outline of &lt;a href=&quot;https://github.com/cboettig/pdg_control/tree/master/inst/doc/policycosts&quot;&gt;policy costs paper&lt;/a&gt; sent to Paul.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;misc&quot;&gt;Misc&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;ropensci &lt;a href=&quot;https://github.com/ropensci/docs/blob/master/nceas/nceas_working_group_proposal.md&quot;&gt;NCEAS proposal&lt;/a&gt; - contacts&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;MEE supplement follow-up: Wow, MEE promotes &lt;a href=&quot;http://www.methodsinecologyandevolution.org/view/0/podcasts.html&quot;&gt;video podcasts along with publications&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://blog.rstudio.org/2012/08/20/welcome-hadley-winston-and-garrett/&quot;&gt;Hadley to join RStudio&lt;/a&gt; full time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://gist.github.com/3379144&quot;&gt;A gist by Hadley on storing things like API keys across R packages&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Joined &lt;a href=&quot;http://segate.sunet.se/cgi-bin/wa&quot;&gt;fisheries-science mailing list&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;/h2&gt;
&lt;h3 id=&quot;warning-signals&quot;&gt;Warning signals&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://afs.confex.com/afs/2012/webprogram/Paper9299.html&quot;&gt;Critical transitions at Amer Fisheries Society&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ives, A., &amp;amp; Dakos, V. (2012). Detecting dynamical changes in nonlinear time series using locally linear state-space models. Ecosphere, 3(June). Retrieved from http://www.esajournals.org/doi/abs/10.1890/ES11-00347.1&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Feng, J., Dakos, V., &amp;amp; van Nes, E. H. (2012). Does predator interference cause alternative stable states in multispecies communities? Theoretical population biology. doi:10.1016/j.tpb.2012.06.003&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Katz, R. W., Brush, G. S., &amp;amp; Parlange, M. B. (2005). Statistics of Extremes : Modeling Ecological Disturbances, 86(5), 1124–1134.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;more-abc-methods-in-evolution&quot;&gt;More ABC methods in Evolution&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Kutsukake, N., &amp;amp; Innan, H. (2012). Simulation-Based Likelihood Approach for Evolutionary Models of Phenotypic Traits on Phylogeny. Evolution, (1), no–no. doi:10.1111/j.1558-5646.2012.01775.x&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;methods&quot;&gt;Methods&lt;/h3&gt;
&lt;p&gt;Might be a good paper for algorithms group to read.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Wu, X., Kumar, V., Ross Quinlan, J., Ghosh, J., Yang, Q., Motoda, H., McLachlan, G. J., et al. (2007). Top 10 algorithms in data mining. Knowledge and Information Systems (Vol. 14, pp. 1–37). doi:10.1007/s10115-007-0114-2&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And a good one for theory tea?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;De Boer, R. J. (2012). Which of Our Modeling Predictions Are Robust? (R. Antia, Ed.)PLoS Computational Biology, 8(7), e1002593. doi:10.1371/journal.pcbi.1002593&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;papers-following-up-from-esa&quot;&gt;Papers following up from ESA&lt;/h3&gt;
&lt;p&gt;Regime shifts in disease models&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Chaves, L. F., Hashizume, M., Satake, A., &amp;amp; Minakawa, N. (2012). Regime shifts and heterogeneous trends in malaria time series from Western Kenya Highlands. Parasitology, 139(1), 14–25. doi:10.1017/S0031182011001685&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Davies, T. D., &amp;amp; Baum, J. K. (2012). Extinction Risk and Overfishing: Reconciling Conservation and Fisheries Perspectives on the Status of Marine Fishes. Scientific Reports, 2, 1–9. doi:10.1038/srep00561&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fries, R. S. D., Chapin, F. S., &amp;amp; Syvitski, J. (2012). Planetary Opportunities: A Social Contract for Global Change Science to Contribute to a Sustainable Future. BioScience, 62(6), 603–606. doi:10.1525/bio.2012.62.6.11&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shelton, a. O., &amp;amp; Mangel, M. (2011). Reply to Sugihara et al: The biology of variability in fish populations. Proceedings of the National Academy of Sciences, 108(48), E1226–E1226. doi:10.1073/pnas.1115765108&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shelton, A., Dick, E., &amp;amp; Pearson, D. (2012). species composition and quantifying uncertainty in multispecies fisheries: hierarchical Bayesian models for stratified sampling protocols with missing data. … Journal of Fisheries …, 246(5007), 231–246. doi:10.1139/F2011-152&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shelton, A. O., &amp;amp; Mangel, M. (2011). Fluctuations of fish populations and the magnifying effects of fishing. Proceedings of the National Academy of Sciences of the United States of America, 108(17), 7075–80. doi:10.1073/pnas.1100334108&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Esa 2012 Conference</title>
   <link href="/2012/08/10/ESA-2012-Conference.html"/>
   <updated>2012-08-10T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/08/10/ESA-2012-Conference</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;/assets/files/ESA2012_cboettig_schedule.pdf&quot;&gt;My Schedule&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Meetings/discussion with Don Strong, Tony Ives, Marten Scheffer, Justin Yeakel, Karen Abbott, Jarrett Byrnes, Christopher Lortie.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Check in with Paul Armsworth on working group&lt;/li&gt;
&lt;li&gt;rOpenSci tutorial session (below)&lt;/li&gt;
&lt;li&gt;tweetup&lt;/li&gt;
&lt;li&gt;My contributed talk (below)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;ropensci-tutorial-thursday&quot;&gt;rOpenSci tutorial, Thursday&lt;/h2&gt;
&lt;p&gt;A year out from our launch at ESA last year, we presented an introduction and tutorial on rOpenSci. Slides and links to more information are all available at &lt;a href=&quot;http://esa.ropensci.org&quot;&gt;esa.ropensci.org&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;slides-from-my-talk-friday&quot;&gt;Slides from my talk, Friday&lt;/h2&gt;
&lt;iframe src=&quot;http://www.slideshare.net/slideshow/embed_code/13962709?hostedIn=slideshare&amp;page=upload&quot; width=&quot;476&quot; height=&quot;400&quot; frameborder=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot;&gt;&lt;/iframe&gt;


&lt;h2 id=&quot;twitter-notes-generated-from-r&quot;&gt;Twitter Notes (generated from R)&lt;/h2&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;&lt;span class=&quot;kw&quot;&gt;library&lt;/span&gt;(twitteR)
hashtag &amp;lt;- &lt;span class=&quot;st&quot;&gt;&amp;quot;#ESA2012&amp;quot;&lt;/span&gt;
user &amp;lt;- &lt;span class=&quot;st&quot;&gt;&amp;quot;cboettig&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Generate a list of a user’s conference tweets&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;tweets &amp;lt;- &lt;span class=&quot;kw&quot;&gt;twListToDF&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;userTimeline&lt;/span&gt;(user, &lt;span class=&quot;dt&quot;&gt;n =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;500&lt;/span&gt;))
tagged &amp;lt;- &lt;span class=&quot;kw&quot;&gt;grep&lt;/span&gt;(hashtag, tweets$text, &lt;span class=&quot;dt&quot;&gt;ignore.case =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Write to file, making links appear as links&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;text &amp;lt;- tweets$text[tagged]
text &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;(@[A-Za-z0-9_]+)&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;lt;a href=&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;http://twitter.com/&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;1&amp;lt;/a&amp;gt;&amp;quot;&lt;/span&gt;, 
    text)
text&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;my-twitter-notes&quot;&gt;My twitter notes&lt;/h3&gt;
&lt;p&gt;[1] “.&lt;a href=\&quot;http://twitter.com/@luketkelly\&quot;&gt;@luketkelly&lt;/a&gt; uses GAMM for species response from time since fire, interval, intensity, etc, then solves SDP for optimal policy #esa2012”&lt;br /&gt; [2] “.&lt;a href=\&quot;http://twitter.com/@luketkelly\&quot;&gt;@luketkelly&lt;/a&gt; optimizes distrib of time since fire to maximize geom mean of biodiversity - better than arithmetic or shannon. #esa2012”&lt;br /&gt; [3] “.&lt;a href=\&quot;http://twitter.com/@luketkelly\&quot;&gt;@luketkelly&lt;/a&gt; on optimal fire histories for conserving biodiversity #esa2012 w/ amazing images from down under”&lt;br /&gt; [4] “Armsworth’s analysis in eco let http://t.co/w5W8Ubsa #esa2012”&lt;br /&gt; [5] “Armswortth shows paying farmers for biodiversity gains is best when spatially targeted &amp;amp; worse with multispecies targets #esa2012”&lt;br /&gt; [6] “Fun at #esa2012 where a physics PhD student presents the experimental study testing the mathematical theories presented by the ecology PhD”&lt;br /&gt; [7] “Yet another Science paper described at #esa2012 resilience session: warning signals in yeast dynamics http://t.co/QRGwSH2x”&lt;br /&gt; [8] “Michael Pace shows early warning in zooplankton levels in lake ecosystem experiment. #esa2012 Why is cv=1 a special value?”&lt;br /&gt; [9] “David Seekell speaking on conditional #heteroskedacity as an early warning signal of sudden shifts #esa2012”&lt;br /&gt;[10] “See Will’s recent paper for correct link to Doak et al http://t.co/fVclkNM9 #esa2012 (link pdfs from homepages &amp;amp; help a tweep out!)”&lt;br /&gt;[11] “Notes that portfolio effect is inevitable, cites Dan Doak paper: http://t.co/3RDcyI8L need different null #esa2012”&lt;br /&gt;[12] “96% of returning CA salmon come from hatcheries #esa2012”&lt;br /&gt;[13] “Portfolio effects in salmon stocks: do fish manage risk better than bankers? Will Satterthwaite up now #esa2012”&lt;br /&gt;[14] “Alex Perkins examines impact of poor mixing in disease dynamics, draws analogy to #esa2012 mixers. Transmission is a very local process!”&lt;br /&gt;[15] “Learn how 2 get data &amp;amp; full text open access literature/metadata through R/#rstats w/ &lt;a href=\&quot;http://twitter.com/@ropensci\&quot;&gt;@ropensci&lt;/a&gt; 11:30a F150 http://t.co/zkifSTuU #esa2012”&lt;br /&gt;[16] “de Roos just showed how total biomass can increase with &lt;em&gt;increased&lt;/em&gt; mortality. #Wow. #esa2012”&lt;br /&gt;[17] “de Roos: asymmetry/differences in age/size responses (e.g. biomass production) leads to alternate stable states #esa2012”&lt;br /&gt;[18] “Andrre de Roos shows how ontogenetic assymetry (size structure) breaks basic pop dyn predictions #esa2012”&lt;br /&gt;[19] “Check out &lt;a href=\&quot;http://twitter.com/@luketkelly\&quot;&gt;@luketkelly&lt;/a&gt; ’s talk at #esa2012 Friday (10:20a?) #notetoself”&lt;br /&gt;[20] “#esa2012 Come to the &lt;a href=\&quot;http://twitter.com/@nceas\&quot;&gt;@nceas&lt;/a&gt; &amp;amp; &lt;a href=\&quot;http://twitter.com/@sesync\&quot;&gt;@sesync&lt;/a&gt; mixer, 6:30 PM-8:00 PM, in conference center rm F150”&lt;br /&gt;[21] “In case you missed the talk or the links, see &lt;a href=\&quot;http://twitter.com/@jebyrnes\&quot;&gt;@jebyrnes&lt;/a&gt; slides online http://t.co/nCcrvAYE #esa2012”&lt;br /&gt;[22] “.&lt;a href=\&quot;http://twitter.com/@jebyrnes\&quot;&gt;@jebyrnes&lt;/a&gt; mentions Nielsen’s book on online #openscience. Also see his TED talk http://t.co/UkCYR7xV #esa2012”&lt;br /&gt;[23] “.&lt;a href=\&quot;http://twitter.com/@jebyrnes\&quot;&gt;@jebyrnes&lt;/a&gt; reminds us that we live in the 21st century. &amp;quot;Taking the science conversation online&amp;quot; #esa2012”&lt;br /&gt;[24] “Ruckelshaus &lt;a href=\&quot;http://twitter.com/@NatCapProject\&quot;&gt;@NatCapProject&lt;/a&gt; echoes Kareiva’s theme of collaborating with groups you don’t agree with: &amp;quot;I’m with stupid&amp;quot; #esa2012”&lt;br /&gt;[25] “Karevia: Best levers for change are private sector, not public. Don’t testify before congress, but before Walmart &amp;amp; DOW #esa2012”&lt;br /&gt;[26] “Karieva cites G. West on cities and creativity, possibly this paper: http://t.co/WBGJtLTl #esa2012”&lt;br /&gt;[27] “Karevia channels Sarah Palin: how’s that &amp;quot;hope-y change-y thing going?&amp;quot; #esa2012 need more than talking to congress about ecology”&lt;br /&gt;[28] “Olsen: problem isn’t information, it’s informatics (making sense of information) #esa2012”&lt;br /&gt;[29] “Olsen: cites Karevia, biggest problem is scientists cease to be good listeners. #esa2012 Buisnesses hire improv actors to learn this”&lt;br /&gt;[30] “Randy Olsen: scientists evolved from humans. Split was pretty recent. Still have vestiges of story-telling. Don’t lose them! #esa2012”&lt;br /&gt;[31] “Can find the room by the line going deep into the hallway RT &lt;a href=\&quot;http://twitter.com/@carlystrasser\&quot;&gt;@carlystrasser&lt;/a&gt;: .&lt;a href=\&quot;http://twitter.com/@se_hampton\&quot;&gt;@se_hampton&lt;/a&gt; is TEARING IT UP. join the fun A106 #ESA2012” [32] “to be accessible to reviewers RT &lt;a href=\&quot;http://twitter.com/@rOpenSci\&quot;&gt;@rOpenSci&lt;/a&gt;: Ecological Monographs now requires data to be deposited prior to publication #esa2012”&lt;br /&gt;[33] “Ben Bolker on the need for off-the-shelf methods: not enough staticians for every ecologist to have a stats buddy 4 custom methods #esa2012”&lt;br /&gt;[34] “#esa2012 stats discussion: &amp;quot;all modeling is exploratory. If you think AIC confirms your hypothesis, you’re wrong&amp;quot;”&lt;br /&gt;[35] “Yeakel uses perturbations/return rate to estimate elasticity, more senstive to fun. form, see http://t.co/AX3ds7uR #esa2012 #mustread”&lt;br /&gt;[36] “Yeakel cites http://t.co/UYaDso0d on nonpar bayes, compares to generalized models #esa2012”&lt;br /&gt;[37] “Excellent #esa2012 session understand vs predict in modelling. Explores ecologist’s v of Breiman’s &amp;quot;Two Cultures&amp;quot; http://t.co/TIDL87hZ”&lt;br /&gt;[38] “Kellner: Multispecies modelling has biggest impact when including non-consumptive value http://t.co/lj3NN0Be #esa2012”&lt;br /&gt;[39] “Kellner presents rich model for multispecies management of fisheries, see http://t.co/fdopymKB #esa2012”&lt;br /&gt;[40] “Bobby describing disease modeling: humans are essentially widgets that eventually fail #esa2012”&lt;br /&gt;[41] “Not nearly enough room for the crowd outside Karen Abbott’s talk: what’s so special about alternative stable states? #esa2012”&lt;br /&gt;[42] “#esa2012 &lt;a href=\&quot;http://twitter.com/@sesync\&quot;&gt;@sesync&lt;/a&gt; panel live peer-review of audience-submitted ideas. Levin: &amp;quot;It should count: I view social science as subset of ecology&amp;quot;”&lt;br /&gt;[43] “Ray Hilborn &amp;quot;fisheries management is people management&amp;quot; need socio-econ context of ecology. &lt;a href=\&quot;http://twitter.com/@sesync\&quot;&gt;@sesync&lt;/a&gt; #esa2012”&lt;br /&gt;[44] “Molly discusses &amp;quot;most important number you’ve never heard of&amp;quot; - Social cost of carbon #esa2012 &lt;a href=\&quot;http://twitter.com/@sesync\&quot;&gt;@sesync&lt;/a&gt; ($25/ton is current est)”&lt;br /&gt;[45] “Lopez-Hoffman explores equitable water-rights that conserve ecosystem services, e.g. Colarado river use &lt;a href=\&quot;http://twitter.com/@sesync\&quot;&gt;@sesync&lt;/a&gt; #esa2012”&lt;br /&gt;[46] “Levin: cites common-pool resources example from African cattle http://t.co/j35iY3MO #esa2012”&lt;br /&gt;[47] “Simon Levin speaking &lt;a href=\&quot;http://twitter.com/@sesync\&quot;&gt;@sesync&lt;/a&gt; panel: polycentric appches to international agreements on enviro resources #esa2012”&lt;br /&gt;[48] “#esa2012 &lt;a href=\&quot;http://twitter.com/@sesync\&quot;&gt;@sesync&lt;/a&gt; will focus on &amp;quot;wicked problems&amp;quot; (technical term) using theme-driven, interdisciplinary approaches”&lt;br /&gt;[49] “Excellent #esa2012 session intro 2 &lt;a href=\&quot;http://twitter.com/@sesync\&quot;&gt;@sesync&lt;/a&gt;: &amp;quot;if you’re familiar with &lt;a href=\&quot;http://twitter.com/@nceas\&quot;&gt;@nceas&lt;/a&gt;, you’re familiar w/ synthesis&amp;quot;. Now focus on socio-econ + uncert”&lt;br /&gt;[50] “#esa2012 &lt;a href=\&quot;http://twitter.com/@biocreativity\&quot;&gt;@biocreativity&lt;/a&gt; Speaking of art-science collab, don’t forget Dr. Scheffer’s &amp;quot;Critical Transitions, the Movie&amp;quot; http://t.co/2nM6RxL9”&lt;br /&gt;[51] “Lubchenco discusses NOAA’s effort to create climate services like their drought forecasting software: http://t.co/zSRN3Y2U #esa2012”&lt;br /&gt;[52] “Lubchenco’s Q&amp;amp;A brings with disclaimer about Hatch Act: she is speaking for the agency, not the campaign, and can’t answer some Q’s #esa2012”&lt;br /&gt;[53] “At #esa2011 plenary, Pacala encouraged us to spend some time on policy-rel issues. #esa2012 Lubchenco raises the bar: run for office!”&lt;br /&gt;[54] “For instance, to promote outreach, NOAA workers are encouraged to use social media, see their policy: http://t.co/SqSw6UeK #esa2012”&lt;br /&gt;[55] “Lubchenco trumpets success of Magnuson-Stevens Act of 2007 (http://t.co/bOqdasVT) as the policy which will end overfishing #esa2012”&lt;br /&gt;[56] “Lubchenco discusses examples of ecosystem thinking in policy such as the Ocean Policy Task Force: http://t.co/XeyAkQVc #ESA2012”&lt;br /&gt;[57] “#esa2012 Lubchenco on the challenge of scale across ecological, social + econ contexts: highlights DeFries 2012 http://t.co/NEU3AdiQ”&lt;br /&gt;[58] “Jane Lubchenco, opening plenary of #esa2012, dedicates her talk to economics Nobel Laureate Elinor Ostrom http://t.co/XZLEeUnQ”&lt;br /&gt;[59] “.&lt;a href=\&quot;http://twitter.com/@mickresearch\&quot;&gt;@mickresearch&lt;/a&gt; speaker ready rooms are D134 &amp;amp; F152 7a-7p, by reservation(?) (program pg 7). Looking forward to your talk btw #esa2012”&lt;br /&gt;[60] “#esa2012 is trying to facilitate networking for young scientists by labeling cocktail tables by sub-field during tonight’s reception”&lt;br /&gt;[61] “Off to Portland for #esa2012”&lt;/p&gt;
&lt;h3 id=&quot;mentions-at-conference-other-than-retweets&quot;&gt;Mentions at conference, (other than retweets)&lt;/h3&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;mentions &amp;lt;- &lt;span class=&quot;kw&quot;&gt;twListToDF&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;searchTwitter&lt;/span&gt;(&lt;span class=&quot;kw&quot;&gt;paste&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;@&amp;quot;&lt;/span&gt;, user, &lt;span class=&quot;dt&quot;&gt;sep =&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;), 
    &lt;span class=&quot;dt&quot;&gt;n =&lt;/span&gt; &lt;span class=&quot;dv&quot;&gt;300&lt;/span&gt;))
with_hashtag &amp;lt;- &lt;span class=&quot;kw&quot;&gt;grep&lt;/span&gt;(hashtag, mentions$text, &lt;span class=&quot;dt&quot;&gt;ignore.case =&lt;/span&gt; &lt;span class=&quot;ot&quot;&gt;TRUE&lt;/span&gt;)
rt &amp;lt;- &lt;span class=&quot;kw&quot;&gt;grep&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;RT&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;s&amp;quot;&lt;/span&gt;, mentions$text)
me_not_rt &amp;lt;- with_hashtag[!(with_hashtag %in% rt)]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Again, write the output&lt;/p&gt;
&lt;pre class=&quot;sourceCode r&quot;&gt;&lt;code class=&quot;sourceCode r&quot;&gt;text2 &amp;lt;- mentions$text[me_not_rt]
text2 &amp;lt;- &lt;span class=&quot;kw&quot;&gt;gsub&lt;/span&gt;(&lt;span class=&quot;st&quot;&gt;&amp;quot;(@[A-Za-z0-9_]+)&amp;quot;&lt;/span&gt;, &lt;span class=&quot;st&quot;&gt;&amp;quot;&amp;lt;a href=&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;http://twitter.com/&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;st&quot;&gt;1&amp;lt;/a&amp;gt;&amp;quot;&lt;/span&gt;, 
    text2)
text2&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;[1] “. &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; building cost of switching policies into models necessary &amp;amp; provide better outcomes that reduce costs of management #ESA2012”&lt;br /&gt; [2] “. &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; most optimal management strategies produce fluctuations that policy makers don’t like - we can model their dislike! #esa2012”&lt;br /&gt; [3] “.&lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; enthusiastically uniting decision theory and resilience theory for management. Making math exciting! #esa2012”&lt;br /&gt; [4] “Go see &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; (Carl Boettiger’s) talk today in E143 at 920 - he gives a great engaging talk #esa2012”&lt;br /&gt; [5] “#FF #ESA2012 &lt;a href=\&quot;http://twitter.com/@DynamicEcology\&quot;&gt;@DynamicEcology&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@labroides\&quot;&gt;@labroides&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@qaecology\&quot;&gt;@qaecology&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@paulrehrlich\&quot;&gt;@paulrehrlich&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@tessafrancis\&quot;&gt;@tessafrancis&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@lizabio\&quot;&gt;@lizabio&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@gigi_rose\&quot;&gt;@gigi_rose&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@IngaPLaPuma\&quot;&gt;@IngaPLaPuma&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@sarcozona\&quot;&gt;@sarcozona&lt;/a&gt;” [6] “Awesome! MT &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt;: Fun at #esa2012 where physics student presents experiment testing the mathematical theories presented by ecology PhD”&lt;br /&gt; [7] “.&lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; says readme.txt is the best way to keep track of dataset versions. Can version control that on github #ESA2012”&lt;br /&gt; [8] “&lt;a href=\&quot;http://twitter.com/@jasonpriem\&quot;&gt;@jasonpriem&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@_inundata\&quot;&gt;@_inundata&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; Don’t worry- you made an appearance earlier when &lt;a href=\&quot;http://twitter.com/@totalimpactdev\&quot;&gt;@totalimpactdev&lt;/a&gt; was discussed! #ESA2012”&lt;br /&gt; [9] “&lt;a href=\&quot;http://twitter.com/@carlystrasser\&quot;&gt;@carlystrasser&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@_inundata\&quot;&gt;@_inundata&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; Sorry to be missing that! #ESA2012”&lt;br /&gt;[10] “We’ve reached the part of the workshop where .&lt;a href=\&quot;http://twitter.com/@_inundata\&quot;&gt;@_inundata&lt;/a&gt; and &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; slamming MATLAB now… #ESA2012”&lt;br /&gt;[11] “&lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; - let db managers know that you would use a repository + API to share your data with them - move ecology data forward #esa2012”&lt;br /&gt;[12] “.&lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt;: R is a pain to learn. &lt;a href=\&quot;http://twitter.com/@rOpenSci\&quot;&gt;@rOpenSci&lt;/a&gt; packages and tools take advantage of your current knowledge base. #ESA2012”&lt;br /&gt;[13] “&lt;a href=\&quot;http://twitter.com/@ropensci\&quot;&gt;@ropensci&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt;: scripting analyses makes science reproducible, repeatable, &amp;amp; creates an analytical workflow #esa2012”&lt;br /&gt;[14] “.&lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; showing Michener’s Info Entropy Graph: more time passing means less remembered about data #ESA2012”&lt;br /&gt;[15] “&lt;a href=\&quot;http://twitter.com/@jacquelyngill\&quot;&gt;@jacquelyngill&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@treebiology\&quot;&gt;@treebiology&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@jenedavison\&quot;&gt;@jenedavison&lt;/a&gt; would you like to write about #ESA2012 for &lt;a href=\&quot;http://twitter.com/@Scitable\&quot;&gt;@Scitable&lt;/a&gt; http://t.co/tPzaPL2U”&lt;br /&gt;[16] “Fun #ESA2012 tweetup. Nice meeting you! &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@MiriamGoldste\&quot;&gt;@MiriamGoldste&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@SarahBisbing\&quot;&gt;@SarahBisbing&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@bonebraking\&quot;&gt;@bonebraking&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@JacquelynGill\&quot;&gt;@JacquelynGill&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@msanclem\&quot;&gt;@msanclem&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@luketkelly\&quot;&gt;@luketkelly&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@edyong209\&quot;&gt;@edyong209&lt;/a&gt;”&lt;br /&gt;[17] “Check out &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt;’s talk at #ESA2012 Friday 9:20 in E143. Unknown unknowns: management strategies under uncertainty &amp;amp; alt stable states”&lt;br /&gt;[18] “&lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@luketkelly\&quot;&gt;@luketkelly&lt;/a&gt; is at 10:30 on Friday in E144 at #ESA2012. Optimal fire history for conserving biodiversity.”&lt;br /&gt;[19] “#ESA2012 tweetup was a great idea. Nice meeting you guys &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@MiriamGoldste\&quot;&gt;@MiriamGoldste&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@SarahBisbing\&quot;&gt;@SarahBisbing&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@bonebraking\&quot;&gt;@bonebraking&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@JacquelynGill\&quot;&gt;@JacquelynGill&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@msanclem\&quot;&gt;@msanclem&lt;/a&gt; and co”&lt;br /&gt;[20] “Rt &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; in case you missed the talk or the links, see &lt;a href=\&quot;http://twitter.com/@jebyrnes\&quot;&gt;@jebyrnes&lt;/a&gt; slides online http://t.co/cUiwTe23 #esa2012”&lt;br /&gt;[21] “&lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@ropensci\&quot;&gt;@ropensci&lt;/a&gt; for all other journals too I mean. Why not share the data? #esa2012”&lt;br /&gt;[22] “&lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@ropensci\&quot;&gt;@ropensci&lt;/a&gt; agreed. Or at least a subset of data for referees and the readership to access #esa2012”&lt;br /&gt;[23] “&lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; which leads to the suggestion that we need stats mentors and editors in eeb. #esa2012”&lt;br /&gt;[24] “MT &lt;a href=\&quot;http://twitter.com/@forestdim\&quot;&gt;@forestdim&lt;/a&gt;: Inspired by &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; ’s stardom to tweet. Ppl mistaking me 4 &lt;a href=\&quot;http://twitter.com/@edyong209\&quot;&gt;@edyong209&lt;/a&gt;. Need 2 now ride the wave of false ID #ESA2012”&lt;br /&gt;[25] “Yay for Baysian stats! MT &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt;: #esa2012 stats discussion: &amp;quot;If you think AIC confirms your hypothesis, you’re wrong&amp;quot;”&lt;br /&gt;[26] “Why code should be made avail: MT &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; Ben Bolker: not enuf staticians 4 each ecologst to have a stats buddy 4 custom methods #esa2012”&lt;br /&gt;[27] “Conversation at #esa2012 Hastings lab dinner: pole dancing at the 2016 Olympics? http://t.co/slpeBcNA &lt;a href=\&quot;http://twitter.com/@Dr_Bik\&quot;&gt;@Dr_Bik&lt;/a&gt; &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt;”&lt;br /&gt;[28] “&lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; Thanks for the art-science tip! #ESA2012 #biocreativity &amp;quot;Critical Transitions, The Movie&amp;quot; TONIGHT Portland Blrm 251 8-10p”&lt;br /&gt;[29] “Let’s hear it for statistics! MT &lt;a href=\&quot;http://twitter.com/@ropensci\&quot;&gt;@ropensci&lt;/a&gt;: Check out &lt;a href=\&quot;http://twitter.com/@rOpenSci\&quot;&gt;@rOpenSci&lt;/a&gt; developer talks: &lt;a href=\&quot;http://twitter.com/@_inundata\&quot;&gt;@_inundata&lt;/a&gt; Tues 840a, F150 &amp;amp; &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; 920a, E143. #esa2012”&lt;br /&gt;[30] “Not on rOpenSci… MT &lt;a href=\&quot;http://twitter.com/@rOpenSci\&quot;&gt;@rOpenSci&lt;/a&gt;: Check out talks by &lt;a href=\&quot;http://twitter.com/@rOpenSci\&quot;&gt;@rOpenSci&lt;/a&gt; developers: &lt;a href=\&quot;http://twitter.com/@_inundata\&quot;&gt;@_inundata&lt;/a&gt; Tues 8:40 am F150 - &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; 9:20 am E143 #esa2012”&lt;br /&gt;[31] “Check out talks by &lt;a href=\&quot;http://twitter.com/@rOpenSci\&quot;&gt;@rOpenSci&lt;/a&gt; developers: &lt;a href=\&quot;http://twitter.com/@_inundata\&quot;&gt;@_inundata&lt;/a&gt; Tues 8:40 am F150 - &lt;a href=\&quot;http://twitter.com/@cboettig\&quot;&gt;@cboettig&lt;/a&gt; 9:20 am E143 #esa2012”&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Deviations from S = D</title>
   <link href="/2012/07/30/notes.html"/>
   <updated>2012-07-30T00:00:00-07:00</updated>
   <id>http://www.carlboettiger.info/2012/07/30/notes</id>
    
   <category term="//categories.html#ecology" label="ecology"/>
   
   <content type="html">&lt;h3 id=&quot;pdg-control&quot;&gt;pdg-control&lt;/h3&gt;
&lt;h4 id=&quot;value-of-information&quot;&gt;Value of information&lt;/h4&gt;
&lt;p&gt;Exploring causes for deviation from &lt;code&gt;S = D&lt;/code&gt; in the