Reproduce frequency matrix plot

帅比萌擦擦* 提交于 2019-12-11 02:06:19

问题


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

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...


回答1:


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.




回答2:


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))
}



来源:https://stackoverflow.com/questions/5913006/reproduce-frequency-matrix-plot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!