July 2012

Optical Art with R

July 16, 2012 | flodel

Last week, in a post entitled Bridget Riley exhibition in London, the author Markus Gesmann wrote an R script reproducing one of Riley's famous art pieces: Movement in Squares.This reminded me of my own first "brush" with Op art. It was in art class ye...
[Read more...]

Convenient access to Gapminder’s datasets from R

July 16, 2012 | Karsten W.

In April, Hans Rosling examined the influence of religion on fertility. I used R to replicate a graphic of his talk:
> <span>library</span>(datamart)
> gm <- <span>gapminder</span>()
> <span>#queries(gm)</span>
> <span>#</span>
> <span># babies per woman</span>
> tmp <- <span>query</span>(gm, <span>"TotalFertilityRate"</span>)
> babies <- <span>as.vector</span>(tmp[<span>"2008"</span>])
> <span>names</span>(babies) <- <span>names</span>(tmp)
> babies <- babies[!<span>is.na</span>(babies)]
> countries <- <span>names</span>(babies)
> <span>#</span>
> <span># income per capita, PPP adjusted</span>
> tmp <- <span>query</span>(gm, <span>"IncomePerCapita"</span>)
> income <- <span>as.vector</span>(tmp[<span>"2008"</span>])
> <span>names</span>(income) <- <span>names</span>(tmp)
> income <- income[!<span>is.na</span>(income)]
> countries <- <span>intersect</span>(countries, <span>names</span>(income))
> <span>#</span>
> <span># religion</span>
> tmp <- <span>query</span>(gm, <span>"MainReligion"</span>)
> religion <- tmp[,<span>"Group"</span>]
> <span>names</span>(religion) <- tmp[,<span>"Entity"</span>]
> religion[religion==<span>""</span>] <- <span>"unknown"</span>
> colcodes <- <span>c</span>(
+   <span>Christian=</span><span>"blue"</span>, 
+   <span>"Eastern religions"</span>=<span>"red"</span>, 
+   <span>Muslim=</span><span>"green"</span>, <span>"unknown"</span>=<span>"grey"</span>
+ )
> countries <- <span>intersect</span>(countries, <span>names</span>(religion))
> <span>#</span>
> <span># plot</span>
> <span>par</span>(<span>mar=</span><span>c</span>(<span>4</span>,<span>4</span>,<span>0</span>,<span>0</span>)+<span>0.1</span>)
> <span>plot</span>(
+   <span>x=</span>income[countries], 
+   <span>y=</span>babies[countries], 
+   <span>col=</span>colcodes[religion[countries]], 
+   <span>log=</span><span>"x"</span>,
+   <span>xlab=</span><span>"Income per Person, PPP-adjusted"</span>, 
+   <span>ylab=</span><span>"Babies per Woman"</span>
+ )
> <span>legend</span>(
+   <span>"topright"</span>, 
+   <span>legend=</span><span>names</span>(colcodes), 
+   <span>fill=</span>colcodes, 
+   <span>border=</span>colcodes
+ )
One of the points Rosling wanted to make is: Religion has no or very little influence on fertility, but economic welfare has. I wonder if demographs agree and ...
[Read more...]

Holt-Winters forecast using ggplot2

July 16, 2012 | Bart

R has great support for Holt-Winter filtering and forecasting. I sometimes use this functionality, HoltWinter & predict.HoltWinter, to forecast demand figures based on historical data. Using the HoltWinter functions in R is pretty straightforward. Let's say our dataset looks as follows; demand [Read more...]

Using integer programming in R to optimize cargo loads

July 16, 2012 | David Smith

Linear Programming is a mathematical technique used to find the values of some variables (within the bounds of some defined constraints) to find the maximum value of a quantity. For example, consider this problem from the FishyOperations blog: A trading company is looking for a way to maximize profit per ... [Read more...]

Example 9.38: dynamite plots, revisited

July 16, 2012 | Nick Horton

Dynamite plots are a somewhat pejorative term for a graphical display where the height of a bar indicates the mean, and the vertical line on top of it represents the standard deviation (or standard error). These displays are commonly found in many scientific disciplines, as a way of communicating group ... [Read more...]

2 dimensions of portfolio diversity

July 16, 2012 | Pat

Portfolio diversity is a balancing act. Previously The post “Portfolio diversity” talked about the role of the correlation between assets and the portfolio.  The current post fills a hole in that post. The 2 dimensions asset-portfolio correlation Each asset in the universe has a correlation with the portfolio.  If there are ... [Read more...]

Project Euler — problem 14

July 16, 2012 | Tony

It’s Monday today! It’s work day! And I’ve already worked on computer for two hours. Time for a break, which is the 14th problem of Project Euler. The following iterative sequence is defined for the set of positive integers: n n/2 (n … Continue reading → [Read more...]

A simple Approximate Bayesian Computation MCMC (ABC-MCMC) in R

July 15, 2012 | Florian Hartig

Approximate Bayesian Computing and similar techniques, which are based on calculating approximate likelihood values based on samples from a stochastic simulation model, have attracted a lot of attention in the last years, owing to their promise to provide a general statistical technique for stochastic processes of any complexity, without the ... [Read more...]

Sourcing an R Script from Dropbox

July 14, 2012 | Jared Knowles

Working on my R bootcamp materials and I thought it would be handy to get the bootcamp computers setup by sourcing an R script that will install all necessary non-core packages in it. The problem? How to deploy this script efficiently. A quick method w... [Read more...]

Trends in AL run scoring (using R)

July 14, 2012 | Martin Monkman

I have started to explore the functionality of R, the statistical and graphics programming language. And with what better data to play than that of Major League Baseball?There have already been some good examples of using R to analyze baseball data. The most comprehensive is the on-going series at ... [Read more...]
1 5 6 7 8 9 13

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)