<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Brandon Erik Bertelsen</title>
	<atom:link href="http://bertelsen.ca/feed" rel="self" type="application/rss+xml" />
	<link>http://bertelsen.ca</link>
	<description>Nothing of particular relevance...</description>
	<lastBuildDate>Sun, 19 Feb 2012 22:58:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>An Introduction to Reproducible Research with R Part 1</title>
		<link>http://bertelsen.ca/articles/an-introduction-to-reproducible-research-with-r-part-1?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=an-introduction-to-reproducible-research-with-r-part-1</link>
		<comments>http://bertelsen.ca/articles/an-introduction-to-reproducible-research-with-r-part-1#comments</comments>
		<pubDate>Tue, 14 Feb 2012 08:48:24 +0000</pubDate>
		<dc:creator>Brandon Bertelsen</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://bertelsen.ca/?p=86</guid>
		<description><![CDATA[The concept is simple, provide a set of files that anyone can use to recreate your output in exactly the same fashion that you have. Reproducible Research is not new. The ability to look back and say &#8220;here is how...]]></description>
			<content:encoded><![CDATA[<p>The concept is simple, provide a set of files that anyone can use to recreate your output in exactly the same fashion that you have. <a title="Reproducible Research on Wikipedia" href="http://en.wikipedia.org/wiki/Reproducibility#Reproducible_research">Reproducible Research</a> is not new. The ability to look back and say &#8220;here is how we did that&#8221; &#8211; is worth the extra time required to do so. R is an effective way to generate large amounts of customized reporting in a very short time span, with limited room for error (with a bit of forethought) and a relatively small amount of time. This concept can be extended to generating reports for large distributions or even more customized or exploratory reporting.</p>
<p>With R this is quite simple. The most common method used is to create an <code>*.Rnw</code> file that loads all of your libraries, data and calculations within. Sharing this file makes it easy for others to simply reproduce your output and regenerate your code. Below is a really simple example of the results of a linear regression on auto-generated data. For the time being, we will not go into much detail about <a href="http://www.statistik.lmu.de/~leisch/Sweave/" title="Sweave Introduction">Sweave</a>, but you should know &#8211; it&#8217;s the magic behind getting your R code into a format that can be converted into PDF.</p>
<p>Here are just a few usage case scenarios</p>
<ul>
<li>High quality, corporate themed articles and reports that are easy to duplicate or recreate</li>
<li>Customized reports, for business intelligence, marketing research, or data mining exercises</li>
<li>Reporting on financial data, or metrics.</li>
<li>Human readable tables for model selection or parameter interpretation</li>
<li>Exploratory data analysis: plot and tabulate everything, interpret later</li>
</ul>
<p>The real challenge that surrounds reproducible research with R, is learning LaTex. It&#8217;s an old format and there are quite a few peculiarities that you will encounter that are neither immediately obvious nor intuitive. Let&#8217;s keep this in mind.</p>
<p>However, there are a few really useful places for information on using LaTex:</p>
<ol>
<li><a title="Latex Intro" href="http://en.wikibooks.org/wiki/LaTeX/Introduction">Introduction to Latex</a> Before you begin, you <strong>must</strong> read it and follow the installation instructions for your operating system. It is an excellent source of information for a beginner and tackles many of the frequently asked questions that would generally crush one&#8217;s soul otherwise</li>
<li><a title="Tex Stackexchange Q&amp;A" href="http://tex.stackexchange.com/">Tex Stackexchange</a> is where you go if your problem is more specific to LaTeX, you can always get a quick answer from real people there</li>
<li>And of course, there&#8217;s <a title="Stack Overflow" href="http://stackoverflow.com">Stack Overflow</a> for questions pertaining to R</li>
</ol>
<p>Without further ado, let&#8217;s create a small piece of reproducible research</p>
<ul>
<li>Here is the <a href="http://bertelsen.ca/wp-content/uploads/2012/02/Example.Rnw" title="Example Rnw file">Rnw file</a></li>
<li>And here is the <a href="http://bertelsen.ca/wp-content/uploads/2012/02/Example.pdf" title="Example PDF file">resulting PDF</a></li>
</ul>

<div class="wp_codebox"><table><tr id="p863"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code" id="p86code3"><pre class="latex" style="font-family:monospace;"><span style="color: #2C922C; font-style: italic;">% Preamble</span>
<span style="color: #E02020; ">\</span><span style="color: #800000;">documentclass</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Article</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><span style="color: #800000;">usepackage</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Sweave</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #2C922C; font-style: italic;">% Start Document</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #2C922C; font-style: italic;">% Titlepage</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">titlepage</span></span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><span style="color: #800000;">title</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">A Title</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><span style="color: #800000;">author</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Author's Name</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><span style="color: #800000;">date</span> <span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">\<span style="color: #800000;">today</span></span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><span style="color: #800000;">maketitle</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">titlepage</span></span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #2C922C; font-style: italic;">% Content Begins</span>
&nbsp;
<span style="color: #E02020; ">\</span><span style="color: #800000;">section</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">A Linear Regression</span><span style="color: #E02020; ">}</span>
&nbsp;
Here, we generate some sample data. By default, sweave echoes the results - showing
us what commands are run in R. But we can stop that in our code chunk by specifying
 &quot;echo=FALSE&quot;. In the example below, we will generate random variables from the
 normal and uniform distribution, put them in a data frame, run a linear regression
 and output a table that shows us the pertinent information from the regression.  
&nbsp;
<span style="color: #2C922C; font-style: italic;">% R Code Chunk</span>
&lt;&lt;echo=FALSE, results=tex&gt;&gt;=
library(xtable)
set.seed(1234) # Set seed for RNG
x &lt;- rnorm(100) # Generate a vector of 100 random numbers from the normal distribution
y &lt;- runif(100) # Generate a vector of 100 random numbers from the uniform distribution 
dat &lt;- data.frame(x,y) # Create a data.frame object
fit &lt;- lm(y ~ x, dat) # Fit x and y as a linear model in the form y= x + a
xtable(summary(fit)) # Output a latex summary of the results
@ 
&nbsp;
<span style="color: #E02020; ">\</span><span style="color: #800000;">subsection</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Plotting Example</span><span style="color: #E02020; ">}</span>
It is also quite simple to include plots and graphics. Resizing them, is quite
 painful if you are generating them automatically. My recommendation is to always
 save them as a seperate file, and then place them. But for the sake of example,
 here is a plot of Residuals vs. Fitted from our model and Normal Q-Q. Note, that
 when we want the output of a figure we have to specify &quot;fig=TRUE&quot; for our code chunk:
&nbsp;
<span style="color: #2C922C; font-style: italic;">% R Code Chunk</span>
&lt;&lt;echo=FALSE, fig=TRUE&gt;&gt;=
plot(fit, which=1)
@
&nbsp;
<span style="color: #2C922C; font-style: italic;">% End Document</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span></pre></td></tr></table></div>

<p>Now, it&#8217;s a fairly simple matter of setting your working directory and running a few more lines of code in R. If you&#8217;re using <a href="http://rstudio.org" title="RStudio IDE for R">RStudio</a> (which I highly recommend) you can simply open the Rnw file and click on &#8220;CompilePDF&#8221; on the toolbar. From the console:</p>

<div class="wp_codebox"><table><tr id="p864"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p86code4"><pre class="rsplus" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">setwd</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'path/to/Example.Rnw/'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">Sweave</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'Example.Rnw'</span><span style="color: #080;">&#41;</span>
texi2pdf<span style="color: #080;">&#40;</span><span style="color: #ff0000;">'Example.tex'</span><span style="color: #080;">&#41;</span></pre></td></tr></table></div>

<p>That&#8217;s a wrap. </p>
]]></content:encoded>
			<wfw:commentRss>http://bertelsen.ca/articles/an-introduction-to-reproducible-research-with-r-part-1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove &#8220;Leave a response&#8221; from hybrid theme</title>
		<link>http://bertelsen.ca/articles/remove-leave-a-response-from-hybrid-theme?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=remove-leave-a-response-from-hybrid-theme</link>
		<comments>http://bertelsen.ca/articles/remove-leave-a-response-from-hybrid-theme#comments</comments>
		<pubDate>Sun, 12 Feb 2012 03:13:39 +0000</pubDate>
		<dc:creator>Brandon Bertelsen</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://bertelsen.ca/?p=26</guid>
		<description><![CDATA[If you are using disqus to manage your websites feedback and commentary. You may prefer to remove the built in hooks for WordPress&#8217;s build in comment system while using the hybrid theme1. In ./wp-content/themes/hybrid/functions.php On line 242, find the following...]]></description>
			<content:encoded><![CDATA[<p>If you are using disqus to manage your websites feedback and commentary. You may prefer to remove the built in hooks for WordPress&#8217;s build in comment system while using the hybrid theme<sup class='footnote'><a href='http://bertelsen.ca/articles/remove-leave-a-response-from-hybrid-theme#fn-26-1' id='fnref-26-1' onclick='return fdfootnote_show(26)'>1</a></sup>.</p>
<p>In <code>./wp-content/themes/hybrid/functions.php</code></p>
<p>On line 242, find the following code:</p>

<div class="wp_codebox"><table><tr id="p267"><td class="line_numbers"><pre>242
</pre></td><td class="code" id="p26code7"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$meta</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">.</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'[entry-terms taxonomy=&quot;category&quot; before=&quot;Posted in &quot;] [entry-terms taxonomy=&quot;post_tag&quot; before=&quot;| Tagged &quot;] [entry-comments-link before=&quot;| &quot;]'</span><span style="color: #339933;">,</span> hybrid_get_textdomain<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And replace it with the following line:</p>

<div class="wp_codebox"><table><tr id="p268"><td class="line_numbers"><pre>242
</pre></td><td class="code" id="p26code8"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$meta</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">.</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'[entry-terms taxonomy=&quot;category&quot; before=&quot;Posted in &quot;] [entry-terms taxonomy=&quot;post_tag&quot; before=&quot;| Tagged &quot;]'</span><span style="color: #339933;">,</span> hybrid_get_textdomain<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Voila, you&#8217;re finished.</p>
]]></content:encoded>
			<wfw:commentRss>http://bertelsen.ca/articles/remove-leave-a-response-from-hybrid-theme/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loading Fundserve Data into R</title>
		<link>http://bertelsen.ca/articles/lorem-ipsum?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=lorem-ipsum</link>
		<comments>http://bertelsen.ca/articles/lorem-ipsum#comments</comments>
		<pubDate>Sat, 11 Feb 2012 10:05:13 +0000</pubDate>
		<dc:creator>Brandon Bertelsen</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://bertelsen.ca/?p=8</guid>
		<description><![CDATA[If, like me, you do a bit of work with mutual fund data across a number of sources, you&#8217;ll eventually need to pull in the dealer codes or the fund codes. Below is a working example of how to pull in active...]]></description>
			<content:encoded><![CDATA[<p>If, like me, you do a bit of work with mutual fund data across a number of sources, you&#8217;ll eventually need to pull in the dealer codes or the fund codes. Below is a working example of how to pull in active dealership codes</p>

<div class="wp_codebox"><table><tr id="p810"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p8code10"><pre class="rsplus" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&#40;</span>XML<span style="color: #080;">&#41;</span>
theurl <span style="color: #080;">&lt;-</span> <span style="color: #ff0000;">&quot;http://www.fundserv.com/services/code-lists.php?status_type=1&amp;file_type=d&quot;</span>
dealer.<span style="">codes</span> <span style="color: #080;">&lt;-</span> readHTMLTable<span style="color: #080;">&#40;</span>theurl<span style="color: #080;">&#41;</span>
n.<span style="">rows</span> <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">unlist</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">lapply</span><span style="color: #080;">&#40;</span>dealer.<span style="">codes</span>, <span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">t</span><span style="color: #080;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">dim</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">t</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#91;</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
dealer.<span style="">codes</span> <span style="color: #080;">&lt;-</span> dealer.<span style="">codes</span><span style="color: #080;">&#91;</span><span style="color: #080;">&#91;</span><span style="color: #0000FF; font-weight: bold;">which.<span style="">max</span></span><span style="color: #080;">&#40;</span>n.<span style="">rows</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#93;</span></pre></td></tr></table></div>

<p>Minor adjustments of the method above can be used to pull any most types of tabular data from a webpage to R.</p>
]]></content:encoded>
			<wfw:commentRss>http://bertelsen.ca/articles/lorem-ipsum/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

