Skip to content

Instantly share code, notes, and snippets.

@doryokujin
Created May 21, 2012 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doryokujin/2762511 to your computer and use it in GitHub Desktop.
Save doryokujin/2762511 to your computer and use it in GitHub Desktop.
> calc.p <- function(n) { rbinom(1,n,1/2)/n } # n回試行での表の出る確率
> x <- seq(1,1000)
> y <- sapply(x, calc.p)
> x
[1] 1 2 3 4 5 6 7 8 9 10
...
[995] 995 996 997 998 999 1000
> y
[1] 1.0000000 0.5000000 1.0000000 0.7500000 0.6000000
...
[995] 0.4914573 0.4939759 0.5025075 0.4749499 0.5045045
> plot(x,y,type='l',ylim=c(0,1), xlab='n', ylab='prob')
> lines(x,rep(0.5,1000),type='l',col=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment