?prop.test
## starting httpd help server ... done
x<-10
n<-50
prop.test(x,n,p=0.5)
##
## 1-sample proportions test with continuity correction
##
## data: x out of n, null probability 0.5
## X-squared = 16.82, df = 1, p-value = 4.11e-05
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
## 0.1050216 0.3414368
## sample estimates:
## p
## 0.2
qbeta(0.025,x+1/2,n-x+1/2)
## [1] 0.107734
qbeta(0.975,x+1/2,n-x+1/2)
## [1] 0.3258269
y<-1
N<-180
prop.test(y,N)
##
## 1-sample proportions test with continuity correction
##
## data: y out of N, null probability 0.5
## X-squared = 174.05, df = 1, p-value < 2.2e-16
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
## 0.000290069 0.035287041
## sample estimates:
## p
## 0.005555556
qbeta(0.025,y+1/2,N-y+1/2)
## [1] 0.0006000859
qbeta(0.975,y+1/2,N-y+1/2)
## [1] 0.02566883
# MƩtodo de montecarlo
x<-runif(10000)
y<-runif(10000)
plot(x,y)

pi/4
## [1] 0.7853982
sum((x-0.5)**2+(y-0.5)**2 <0.25)
## [1] 7892
7891/10000
## [1] 0.7891
x<-51
y<-49
n<-100
m<-100
p1<-rbeta(10000,x+0.5,n-x+1/2)
p2<-rbeta(10000,y+0.5,m-y+1/2)
quantile(p1-p2,0.025)
## 2.5%
## -0.1163147
quantile(p1-p2,0.975)
## 97.5%
## 0.1572224
p1<-0.51
p2<-0.49
p1-p2-1.96*sqrt(p1*(1-p1)/100+p2*(1-p2)/100)
## [1] -0.1185652
p1-p2+1.96*sqrt(p1*(1-p1)/100+p2*(1-p2)/100)
## [1] 0.1585652
#Ejercicio
#1. 0.2,n=2000, 0.6, n=100