Guest User

Untitled

a guest
Nov 19th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. binom.prob=0.01
  2. set.seed(8)
  3. x=1:20000
  4. y=sapply(x,function(x) sum(rbinom(x,1,binom.prob)))
  5. plot(x,y,col=rgb(1,0,0,0.5),pch='.',main='binomial distribution');grid()
  6. plot(x,y/x,col=rgb(1,0,0,1),pch='.',main='binomial distribution ratio');grid()
  7.  
  8. (summary(lm(y~x)))$r.squared #obviously high r squared, returns 0.97
  9.  
  10. (summary(lm(I(y/x)~x)))$r.squared #obviously low r squared, returns 0.00001977375
  11.  
  12. d=expand.grid(num=0:50,dem=1:50)
  13. d=d[d$num<=d$dem,]
  14. plot(d$dem,d$num/d$dem,col=rgb(1-d$dem/50,d$dem/50,0,1),pch=20,main='binomial distribution flower')
Add Comment
Please, Sign In to add comment