Documentos de Académico
Documentos de Profesional
Documentos de Cultura
N /2
1
( )
σ2
exp ¿
σ −2 G ¿(15.17¿2),
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-29.069 -9.525 -2.272 9.215 43.201
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -17.5791 6.7584 -2.601 0.0123 *
x 3.9324 0.4155 9.464 1.49e-12 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Call:
lm(formula = y ~ x + x2)
Residuals:
Min 1Q Median 3Q Max
-28.720 -9.184 -3.188 4.628 45.152
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.47014 14.81716 0.167 0.868
x 0.91329 2.03422 0.449 0.656
x2 0.09996 0.06597 1.515 0.136
> MSR <- 15.18^2 ##Tomamos el error estándar de los residuales, que es
> SSR <- MSR*47 ##la raíz cuadrada de los errores medios.
> plot(MH1(10^5)$a[90000:10^5],type="l",xlab="",ylab="a");acf(MH1(10^5)$a)
> plot(MH1(10^5)$b[90000:10^5],type="l",xlab="",ylab="b");acf(MH1(10^5)$b)
> plot(MH1(10^5)$c[90000:10^5],type="l",xlab="",ylab="c");acf(MH1(10^5)$c)
> hist(MH1$a,prob=T,main="",ylab="",xlab="a",col="wheat2",nclass=100)
> curve(dnorm(x,2.47014,sd=14.81716),add=T,col="cyan")
> hist(MH1$b,prob=T,main="",yla="",xla="b",col="wheat2",nclass=100)
> curve(dnorm(x,0.91329,sd=2.03422),add=T,col="cyan")
> hist(MH1$c,prob=T,main="",yla="",xla="c",col="wheat2",nclass=100)
> curve(dnorm(x,0.09996,sd=0.06597),add=T,col="cyan")
EJERCICIO 7.20
Desde la jerarquía (7.6), muestre que la distribución conjunta puede obtenerse
multiplicando las densidades. Luego, utilizando la estrategia del Ejercicio 7.4, verifique que
los condicionales completos estén dados por (7.7).
Sol. (7.6)
X ij N ( θi ,σ 2 ) ,i=1 , … , k , j=1 , … , ni ,
θi N ( μ , τ 2 ) , i=1 , … , k ,
μ N ( μ0 , σ 2μ ) ,
σ 2 IG ( a1 , b1 ) , τ 2 IG ( a2 , b 2) , σ 2μ IG (a3 , b3 )
(7.7)
σ2 ni τ 2 σ 2τ2
θi N 2
(
σ +ni τ 2
μ+ 2
σ +n i τ 2
X́ i , 2
σ +n i τ 2
, i=1 , … , k ,
)
τ2 k σ 2μ σ 2μ τ 2
μ N 2
(
τ +k σ 2μ
μ0 + 2 θ́ ,
τ +k σ 2μ τ 2 +k σ 2μ )
n 1
σ 2 IG
( 2 )
+a1 ,( ) ∑ (X ij −θ i)2 +b1 ,
2 i j
k 1
τ2
(2 2
IG +a ,( ) ∑ (θ −μ) +b ,
2
ij
)
i
2
2
σ 2μ
( 12 12 3 )
IG +a , ( ) ( μ−μ ) +b , 0
2
3
Donde n=∑
i
ni y θ́=∑ ni θi /n .
i
Comando en R:
> library(mcsm)
> data(Energy)
> X <- Energy
> a1 <- a2 <- a3 <- 7
> b1 <- b2 <- b3 <- 5
> mu0 <- 7
> X1 <- X$Girls
> X2 <- X$Boys
> x <- rbind(X1,X2)
> x1bar <- mean(X1)
> x2bar <- mean(X2)
> k <- 2
> n1 <- length(X1)
> n2 <- length(X2)
> Nsim <- 1e4
> sig2 <- tau2 <- sigmu2 <- rep(0,Nsim)
> theta1 <- theta2 <- mu <- rep(0,Nsim)
> n <- n1+n2
> sh1 <- (n/2)+a1
> sh2 <- (k/2)+a2
> sh3 <- (1/2)+a3
> sig2[1] <- 1/rgamma(1,a1,b1)
> tau2[1] <- 1/rgamma(1,a2,b2)
> sigmu2[1] <- 1/rgamma(1,a3,b3)
> mu[1] <- rnorm(1,mu0,sqrt(sigmu2[1]))
> B1 <- sig2[1]/(sig2[1]+n1*tau2[1])
> B2 <- sig2[1]/(sig2[1]+n2*tau2[1])
> D <- tau2[1]/(tau2[1]+k*sigmu2[1])
> theta1[1] <- rnorm(1,mean=B1*mu[1]+(1-B1)*x1bar,sd=sqrt(B1*tau2[1]))
> theta2[1] <- rnorm(1,mean=B2*mu[1]+(1-B2)*x2bar,sd=sqrt(B2*tau2[1]))
> for (i in 2:Nsim){
+ B1 <- sig2[i-1]/(sig2[i-1]+n1*tau2[i-1])
+ B2 <- sig2[i-1]/(sig2[i-1]+n2*tau2[i-1])
+ theta1[i] <- rnorm(1,mean=B1*mu[i-1]+(1-B1)*x1bar,sd=sqrt(B1*tau2[i-1]))
+ theta2[i] <- rnorm(1,mean=B2*mu[i-1]+(1-B2)*x2bar,sd=sqrt(B2*tau2[i-1]))
+ thetabar <- (n1*theta1[i]+n2*theta2[i])/n
+ D <- tau2[i-1]/(tau2[i-1]+k*sigmu2[i-1])
+ mu[i] <- rnorm(1,mean=D*mu0+(1-D)*thetabar,sd=sqrt(D*sigmu2[i-1]))
+ sum1 <- sum2 <- 0
+ for (j in 1:n1){
+ sum1 <- sum1+(x[1,j]-theta1[i])^2
+ }
+ for (j in 1:n2){
+ sum2 <- sum2+(x[2,j]-theta2[i])^2
+ }
+ rate1 <- (1/2)*(sum1+sum2)+b1
+ rate2 <- (1/2)*((theta1[i]-mu[i])^2+(theta2[i]-mu[i])^2)+b2
+ rate3 <- (1/2)*(mu[i]-mu0)^2+b3
+ sig2[i] <- 1/rgamma(1,sh1,rate1)
+ tau2[i] <- 1/rgamma(1,sh2,rate2)
+ sigmu2[i] <- 1/rgamma(1,sh3,rate3)
+}
> par(mfrow=c(2,3))
> hist(mu[5001:1e4],main="mu",col=8,nclass=100,xlab="")
> hist(theta1[5001:1e4],main="theta1",col=8,nclass=100,xlab="")
> hist(theta2[5001:1e4],main="theta2",col=8,nclass=100,xlab="")
> hist(sqrt(sigmu2)[5001:1e4],main="sigmu",col=10,nclass=100,xlab="")
> hist(sqrt(tau2)[5001:1e4],main="tau",col=10,nclass=100,xlab="")
l
> hist(sqrt(sig2)[5001:1e4],main="sig",col=10,nclass=100,xlab="")
EJEMPLO 6.4
Sea el vector aleatorio X =( X 1 , X 2 ) que tiene la siguiente pdf (función de densidad de
probabilidad) bidimensional:
−x 21 x22 + x 21 + x 22−8 x1 −8 x2
f ( x )=c exp ( 2 ) ,
> hist(X1,nclass=100,freq=F,col="green")
## Hacemos el histograma de la marginal X1
S^
( l^ ± z 1−α / 2
√T )
k
2
Con ^S = R
^ ( 0 )+ 2 ∑ R(
^ t) (varianza asintótica)
t =1
Con ^
R(t ) función de autocovarianza.
EJERCICIO 6.5
1 −¿x− μ∨¿
f ( x|μ , σ )= e σ
2σ
1 −(x− μ)/σ
¿ 2σ
{ e
1 (x−μ)/ σ
2
e
x−μ ≥ 0
x−μ<0
Si x ≥ μ:
x −|t− μ|
1 σ
F ( x|μ , σ )= ∫e dt
2 σ −∞
μ x
¿
1
2σ [ ∫e
−∞
(t− μ)/σ
dt+∫ e
μ
−(t−μ )/ σ
dt
]
Integral uno: t <μ
Integral dos:t ≥ μ
t−μ −(t−μ)
v= w=
σ σ
1 −1
dv = dt dw= dt
σ σ
μ x
F ( x|μ , σ )=
1
2 [ ∫e
−∞
v σdt
σ μ
+∫ e
w (−σ ) dt
σ ]
x
t−μ μ
1
¿ e
2
[ σ |
−∞ −e σ |]
−(t−μ )
μ
− ( x−μ)
1
¿ 1−0−e
2
[ σ
+1 ]
−(x−μ )
1 σ
¿ 1− e
2
Si x < μ:
x
1 |t−μ|/ σ
F ( x|μ , σ )= ∫ e dt
−∞ 2σ
x
1 (t−μ )/ σ
¿∫ e dt
−∞ 2σ
x−μ x
1
¿ e
2
σ
|
−∞
(x− μ)
1 σ
¿ e −0
2
(x− μ)
1 σ
¿ e
2
Así, si x−μ ≥ 0:
−(x− μ)
1 σ
F ( x|μ , σ )=1− e
2
Si x−μ<0 :
(x−μ)
1 σ
F ( x|μ , σ )= e
2
Así,
1
F ( x|μ , σ )= [ 1+ sgn ( x−μ ) [1−e−¿ x−μ∨¿ σ ] ]
2
Si x ≥ μ :
1
y=1− e−( x− μ)
2
e−(x−μ)/ σ =2(1− y )
(x−μ)
=−ln(2(1− y ))
σ
x=μ−σ ln(2(1− y ))
Si x−μ ≥ 0:
−σ ln ( 2 ( 1− y ) ) ≥ 0
ln (2(1− y )) ≥ 0
0 ≤ 2(1− y )≤ 1
1
0 ≤(1− y)≤
2
1 1
y ≥1− =
2 2
Si x−μ<0 :
σ ln2 y <0
ln 2 y <0
0 ≤ 2 y <1
1
0 ≤ y<
2
Así,
1 1 1 1
x=μ−sgn U− ( 2 )
σ ln 2( + sgn(U − )( −U ))
2 2 2
Objetivo
f (y)
∝ ( x , y )=mín { f ( x)
,1 } caminata aleatoria
e− y I
¿ mín { e− x
{ y >0 },1 }
¿ mín {e (x− y) I { y> 0 } ,1 }
Muestrador de independencia
exp( 1) objetivo
exp( λ) instrumental
f ( y ) g( x)
∝ ( x , y )=mín { f ( x) g ( y )
,1 }
λ e−λx
¿ mín e { (x− y)
λ e−xy
,1 }
¿ mín { e (x− y) e−λ(x− y) , 1 }
Sol.
Programa