<?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>John Myles White &#187; Observations</title>
	<atom:link href="http://www.johnmyleswhite.com/notebook/category/observations/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johnmyleswhite.com</link>
	<description>&#34;He who refuses to do arithmetic is doomed to talk nonsense.&#34;</description>
	<lastBuildDate>Wed, 26 Oct 2011 11:36:05 +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>Quick Review of Matrix Algebra in R</title>
		<link>http://www.johnmyleswhite.com/notebook/2009/12/16/quick-review-of-matrix-algebra-in-r/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2009/12/16/quick-review-of-matrix-algebra-in-r/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 03:29:09 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>
		<category><![CDATA[Statistics]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3707</guid>
		<description><![CDATA[Lately, I&#8217;ve been running a series of fMRI experiments on visual perception. In the interests of understanding the underlying properties of the images I&#8217;m using as stimuli, I&#8217;ve been trying to learn more about the matrix transformations commonly used for image compression and image manipulation. Thankfully, R provides simple-to-use implementations for all of the matrix [...]]]></description>
			<content:encoded><![CDATA[<p>Lately, I&#8217;ve been running a series of fMRI experiments on visual perception. In the interests of understanding the underlying properties of the images I&#8217;m using as stimuli, I&#8217;ve been trying to learn more about the matrix transformations commonly used for image compression and image manipulation. Thankfully, R provides simple-to-use implementations for all of the matrix operations I wanted to play around with, so it&#8217;s been quite easy to get started. For the next few posts, I thought that I&#8217;d review the standard matrix techniques for image compression and editing, giving full examples of their implementation in R and demonstrations of their real-world value.</p>
<p>Before I start, I should make sure that you&#8217;re familiar with basic matrix operations in R. I imagine almost every R user knows a little bit about matrix algebra and probably knows the basics of using R to perform matrix algebra, but here&#8217;s a quick review to make sure I don&#8217;t leave anyone in the dark:</p>
<h3>Building Matrices</h3>
<p>You can build a matrix in R using the <code>matrix</code> function:</p>

<div class="wp_codebox"><table><tr id="p370715"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p3707code15"><pre class="c" style="font-family:monospace;">m <span style="color: #339933;">&lt;-</span> matrix<span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> nrow <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> ncol <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> byrow <span style="color: #339933;">=</span> TRUE<span style="color: #009900;">&#41;</span>
&nbsp;
m
<span style="color: #339933;">#      [,1] [,2]</span>
<span style="color: #339933;"># [1,]    1    0</span>
<span style="color: #339933;"># [2,]    0    1</span></pre></td></tr></table></div>

<p>You can test whether an item you&#8217;ve been given is a matrix using <code>is.matrix</code> and you can convert appropriate objects to matrices using <code>as.matrix</code>:</p>

<div class="wp_codebox"><table><tr id="p370716"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p3707code16"><pre class="c" style="font-family:monospace;">m <span style="color: #339933;">&lt;-</span> matrix<span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> nrow <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> ncol <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> byrow <span style="color: #339933;">=</span> TRUE<span style="color: #009900;">&#41;</span>
&nbsp;
is.<span style="color: #202020;">matrix</span><span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#41;</span>
<span style="color: #339933;"># TRUE</span>
&nbsp;
as.<span style="color: #202020;">matrix</span><span style="color: #009900;">&#40;</span>data.<span style="color: #202020;">frame</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">=</span> c<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> y <span style="color: #339933;">=</span> c<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">#      x y</span>
<span style="color: #339933;"># [1,] 1 0</span>
<span style="color: #339933;"># [2,] 0 1</span></pre></td></tr></table></div>

<h3>Diagonal Matrices</h3>
<p>The matrix I&#8217;ve been building in the examples above is a diagonal matrix, so you could also construct it using <code>diag</code>:</p>

<div class="wp_codebox"><table><tr id="p370717"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p3707code17"><pre class="c" style="font-family:monospace;">m <span style="color: #339933;">&lt;-</span> diag<span style="color: #009900;">&#40;</span>nrow <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> ncol <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span>
&nbsp;
m
<span style="color: #339933;">#      [,1] [,2]</span>
<span style="color: #339933;"># [1,]    1    0</span>
<span style="color: #339933;"># [2,]    0    1</span></pre></td></tr></table></div>

<p>In general, you can generate the n by n identity matrix as:</p>

<div class="wp_codebox"><table><tr id="p370718"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p3707code18"><pre class="c" style="font-family:monospace;">n <span style="color: #339933;">&lt;-</span> <span style="color: #0000dd;">10</span>
&nbsp;
diag<span style="color: #009900;">&#40;</span>nrow <span style="color: #339933;">=</span> n<span style="color: #339933;">,</span> ncol <span style="color: #339933;">=</span> n<span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>I&#8217;ll be exploiting a more interesting use of <code>diag</code> in my next post, so let&#8217;s see how you can build matrices other than the identity with <code>diag</code> by specifying a vector of entries along the diagonal:</p>

<div class="wp_codebox"><table><tr id="p370719"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p3707code19"><pre class="c" style="font-family:monospace;">m <span style="color: #339933;">&lt;-</span> diag<span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> nrow <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> ncol <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span>
&nbsp;
m
<span style="color: #339933;">#      [,1] [,2]</span>
<span style="color: #339933;"># [1,]    2    0</span>
<span style="color: #339933;"># [2,]    0    1</span></pre></td></tr></table></div>

<p>This form of <code>diag</code> turns out to be extremely useful, as you&#8217;ll see once I cover the SVD&#8217;s syntax in R.</p>
<h3>Matrix Algebra: Addition, Scalar Multiplication, Matrix Multiplication</h3>
<p>The three core operations that can be performed on matrices are addition, scalar multiplication and matrix multiplication. These are easy to work with in R:</p>

<div class="wp_codebox"><table><tr id="p370720"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p3707code20"><pre class="c" style="font-family:monospace;">m <span style="color: #339933;">&lt;-</span> matrix<span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> nrow <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> ncol <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> byrow <span style="color: #339933;">=</span> TRUE<span style="color: #009900;">&#41;</span>
&nbsp;
m <span style="color: #339933;">+</span> m
<span style="color: #339933;">#      [,1] [,2]</span>
<span style="color: #339933;"># [1,]    0    4</span>
<span style="color: #339933;"># [2,]    2    0</span>
&nbsp;
<span style="color: #0000dd;">2</span> <span style="color: #339933;">*</span> m
<span style="color: #339933;">#      [,1] [,2]</span>
<span style="color: #339933;"># [1,]    0    4</span>
<span style="color: #339933;"># [2,]    2    0</span>
&nbsp;
m <span style="color: #339933;">%*%</span> m
<span style="color: #339933;">#      [,1] [,2]</span>
<span style="color: #339933;"># [1,]    2    0</span>
<span style="color: #339933;"># [2,]    0    2</span></pre></td></tr></table></div>

<p>Be careful with the <code>*</code> operator: it does not perform matrix multiplication, but rather an entry-wise multiplication:</p>

<div class="wp_codebox"><table><tr id="p370721"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p3707code21"><pre class="c" style="font-family:monospace;">m <span style="color: #339933;">*</span> m
&nbsp;
<span style="color: #339933;">#      [,1] [,2]</span>
<span style="color: #339933;"># [1,]    0    4</span>
<span style="color: #339933;"># [2,]    1    0</span></pre></td></tr></table></div>

<h3>Matrix Transposes and Inverses</h3>
<p>The next few matrix operations are a little more complex: transposition and inversion. Transposition is the easier of the two. To get the transpose of a matrix, you simply call the <code>t</code> function:</p>

<div class="wp_codebox"><table><tr id="p370722"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p3707code22"><pre class="c" style="font-family:monospace;">t<span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#41;</span>
<span style="color: #339933;">#      [,1] [,2]</span>
<span style="color: #339933;"># [1,]    0    1</span>
<span style="color: #339933;"># [2,]    2    0</span></pre></td></tr></table></div>

<p>In contrast, inversion is a little more complex, partly because the function you&#8217;d want to use has a non-obvious name: <code>solve</code>.</p>

<div class="wp_codebox"><table><tr id="p370723"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p3707code23"><pre class="c" style="font-family:monospace;">solve<span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #339933;">#      [,1] [,2]</span>
<span style="color: #339933;"># [1,]  0.0    1</span>
<span style="color: #339933;"># [2,]  0.5    0</span></pre></td></tr></table></div>

<p>The reason that <code>solve</code> is called <code>solve</code> is that it&#8217;s a general purpose function you can use to solve matrix equations without wasting time computing the full inverse, which is often inefficient. If you want to know more about the computational efficiency issues, you should look into the ideas behind the even faster variant, <code>qr.solve</code>.</p>
<p>Now, you probably know this already, but the definition of a matrix&#8217;s inverse is that the product of the matrix and its inverse is the identity matrix, if the inverse exists. I always find this a good way to make sure that I&#8217;m correctly computing the inverse of a matrix:</p>

<div class="wp_codebox"><table><tr id="p370724"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p3707code24"><pre class="c" style="font-family:monospace;">solve<span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#41;</span> <span style="color: #339933;">%*%</span> m <span style="color: #339933;">==</span> diag<span style="color: #009900;">&#40;</span>nrow <span style="color: #339933;">=</span> nrow<span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> ncol <span style="color: #339933;">=</span> ncol<span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #339933;">#      [,1] [,2]</span>
<span style="color: #339933;"># [1,] TRUE TRUE</span>
<span style="color: #339933;"># [2,] TRUE TRUE</span></pre></td></tr></table></div>

<h3>Further Matrix Operations</h3>
<p>The <code>car</code> package defines an <code>inv</code> function, which is simply a new name for <code>solve</code>:</p>

<div class="wp_codebox"><table><tr id="p370725"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p3707code25"><pre class="c" style="font-family:monospace;">library<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'car'</span><span style="color: #009900;">&#41;</span>
inv
&nbsp;
<span style="color: #339933;"># function (x) </span>
<span style="color: #339933;"># solve(x)</span>
<span style="color: #339933;"># &lt;environment: namespace:car&gt;</span></pre></td></tr></table></div>

<p>I think this is pretty clever, though I&#8217;m loathe to import a package just for this one snippet.</p>
<p>More interestingly, the <code>MASS</code> package defines a <code>ginv</code> function, which gives the matrix pseudoinverse, a generalization of matrix inversion that works for all matrices:</p>

<div class="wp_codebox"><table><tr id="p370726"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p3707code26"><pre class="c" style="font-family:monospace;">library<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MASS'</span><span style="color: #009900;">&#41;</span>
&nbsp;
m <span style="color: #339933;">&lt;-</span> matrix<span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> nrow <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> ncol <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span>
&nbsp;
solve<span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#41;</span>
<span style="color: #339933;"># Error in solve.default(m) : </span>
<span style="color: #339933;">#  Lapack routine dgesv: system is exactly singular</span>
&nbsp;
ginv<span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#41;</span>
<span style="color: #339933;">#      [,1] [,2]</span>
<span style="color: #339933;"># [1,]  0.1  0.1</span>
<span style="color: #339933;"># [2,]  0.2  0.2</span></pre></td></tr></table></div>

<p>In practice, you can usually get around using the pseudoinverse, but it&#8217;s nice to know that it&#8217;s at hand all the time. </p>
<h3>Eigenvalues and Eigenvectors</h3>
<p>Eigenvectors are surely the bane of every starting student of linear algebra, though their considerable power to simplify problems makes them the darling of every applied mathematician. Thankfully, R makes it easy to get these for every matrix:</p>

<div class="wp_codebox"><table><tr id="p370727"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p3707code27"><pre class="c" style="font-family:monospace;">m <span style="color: #339933;">&lt;-</span> diag<span style="color: #009900;">&#40;</span>nrow <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> ncol <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span>
&nbsp;
eigen<span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#41;</span>
<span style="color: #339933;"># $values</span>
<span style="color: #339933;"># [1] 1 1</span>
<span style="color: #339933;">#</span>
<span style="color: #339933;"># $vectors</span>
<span style="color: #339933;">#      [,1] [,2]</span>
<span style="color: #339933;"># [1,]    0   -1</span>
<span style="color: #339933;"># [2,]    1    0</span></pre></td></tr></table></div>

<h3>Matrix Metadata</h3>
<p>Last, but not least, you can get metadata about the shape of a matrix using <code>dim</code>, <code>nrow</code> and <code>ncol</code>:</p>

<div class="wp_codebox"><table><tr id="p370728"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p3707code28"><pre class="c" style="font-family:monospace;">m <span style="color: #339933;">&lt;-</span> diag<span style="color: #009900;">&#40;</span>nrow <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> ncol <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span>
&nbsp;
dim<span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#41;</span>
<span style="color: #339933;"># [1] 2 2</span>
&nbsp;
nrow<span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#41;</span>
<span style="color: #339933;"># [1] 2</span>
&nbsp;
ncol<span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#41;</span>
<span style="color: #339933;"># [1] 2</span></pre></td></tr></table></div>

<p>Hopefully those operations were already familiar to any readers out there, as I doubt that they&#8217;ll be clear from this short explanation without prior knowledge. I just felt compelled to review them before using any of them in my next set of posts. Tomorrow, I&#8217;ll start going through more interesting matrix algorithms in R, beginning with the SVD.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2009/12/16/quick-review-of-matrix-algebra-in-r/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some Pitfalls of Object Oriented Programming in R</title>
		<link>http://www.johnmyleswhite.com/notebook/2009/12/15/some-pitfalls-of-object-oriented-programming-in-r/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2009/12/15/some-pitfalls-of-object-oriented-programming-in-r/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 18:58:08 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3691</guid>
		<description><![CDATA[Yesterday, I wrote a post about implementing setter methods for objects in R. On my way to understanding how to implement these methods correctly, I made a bunch of mistakes. To keep people from wasting their time with these same mistakes, I&#8217;m reviewing them here. Mistake One: Naming Conventions Every generic method will search for [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I wrote a post about implementing setter methods for objects in R. On my way to understanding how to implement these methods correctly, I made a bunch of mistakes. To keep people from wasting their time with these same mistakes, I&#8217;m reviewing them here.</p>
<h3>Mistake One: Naming Conventions</h3>
<p>Every generic method will search for a class method using a single convention: if the generic method name is <code>GENERIC_METHOD</code> and the class name is <code>CLASS_NAME</code>, then the class method is always <code>GENERIC_METHOD.CLASS_NAME</code>. This is true no matter how strange the generic method looks: the generic method <code>id&lt;-</code> for class <code>user</code> has a class method called </code>id&lt;-.user</code>. The strange <code>&lt;-</code> in the method name doesn't change the fact that <code>.user</code> comes at the end of the class method name.</p>
<h3>Mistake Two: Inspecting Existing Functions with Strange Names</h3>
<p>If you want to get a sense how the function <code>class</code> works, you can simply type <code>class</code> at the R interpreter. Unfortunately, the parsing rules for R insure that this will never work for methods that end in "&lt;-". For that reason, it's not at all clear how to get the definitions of these strangely named functions to come up in the interpreter. When defining these sort of methods, it's sufficient to simply enclose the method name, but that will not work for the purposes of introspection:</p>

<div class="wp_codebox"><table><tr id="p369134"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p3691code34"><pre class="c" style="font-family:monospace;"><span style="color: #ff0000;">'class&lt;-'</span>
&nbsp;
<span style="color: #339933;"># [1] &quot;class&lt;-&quot;</span></pre></td></tr></table></div>

<p>As you can see, <code>'class&lt;-'</code> evaluates to a string, which is neither surprising nor undesirable. Unfortunately, this leaves it unclear how to get at the definition of <code>class&lt;-</code>. The secret for viewing the definitions of these strangely named functions is to enclose the function name in backticks:</p>

<div class="wp_codebox"><table><tr id="p369135"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p3691code35"><pre class="c" style="font-family:monospace;">`class<span style="color: #339933;">&lt;-</span>`
&nbsp;
<span style="color: #339933;"># function (x, value)  .Primitive(&quot;class&lt;-&quot;)</span></pre></td></tr></table></div>

<h3>Mistake Three: Wasting Time on `&lt;&lt;-`</h3>
<p>Before I learned that the trick to writing setter methods is to return an edited copy of the changed object, I was convinced that I needed to evaluate an assignment in the caller's scope. While pursuing this idea, I discovered the <code>&lt;&lt;-</code> operator. It's quite an interesting operator, but it's not the solution to the setter method definition problem.</p>
<p>You see, <code>&lt;&lt;-</code> is an assignment operator that will go searching through enclosing scopes (more precisely, R's environments) until it finds a variable that can be assigned to. Here's an example of how you could use <code>&lt;&lt;-</code> to do something surprising in R:</p>

<div class="wp_codebox"><table><tr id="p369136"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p3691code36"><pre class="c" style="font-family:monospace;">i <span style="color: #339933;">&lt;-</span> <span style="color: #0000dd;">1</span>
&nbsp;
<span style="color: #ff0000;">&quot;++&quot;</span> <span style="color: #339933;">&lt;-</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  i <span style="color: #339933;">&lt;&lt;-</span> i <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #ff0000;">&quot;++&quot;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
&nbsp;
print<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #339933;"># [1] 2</span>
&nbsp;
<span style="color: #ff0000;">&quot;++&quot;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
&nbsp;
print<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #339933;"># [1] 3</span></pre></td></tr></table></div>

<p>This is pretty cool. In fact, it was cool enough that I wasted a good thirty minutes playing with it before realizing that it wasn't helping anything.</p>
<h3>Mistake Four: UseMethod is Magic</h3>
<p>Figuring out how to write code that calls <code>UseMethod</code> for functions with many arguments is not trivial: <code>UseMethod</code>'s behavior is a little magical, and the R help docs are as spartan as ever with regard to calling <code>UseMethod</code>. If you naively try to write a function like this,</p>

<div class="wp_codebox"><table><tr id="p369137"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" id="p3691code37"><pre class="c" style="font-family:monospace;">i <span style="color: #339933;">&lt;-</span> <span style="color: #0000dd;">2</span>
&nbsp;
class<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;-</span> <span style="color: #ff0000;">'myint'</span>
&nbsp;
raise.<span style="color: #202020;">power</span> <span style="color: #339933;">&lt;-</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> power<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  UseMethod<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'raise.power'</span><span style="color: #339933;">,</span> x<span style="color: #339933;">,</span> power<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
raise.<span style="color: #202020;">power</span>.<span style="color: #202020;">myint</span> <span style="color: #339933;">&lt;-</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> power<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span>as.<span style="color: #202020;">numeric</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">**</span> power<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
raise.<span style="color: #202020;">power</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>you'll succeed at defining a generic method that generates warnings every single time it's run. This is because you are never allowed to pass more than two arguments to <code>UseMethod</code>. You see, <code>UseMethod</code> automatically discovers the arguments passed to its caller when it's called and otherwise completely ignores the arguments passed to it after the second argument. For that reason, what you need to write is</p>

<div class="wp_codebox"><table><tr id="p369138"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" id="p3691code38"><pre class="c" style="font-family:monospace;">i <span style="color: #339933;">&lt;-</span> <span style="color: #0000dd;">2</span>
&nbsp;
class<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;-</span> <span style="color: #ff0000;">'myint'</span>
&nbsp;
raise.<span style="color: #202020;">power</span> <span style="color: #339933;">&lt;-</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> power<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  UseMethod<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'raise.power'</span><span style="color: #339933;">,</span> x<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
raise.<span style="color: #202020;">power</span>.<span style="color: #202020;">myint</span> <span style="color: #339933;">&lt;-</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> power<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span>as.<span style="color: #202020;">numeric</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">**</span> power<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
raise.<span style="color: #202020;">power</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>with the latter arguments dropped from the call to <code>UseMethod</code>. If you're like me, you'll probably feel that you're going to lose <code>value</code> along the way the first few times that you write this. I suggest you try this approach out, convince yourself that it works, and then just take advantage of the <code>UseMethod</code> voodoo to solve your problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2009/12/15/some-pitfalls-of-object-oriented-programming-in-r/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Coase and Literary Talent among Scientists</title>
		<link>http://www.johnmyleswhite.com/notebook/2009/10/13/coase-and-literary-talent-among-scientists/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2009/10/13/coase-and-literary-talent-among-scientists/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 18:45:19 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3593</guid>
		<description><![CDATA[There is no reason to suppose that most human beings are engaged in maximizing anything unless it be unhappiness, and even this with incomplete success.1 Why can&#8217;t more scientists write like this? I have the sad impression that most scientists view wit and spirit of this sort as signs of intellectual weakness rather than as [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>
There is no reason to suppose that most human beings are engaged in maximizing anything unless it be unhappiness, and even this with incomplete success.<sup><a href="http://www.johnmyleswhite.com/notebook/2009/10/13/coase-and-literary-talent-among-scientists/#footnote_0_3593" id="identifier_0_3593" class="footnote-link footnote-identifier-link" title="R. H. Coase : The Firm, the Market, and the Law : 1, The Aim of the Book">1</a></sup>
</p></blockquote>
<p>Why can&#8217;t more scientists write like this? I have the sad impression that most scientists view wit and spirit of this sort as signs of intellectual weakness rather than as signs of personal depth.</p>
<ol class="footnotes"><li id="footnote_0_3593" class="footnote">R. H. Coase : The Firm, the Market, and the Law : 1, The Aim of the Book</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2009/10/13/coase-and-literary-talent-among-scientists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hating on Norman Mailer</title>
		<link>http://www.johnmyleswhite.com/notebook/2009/09/06/hating-on-norman-mailer/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2009/09/06/hating-on-norman-mailer/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 22:45:59 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3585</guid>
		<description><![CDATA[This assault on Norman Mailer impresses me more the more times I read it. I&#8217;m not familiar enough with Mailer to judge its accuracy, but the tone is perfect for my taste: His vulgarity was a more significant factor in his allure than whatever he possessed of high aspiration. The way his most serious ambition [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.commentarymagazine.com/viewarticle.cfm/the-naked-novelist-and-the-dead-reputation-15228">This assault on Norman Mailer</a> impresses me more the more times I read it. I&#8217;m not familiar enough with Mailer to judge its accuracy, but the tone is perfect for my taste:</p>
<blockquote><p>
His vulgarity was a more significant factor in his allure than whatever he possessed of high aspiration. The way his most serious ambition was joined to his crassest need made him singularly appealing to a literary public that fed on nonsensical political ideas and fantasies of artistic superstardom, with its fabulous perquisites of cultural ubiquity, wealth, and hot sex.<sup><a href="http://www.johnmyleswhite.com/notebook/2009/09/06/hating-on-norman-mailer/#footnote_0_3585" id="identifier_0_3585" class="footnote-link footnote-identifier-link" title="Algis Valiunas : Commentary Magazine : The Naked Novelist and the Dead Reputation">1</a></sup>
</p></blockquote>
<ol class="footnotes"><li id="footnote_0_3585" class="footnote">Algis Valiunas : Commentary Magazine : <a href="http://www.commentarymagazine.com/viewarticle.cfm/the-naked-novelist-and-the-dead-reputation-15228">The Naked Novelist and the Dead Reputation</a></li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2009/09/06/hating-on-norman-mailer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sick Day Achievements</title>
		<link>http://www.johnmyleswhite.com/notebook/2009/08/28/sick-day-achievements/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2009/08/28/sick-day-achievements/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 23:37:47 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3579</guid>
		<description><![CDATA[Spending my day at home while being sick has at least one perk: I can catch up with everything on the Internet that I&#8217;ve put off reading. After a day of RSS feed reading, I&#8217;ve compiled a list of things that I think are awesome and another list of things that I think are awful. [...]]]></description>
			<content:encoded><![CDATA[<p>Spending my day at home while being sick has at least one perk: I can catch up with everything on the Internet that I&#8217;ve put off reading. After a day of RSS feed reading, I&#8217;ve compiled a list of things that I think are awesome and another list of things that I think are awful.</p>
<p><b>Things I think are awesome:</b></p>
<ol>
<li>Robots will take over the world one day: after all, here&#8217;s <a href="http://hackaday.com/2009/08/24/lego-mindstorms-sudoku-solver/">a Sudoku-solving Lego Mindstorms robot.</a></li>
<li>Even better, there&#8217;s also <a href="http://www.tiltedtwister.com/index.html">a Rubik&#8217;s Cube-solving Lego Mindstorms robot.</a></li>
<li>My friend Jim Keller&#8217;s latest project was featured on <a href="http://drupal.org/node/552628">the Drupal main page today.</a></li>
<li><a href="http://www.nature.com/news/2009/090828/full/news.2009.870.html">Those cheating chimpanzee women</a> are not to be trusted.</li>
<li>How often <a href="http://www.congressspeaks.com/">does your Congressperson speak up?</a></li>
<li>Here&#8217;s <a href="http://stochastix.wordpress.com/2009/08/27/carnival-of-mathematics-56/">the 56th Carnival of Mathematics</a></li>
<li>Cognitive psychology has something to say about the use of <a href="http://scienceblogs.com/cognitivedaily/2009/08/la_raison_i_had_to_learn_gende.php">gendered words in language.</a></li>
<li><a href="http://econlog.econlib.org/archives/2009/08/how_to_stay_sol.html">A clever scheme</a> from Bryan Caplan for making money in an irrational economy.</li>
<li>Because <a href="http://vimeo.com/6316588">repelling just gets boring after a while.</a></li>
</ol>
<p><b>Things I think are awful:</b></p>
<ol>
<li><a href="http://www.cato-at-liberty.org/2009/08/28/in-massachusetts-the-rule-of-law-dies/">The Rule of Law is flouted once again</a> by an American state.</li>
<li>Swedish regulation <a href="http://techdirt.com/articles/20090827/1929016027.shtml">at its stupidest.</a></li>
<li>Englewood <a href="http://www.nytimes.com/2009/08/28/nyregion/28tent.html?_r=2&#038;hpw">has a little town drama.</a></li>
<li>Most cyclists are killed by <a href="http://www.projectfreeride.org/team/cycling_health_and_safety/index.php?slide=2">terrible drivers.</a></li>
<li>Still think that our <a href="http://www.law.com/jsp/article.jsp?id=1202433411400&#038;Former_NY_Judge_Convicted_of_Attempted_Extortion_and_Soliciting_Bribes">government officials can be trusted?</a></li>
<li>Eugene Volokh notes <a href="http://volokh.com/posts/1251405593.shtml">a recent and dangerous precedent for homeschoolers</a> in a case that he wishes never had to be decided by the legal system.</li>
<li>The public <a href="http://pewresearch.org/pubs/1324/blogs-zombie-study-cocaine-in-circulation">really, really has prurient taste.</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2009/08/28/sick-day-achievements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stagger Lee</title>
		<link>http://www.johnmyleswhite.com/notebook/2009/05/18/stagger-lee/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2009/05/18/stagger-lee/#comments</comments>
		<pubDate>Mon, 18 May 2009 00:00:49 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3547</guid>
		<description><![CDATA[To know a man, you need only find out how he envisions the story of Stagger Lee.]]></description>
			<content:encoded><![CDATA[<p>To know a man, you need only find out how he envisions the story of <a href="http://en.wikipedia.org/wiki/Stagger_Lee_(song)">Stagger Lee</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2009/05/18/stagger-lee/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Painted Veil</title>
		<link>http://www.johnmyleswhite.com/notebook/2009/04/09/the-painted-veil/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2009/04/09/the-painted-veil/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 00:17:37 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3490</guid>
		<description><![CDATA[I watched the Painted Veil again tonight. I&#8217;m always amazed by the quality of the story and the dialogue: while I understand that it&#8217;s an adaptation of a classic novel, I am nevertheless continually astonished that such a good movie should ever have been released. There is just such a wealth of wonderful points about [...]]]></description>
			<content:encoded><![CDATA[<p>I watched the Painted Veil again tonight. I&#8217;m always amazed by the quality of the story and the dialogue: while I understand that it&#8217;s an adaptation of a classic novel, I am nevertheless continually astonished that such a good movie should ever have been released. There is just such a wealth of wonderful points about the subtler parts of love, affection and betrayal:</p>
<blockquote><p>
Do you know what I find strange? That your husband should never look at you. He looks at the walls, the floor, his shoes&#8230;<sup><a href="http://www.johnmyleswhite.com/notebook/2009/04/09/the-painted-veil/#footnote_0_3490" id="identifier_0_3490" class="footnote-link footnote-identifier-link" title="The Painted Veil">1</a></sup>
</p></blockquote>
<ol class="footnotes"><li id="footnote_0_3490" class="footnote">The Painted Veil</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2009/04/09/the-painted-veil/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The ISS Surpasses Venus</title>
		<link>http://www.johnmyleswhite.com/notebook/2009/03/10/the-iss-surpasses-venus/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2009/03/10/the-iss-surpasses-venus/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 00:41:06 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3458</guid>
		<description><![CDATA[I think there&#8217;s something beautiful about the International Space Station becoming the brightest object in the night sky after the Moon.]]></description>
			<content:encoded><![CDATA[<p>I think there&#8217;s something beautiful about the International Space Station becoming <a href="http://spacefellowship.com/News/?p=8379">the brightest object in the night sky</a> after the Moon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2009/03/10/the-iss-surpasses-venus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anatman</title>
		<link>http://www.johnmyleswhite.com/notebook/2009/03/04/anatman/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2009/03/04/anatman/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 13:40:02 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3438</guid>
		<description><![CDATA[The New York Times has a remarkable story up about a New York school teacher who went missing for almost a month after suffering from a case of dissociative fugue. I particularly enjoy how the article portrays the fragility of a self and the potential for massive disconnection from our memories. Also fascinating is the [...]]]></description>
			<content:encoded><![CDATA[<p>The New York Times has <a href="http://www.nytimes.com/2009/03/01/nyregion/thecity/01miss.html?pagewanted=1">a remarkable story</a> up about a New York school teacher who went missing for almost a month after suffering from a case of dissociative fugue. I particularly enjoy how the article portrays the fragility of a self and the potential for massive disconnection from our memories.</p>
<p>Also fascinating is the woman&#8217;s assertion that &#8220;she can&#8217;t let New York win.&#8221; I am always surprised that non-native New Yorkers choose to live in a city that they view as an adversary. New York has always been home to me; sometimes it is too garish or agitating for me to stand, but it has never been an opponent to compete with in an effort to prove my ability to endure. If anything, the hardest thing for me is imagining living perpetually far away from New York.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2009/03/04/anatman/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Late Night Flippancy</title>
		<link>http://www.johnmyleswhite.com/notebook/2009/02/05/late-night-flippancy/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2009/02/05/late-night-flippancy/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 04:57:33 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3343</guid>
		<description><![CDATA[If history is so corrupted by patriarchical mores that it should be called herstory, should histograms be called herstograms?]]></description>
			<content:encoded><![CDATA[<p>If history is so corrupted by patriarchical mores that it should be called herstory, should histograms be called herstograms?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2009/02/05/late-night-flippancy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>United States Botantical Gardens</title>
		<link>http://www.johnmyleswhite.com/notebook/2009/01/26/united-states-botantical-gardens/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2009/01/26/united-states-botantical-gardens/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 05:04:44 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3283</guid>
		<description><![CDATA[If only everything in the world looked as good in photographs as the flowers in the United States Botantical Gardens:]]></description>
			<content:encoded><![CDATA[<p>If only everything in the world looked as good in photographs as the flowers in the <a href="http://www.usbg.gov/">United States Botantical Gardens:</a></p>
<div style="text-align:center;"><img src="http://www.johnmyleswhite.com/notebook/wp-content/uploads/2009/01/dsc05599.jpg" alt="DSC05599.JPG" border="0" width="480" height="640" /></div>
]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2009/01/26/united-states-botantical-gardens/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pedagogical Strategies</title>
		<link>http://www.johnmyleswhite.com/notebook/2009/01/06/pedagogical-strategies/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2009/01/06/pedagogical-strategies/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 20:02:14 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>
		<category><![CDATA[pedagogy induction deduction abstraction]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3254</guid>
		<description><![CDATA[My advice to teachers of mathematics: explain the intuition behind every theorem. Students can look up the statement of a theorem for themselves: you only add value if you give students a broader perspective by articulating the intuition that accompanies and underlies the formal details of a theorem. This intuition is not merely a sign [...]]]></description>
			<content:encoded><![CDATA[<p>My advice to teachers of mathematics: explain the intuition behind every theorem. Students can look up the statement of a theorem for themselves: you only add value if you give students a broader perspective by articulating the intuition that accompanies and underlies the formal details of a theorem.</p>
<p>This intuition is not merely a sign of the mathematical weakness of the human mind, but rather speaks to the essence of human understanding. From the intuition, an intelligent student can usually recreate the theorem, but the theorem does not readily lead to the intuition. This should suffice to show that the intuition is more powerful than the formal theorem.</p>
<p>History also reveals this pattern: the calculus, built upon the idea of limits, began with the intuition that limits existed. Substantial development took place in calculus before limits were formalized rigorously. Similarly, many of the counter-intuitive formulas in statistics are newcomers on the scene: the denominator of the sample variance formula was N for many decades before it became clear to statisticians that this formula led to a biased estimate of the population variance. Understanding the modern variance formula is impossible unless students are introduced to the concepts of expected value and bias: both of which are usually covered only cursorily &#8212; if at all &#8212; in introductory statistics courses. Students are therefore made to memorize formulas they cannot possibly understand &#8212; and which many of the great statisticians of history did not understand either. The subject of statistics, like much of mathematics, is made needlessly complicated by this insistence upon memorization rather than understanding.</p>
<p>Many teachers do not provide students with this perspective because they are unaware of it: they themselves simply memorized the formulas at the beginning and came &#8212; or did not come &#8212; over time to the intuition behind them. Historical ignorance pervades mathematics, in which historical development is too often felt to be irrelevant. This is doubly unfortunate: it obfuscates mathematical ideas that were inspired by intuitions that could be articulated clearly to students, and it makes the subject seem to have been developed more easily than it was. By concealing the difficulty of mathematical progress, mathematics is made to seem easier than it is &#8212; which has the effect of degrading the student who does not find mathematics as easy as it is made to seem.</p>
<p>But perhaps the worst consequence of this indifference to intuitions is that it makes mathematics seem like catechism class, when it should be an education in skepticism and rigor. Mathematics, like life, is a process, rather than a series of results. Any branch of mathematics could be taught to high school students to prepare them for advanced studies in mathematics: if the topic were covered rigorously, the students would be prepared to learn any other topic much more quickly. This is a consequence of the inescapable consilience of mathematics: the same core ideas occur in every branch of mathematics. It is the habit of mathematical thinking that is essential, not the results. Yet students rarely acquire this habit: the majority of students who succeed in their classes merely memorize the formulas that pass from the textbook to the blackboard to their notebooks without passing through either the instructor or the student&#8217;s mind.</p>
<p>Abstractions in the absence of strong examples are also pedagogically unsound: the human brain is far better at receiving clear examples and extracting generalizations from these examples than it is at deriving the implications of generalizations and applying these to new examples. The best textbooks in any field tend to be those that contain a small set of extremely clear examples that can be understood deeply and in their entirety. This is true not simply in mathematics, but also in programming and other fields. Kernighan and Richie&#8217;s &#8220;The C Programming Language&#8221; is such an amazing book because the reader is able to understand every single line of every example. Few other introductions to programming languages have been as clear as Kernighan and Richie&#8217;s because this principle has tended to be avoided. General rules must be learned in context, and the context must be comprehensible in its entirety.</p>
<p>In the end, these two traits are the essence of intuition: one understands something entirely and one can articulate a precise example of its application. If this were imparted to more students, a mathematically literature student body might emerge.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2009/01/06/pedagogical-strategies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linear Regression and Decisions about Sampling</title>
		<link>http://www.johnmyleswhite.com/notebook/2008/12/26/linear-regression-and-decisions-about-sampling/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2008/12/26/linear-regression-and-decisions-about-sampling/#comments</comments>
		<pubDate>Fri, 26 Dec 2008 18:03:08 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3225</guid>
		<description><![CDATA[Lately I&#8217;ve been thinking about the optimal strategy for data collection when you plan to run a linear regression. Clearly, you want a sample of widely distributed points if you&#8217;re unsure that a strict linearity assumption is appropriate. If you already know from theoretical reasons that linearity is appropriate, then you know that you only [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been thinking about the optimal strategy for data collection when you plan to run a linear regression. Clearly, you want a sample of widely distributed points if you&#8217;re unsure that a strict linearity assumption is appropriate. If you already know from theoretical reasons that linearity is appropriate, then you know that you only need two correct (x, y) data points to uniquely define the regression line. To get this, one conventionally samples many (x, y) pairs and then computes the regression line&#8217;s slope and intercept. Why not sample only two x data points over and over again instead? If you are trying to find the formula for the line E[y | x], it seems reasonable to assume that high quality estimates of the points (a, E[y | x = a]) and (b, E[y | x = b]) would be a good way to do this.</p>
<p>Is this a reasonable approach to two variable linear regressions? Is this approach less efficient statistically than sampling at many points? Or is the reason to avoid this strategy in practice is that one is uncertain of the validity of the linearity assumption in all but exceptional cases?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2008/12/26/linear-regression-and-decisions-about-sampling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moral Responsibility</title>
		<link>http://www.johnmyleswhite.com/notebook/2008/11/06/moral-responsibility/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2008/11/06/moral-responsibility/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 03:43:43 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3183</guid>
		<description><![CDATA[Responsibility, in the moral sense, is not a property of actors, but merely a confabulation on our part designed for one and only one purpose: to justify the suffering we inflict upon others. This holds equally well in regard to matters of retributive and distributive justice: responsibility is a mere holdover from an antiquated conception [...]]]></description>
			<content:encoded><![CDATA[<p>Responsibility, in the moral sense, is not a property of actors, but merely a confabulation on our part designed for one and only one purpose: to justify the suffering we inflict upon others. This holds equally well in regard to matters of retributive and distributive justice: responsibility is a mere holdover from an antiquated conception of the world.</p>
<p>It is not responsibility, but the estimation of conditional recidivism that should concern any legal system.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2008/11/06/moral-responsibility/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Social Scientism</title>
		<link>http://www.johnmyleswhite.com/notebook/2008/11/02/social-scientism/</link>
		<comments>http://www.johnmyleswhite.com/notebook/2008/11/02/social-scientism/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 20:12:02 +0000</pubDate>
		<dc:creator>John Myles White</dc:creator>
				<category><![CDATA[Observations]]></category>

		<guid isPermaLink="false">http://www.johnmyleswhite.com/?p=3177</guid>
		<description><![CDATA[I find extraordinary the readiness with which members of certain branches of the social sciences latch onto obscure and irrelevant findings in the natural sciences as means of buttressing their views. This habit convinces me that their work is, as Hayek would say, merely scientistic &#8212; that their life&#8217;s work is the application of a [...]]]></description>
			<content:encoded><![CDATA[<p>I find extraordinary the readiness with which members of certain branches of the social sciences latch onto obscure and irrelevant findings in the natural sciences as means of buttressing their views. This habit convinces me that their work is, as Hayek would say, merely scientistic &#8212; that their life&#8217;s work is the application of a whitewash of scientific terminology to what is merely an exposition of their moral convictions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnmyleswhite.com/notebook/2008/11/02/social-scientism/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.460 seconds -->

