September 17, 2009

RMatlab - Using R from Matlab!

RMatlab is a wonderful package I just discovered.  It interfaces R and Matlab.  I use it to make sexy figure from within Matlab.  (The alternative is to export data, import it to R, and make a figure.  It's possible, but a big pain.)  The package works great, but I found it slightly difficult to get working.  Here are the steps I took.

Continue reading "RMatlab - Using R from Matlab!" »

May 4, 2009

Appendix Slides in Beamer: Controlling frame numbers

A fellow student, Andrew Bradley, and I had a chat today about a feature missing from the beamer package in Latex: fine control over slide numbers.  We both subscribe to the philosophy that a each slide in a presentation should have a slide number and the total number of slides.  (An old professor strongly advocated this approach so that he could critique individual slides and had some idea of how much was left.)

Beamer makes it somewhat difficult to accommodate this system if you have backup slides in your presentation.  You know, those things you are supposed to have prepared in case you get one of the "hard" questions?  Anyway, these slides aren't a part of the standard presentation, and so they shouldn't count to the total slide number --- but they need to be there in your presentation file.

I had previously faced this issue and realized that you can just store and set the frame numbers in beamer at arbitrary points in the presentation.

% All your regular slides
% After your last numbered slide
\appendix
\newcounter{finalframe}
\setcounter{finalframe}{\value{framenumber}}
% Backup frames
\setcounter{framenumber}{\value{finalframe}}
\end{document}

However, Andrew wanted to go beyond just skipping backup slides and "uncount" the outline slides that appear at the beginning of a section, as well as the title slide.  He proposed using the trick above with the following adjustments.

1. Add \addtocounter{framenumber}{-1} on the \AtBeginSubsection frame
2. Add \setcounter{framenumber}{0} or \setcounter{framenumber}{1}
   to the \titlepage frame and/or the \tableofcontents frame
   depending on taste.

There you have it, all the tricks about frame counters in beamer that we know!

I suspect there is some way to accomplish the "backup" slides with a modification of the \appendix command and the \AtEndDocument directive.  My brief attempt at making these changes ended in failure and frustration.  Failure because it didn't work.  Frustration because I forgot to write down that it didn't work and didn't remember it the next time I wanted to use this feature.  (In fact, I really wish that beamer modified the \appendix command to implement precisely this feature.  What else would an appendix do in a presentation?)

April 17, 2009

Birthday distribution

Many of my friends have birthdays in the next few weeks.  This fact prompted a discussion about the uniformity of birthdays.  In Outliers, Gladwell makes the case that birthdays of a group of individuals may appear skewed for subtle reasons; however such results shouldn't hold for the populace.

This question is easy to answer with a bit of Googling.  A Dartmouth professor has precisely the required data --- though only for a single year.

http://www.dartmouth.edu/~chance/teaching_aids/data/birthday.txt

I used R to make a quick display of the data.

Cutting and pasting this into R produces the following output for me.
dob-distribution

No, that isn't a data problem.  There really are two groups of birthdays.

While looking for the overall date of birth data, I discovered another file from the CDC that explains the effect.

http://www.cdc.gov/nchs/data/statab/t941x16.pdf

The data in that file show many fewer births on weekends compared with weekdays.  This effect is precisely what we see in the plot, which R helps us validate.

dob-dayofweek

This analysis was good enough for my own personal edification.  There is still a bit of work left to make these claims statistically valid, but that isn't my point here.