\[ p(\theta) \propto \theta^{\alpha-1}(1-\theta)^{\beta-1} I_{(0,1)}(\theta) \]
es un modelo conjugado para la distribución bernoulli.
\[ p(\theta | \bf{x}) \propto \theta^{\alpha+t-1}(1-\theta)^{\beta+n-t-1} I_{(0,1)}(\theta) \] Los parámetros posteriores \[ \alpha_n = \alpha+t \]
\[ \beta_n = \beta+n-t \]
\[ E(\theta | \bf{x}) = \frac{\alpha_n}{\alpha_n+\beta_n} \]
\[ E(\theta | \bf{x}) = \frac{\alpha_n}{\alpha_n+\beta_n} = \frac{\alpha + t}{\alpha+\beta+n} \]
\[ E(\theta | \bf{x}) = \frac{\alpha_n}{\alpha_n+\beta_n} = \frac{\alpha + t}{\alpha+\beta+n}= \frac{\alpha}{\alpha+\beta+n}+\frac{ t}{\alpha+\beta+n} \] \[ E(\theta | \bf{x}) = \frac{\alpha_n}{\alpha_n+\beta_n} = \frac{\alpha + t}{\alpha+\beta+n}= \frac{\alpha}{\alpha+\beta+n}+\frac{ t}{\alpha+\beta+n}= \frac{\alpha}{\alpha+\beta+n}\frac{\alpha+\beta}{\alpha+\beta}+\frac{ t}{\alpha+\beta+n}\frac{n}{n} \]
\[ E(\theta | \bf{x}) = \frac{\alpha}{\alpha+\beta+n}\frac{\alpha+\beta}{\alpha+\beta}+\frac{ t}{\alpha+\beta+n}\frac{n}{n} =\frac{\alpha+\beta}{\alpha+\beta+n}\frac{\alpha}{\alpha+\beta}+\frac{ n}{\alpha+\beta+n}\frac{t}{n} \]
\[ E(\theta | \bf{x}) = \frac{\alpha}{\alpha+\beta+n}\frac{\alpha+\beta}{\alpha+\beta}+\frac{ t}{\alpha+\beta+n}\frac{n}{n} =\frac{\alpha+\beta}{\alpha+\beta+n}E(\theta)+\frac{ n}{\alpha+\beta+n}\bar{x} \]
\[ E(\theta | \bf{x}) = \frac{\alpha}{\alpha+\beta+n}\frac{\alpha+\beta}{\alpha+\beta}+\frac{ t}{\alpha+\beta+n}\frac{n}{n} =\omega E(\theta)+(1-\omega ) \bar{x} \]
x<-rbinom(30,1,0.3)
x
## [1] 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 1 1 0 0 0 1 1 0 1 0
\[H_0: p = p_0\] \[H_a: p \neq p_0\] \[ z = \frac{\hat{p}-p_0}{\sqrt{\frac{\hat{p}(1-\hat{p})}{n}}} \] Se tiene la convergencia en distribución a \(N(0,1)\).
\[ IC(p) := (\hat{p}-z_{\alpha/2}\sqrt{\frac{\hat{p}(1-\hat{p})}{n}};\hat{p}+z_{\alpha/2}\sqrt{\frac{\hat{p}(1-\hat{p})}{n}}) \]
x<-rbinom(30,1,0.3)
x
## [1] 1 0 0 1 1 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1
t<-sum(x)
n<-length(x)
prop.test(t,n)
##
## 1-sample proportions test with continuity correction
##
## data: t out of n, null probability 0.5
## X-squared = 4.0333, df = 1, p-value = 0.04461
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
## 0.1541280 0.4955791
## sample estimates:
## p
## 0.3
a<-1
b<-1
t<-sum(x)
n<-length(x)
ap <-a+t
bp <-b+n-t
B<-10000
theta_p<-rbeta(B,ap,bp)
plot(density(theta_p))
ic<-c(quantile(theta_p,0.025),quantile(theta_p,0.975))
ic
## 2.5% 97.5%
## 0.1657047 0.4788451
x<-rbinom(1000,1,0.3)
x
## [1] 1 0 0 0 0 0 0 1 1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0
## [38] 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 1
## [75] 1 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0
## [112] 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 1 1 1 1 1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0 0 0 0 1 0 0
## [630] 0 1 0 0 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0 0 0 1 1 0 0 0 0
## [667] 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 1 1 0 0 1 1 0 0 1 0 0 0 0 0 0 1 0 1 0
## [704] 0 0 0 0 0 0 1 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0
## [741] 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 1 0 1 0 0 0 0 1 0 0 1 0 0
## [778] 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 1 1 0 0 0 1
## [815] 1 0 1 1 0 0 0 0 0 1 1 0 0 1 0 0 1 0 0 0 0 1 0 0 1 1 1 0 0 0 0 1 0 1 0 0 0
## [852] 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 1 0 1 0 1 0 0 1 1 1 0 1 0 0 0 0 1 0 1 0 0 0
## [889] 0 0 0 0 0 1 1 1 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0
## [926] 1 0 0 0 0 0 1 1 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 1 1 0 0 0 0 0
## [963] 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0
## [1000] 0
t<-sum(x)
n<-length(x)
prop.test(t,n)
##
## 1-sample proportions test with continuity correction
##
## data: t out of n, null probability 0.5
## X-squared = 162.41, df = 1, p-value < 2.2e-16
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
## 0.2699841 0.3275891
## sample estimates:
## p
## 0.298
a<-1
b<-1
t<-sum(x)
n<-length(x)
ap <-a+t
bp <-b+n-t
B<-10000
theta_p<-rbeta(B,ap,bp)
plot(density(theta_p))
ic<-c(quantile(theta_p,0.025),quantile(theta_p,0.975))
ic
## 2.5% 97.5%
## 0.2701183 0.3271596
x<-rbinom(100,1,0.3)
x
## [1] 1 0 1 0 0 1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 1 0 0 0 1 0 1 0 0 0
## [38] 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 1
## [75] 1 1 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 1
t<-sum(x)
n<-length(x)
prop.test(t,n)
##
## 1-sample proportions test with continuity correction
##
## data: t out of n, null probability 0.5
## X-squared = 12.25, df = 1, p-value = 0.0004653
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
## 0.2322385 0.4217920
## sample estimates:
## p
## 0.32
a<-1
b<-1
t<-sum(x)
n<-length(x)
ap <-a+t
bp <-b+n-t
B<-10000
theta_p<-rbeta(B,ap,bp)
plot(density(theta_p))
ic<-c(quantile(theta_p,0.025),quantile(theta_p,0.975))
ic
## 2.5% 97.5%
## 0.2366880 0.4170067
\[ \theta | x \sim beta(a+t,b+n-t) \]
qbeta(0.025,ap,bp)
## [1] 0.2366944
qbeta(0.975,ap,bp)
## [1] 0.4169196