2

I have a plot that I would like to recreate within R. Here is the plot:

Frquency Matrix

From: Boring, E. G. (1941). Statistical frequencies as dynamic equilibria. Psychological Review, 48(4), 279.

This is a little above my paygrade (abilities) hence asking here. Boring states:

On the first occasion A can occur only 'never' (0) or 'always' (1). On the second occasion the frequencies are 0,1/2, or 1; on the third 0, 1/3, 2/3, or 1 etc, etc.

Obviously, you don't have to worry about labels etc. Just a hint to generate the data and how to plot would be great. ;) I have no clue how to even start...

Bobby
  • 11,419
  • 5
  • 44
  • 69
Frank Zafka
  • 829
  • 9
  • 30

2 Answers2

8

here is an example:

library(plyr)
ps <- ldply(1:36, function(i)data.frame(s=0:i, n=i))
plot.new()
plot.window(c(1,36), c(0,1))
apply(ps, 1, function(x){
  s<-x[1]; n<-x[2];
  lines(c(n, n+1, n, n+1), c(s/n, s/(n+1), s/n, (s+1)/(n+1)), type="o")})
axis(1)
axis(2)

ps represents all points. Each point has two children. So draw lines from each point to the children.

enter image description here

kohske
  • 65,572
  • 8
  • 165
  • 155
  • Niiiice. That gives me something to play with. Many, many thanks. – Frank Zafka May 06 '11 at 16:32
  • Kohshke, would you mind adding some explanatory comments to your code to explain what you're doing here? – Brandon Bertelsen Sep 03 '11 at 10:53
  • @koshke: I used your code as a starting point for this questioner's follow-on question http://stackoverflow.com/questions/7280421/plot-weighted-frequency-matrix/7300824#7300824 – IRTFM Sep 04 '11 at 19:43
5

A solution using base graphics:

x <- 1:36
boring <- function(x, n=1)n/(x+n-1)

plot(x, boring(x), type="l", usr=c(0, 36, 0, 1))
for(i in 1:36){
  lines(tail(x, 36-i+1), head(boring(x, i), 36-i+1), type="o", cex=0.5)
  lines(tail(x, 36-i+1), 1-head(boring(x, i), 36-i+1, type="o", cex=0.5))
}

enter image description here

Andrie
  • 176,377
  • 47
  • 447
  • 496