options(scipen=999)
options(digits=9)
cat("\014") # clear screen
rm(list=ls(all=TRUE))

n=10
p=0.2
x=seq(from=0,to=n,by=1)
plot(x,dbinom(x,n,p),
          xlim=c(0,10),
          ylim=c(0,0.4),
          lwd=1,
          type="p",axes=TRUE,
          col="blue",
          tck=0.01,
          xaxs="r",yaxs="r",
          col.sub="Black",
          col.main="Green",
          xlab="x",
          ylab="P(X = x) = b(x, n, p)",
          main="Binomial Distribution",
          sub="X = Number of Success")
lines(x,dbinom(x,n,p),type="h")


dbinom(0,3,1/6)
dbinom(1,3,1/6)
dbinom(2,3,1/6)
dbinom(3,3,1/6)

n=3
p=1/6
pbinom(0,n,p)
pbinom(1,n,p)
pbinom(2,n,p)
pbinom(3,1,p)

x=seq(from=0,to=n,by=1)
Px=dbinom(x,n,p)
table=data.frame(x,Px)
table

CPx=pbinom(x,n,p)
table=data.frame(x,CPx)
table

n=5
p=0.25
x=seq(from=0,to=n,by=1)
Px=dbinom(x,n,p)
CPx=pbinom(x,n,p)
table=data.frame(x,Px,CPx)
table



b=function(x,n,p) dbinom(x,n,p)
b(0,3,1/6)


n=10
p=0.2
x=seq(from=0,to=n,by=1)
plot(x,dbinom(x,n,p),type="h")
lines(x,dbinom(x,n,p),type="p")



















#lines(t,dt(t,df=2),type="l",col="red")
#lines(t,dt(t,df=5),type="l",col="green")
#lines(t,dt(t,df=100),type="l",col="black")


#lines(x,df(x,df1=6,df2=2),type="l",col="black")


#cat("\014") # clear screen

options(scipen=999)
options(digits=12)
#cat("\014") # clear screen
rm(list=ls(all=TRUE))


n=15
p=0.25
x=seq(from=0,to=n,by=1)
Px=dbinom(x,n,p)
CPx=pbinom(x,n,p)
table=data.frame(x,Px,CPx)
table

P=function(a,b,n,p) pbinom(b,n,p)-pbinom(a-1,n,p)
P(0,4,15,0.25)
P(5,5,15,0.25)

P=function(a,b,n,p) pbinom(b,n,p)-pbinom(a-1,n,p)
P(5,10,10,0.8)


P=function(a,b,n,p) pbinom(b,n,p)-pbinom(a-1,n,p)
P(1,2,10,0.25)
P(1,3,10,0.25)
P(2,5,10,0.25)
P(4,10,10,0.25)


