R | Jason Bryer

R

User Input using tcl/tk

I was inspired by Kay Cichini recent post on creating a a tcl/tk dialog box for users to enter variable values. I am going to have a use for this very soon so took some time to make it a bit more generic. What I wanted is a function that takes a vector (of variable names) of arbitrary length, create a dialog box for an input for each, and return the values in a list.

Graphic Parameters (symbols, line types, and colors) for ggplot2

Following up on John Mount’s post on remembering symbol parameters in ggplot2, I decided to give it a try and included symbols, line types, and colors (based upon Earl Glynn’s wonderful color chart). Code follows below. require(ggplot2) require(grid) theme_update(panel.background=theme_blank(), panel.grid.major=theme_blank(), panel.border=theme_blank()) #Borrowed (i.e. stollen) from http://research.stowers-institute.org/efg/R/Color/Chart/ColorChart.R getColorHexAndDecimal <- function(color) { if(is.na(color)) { return(NA) } else { c <- col2rgb(color) return(sprintf("#%02X%02X%02X %3d %3d %3d", c[1],c[2],c[3], c[1], c[2], c[3])) } } Symbols ggplot(data=data.

Given a room with n people in it, what is the probability any two will have the same birthday?

Revisiting a fun puzzle I remember first encountering as an undergraduate. Nice example of creating a plot in R using ggplot2. I also plot the probability of someone in the room having the same birthday as you.

See http://en.wikipedia.org/wiki/Birthday_problem for an explanation of the problem require(ggplot2) require(reshape) theme_update(panel.background=theme_blank(), panel.grid.major=theme_blank(), panel.border=theme_blank()) birthday <- function(n) { 1 - exp( - n^2 / (2 * 365) ) } myBirthday <- function(n) { 1 - ( (365 - 1) / 365 ) ^ n } d = 200 df = data.

Object Oriented Programming in R

Constructor Define S3 generic method for the print function. Test code As someone who was a Java programmer for many years learning R’s object oriented programming framework has been frustrating to say the least. I like the simplicity of S3 but find it limiting when you wish to write methods that change the underlying data elements.

Retrieving RSS Feeds Using Google Reader

I have been working on a new package makeR to help manage Sweave projects where you wish to create multiple versions of documents that are based on a single source. For example, I create lots of monthly and quarterly reports using Sweave and the only differences between versions are a few variables. I have used GNU make and Apache ANT but wanted a 100% R solution. I will have more to write about that project in a few weeks.

Visualizing Likert Items

I have become quite a big fan of graphics that combine the features of traditional figures (e.g. bar charts, histograms, etc.) with tables. That is, the combination of numerical results with a visual representation has been quite useful for exploring descriptive statistics. I have wrapped two of my favorites (build around ggplot2) and included them as part of my irutils R package (currently under development). Here is the code and results utilizing two item from the 2009 Programme of International Student Assessment (PISA).

Comparing Public and Private Schools

Relationship Between SAT & College Retention

Here is a quick analysis of the relationship between SAT score and student retention. The data is from the Integrated Postsecondary Education Data System (IPEDS) and analyzed using R. This was a quick analysis and would be careful about making any strong conclusions. The source for running this analysis along with some additional graphics that are not included in this post. Here are the results of the regression analysis: Estimate Std.

Recreating Gapminder World Map with R & ggplot2

Gapminder has posted an interesting chart using world development indicators from the World Bank. I thought it would be a good exercise to recreate this chart using R and ggplot2. While playing with the data, not log transforming GDP provides some interesting, and perhaps different, interpretation. The R script and graphics are below. Google Gadget Version library(ggplot2) library(reshape) countries = read.csv(‘Data/WDI_GDF_Country.csv’, strip.white=TRUE) worldData = read.csv(‘Data/WDI_GDF_Data.csv’, strip.white=TRUE) worldData2 = worldData[which(worldData$Series.