Академический Документы
Профессиональный Документы
Культура Документы
26 de abril de 2008
I. Capítulo 2
Una v.a. en toda la recta, se distribuyen en forma logística con parámetro de localización µ y
escala si:
(𝑥 −𝜇 )
𝑒 𝜎
𝑓(𝑥) = 2
𝑥 −𝜇
𝜎 1+𝑒 𝜎
Solución:
La función de distribución acumulada para la distribución Logística es la siguiente:
1
𝐹 𝑥 = 𝑥−𝜇
1 + 𝑒− 𝜎
#1,2,3
x=seq(-10,10,0.01)
u=0
s=1
z=(x-u)/s
pdfx=exp(z)/(s*(1+exp(z))^2)
cdfx=1/(1+exp(-z))
par(mfrow=c(1,2))
plot(x,pdfx,type="l",xlab="X",ylab="f(x)",col="blue")
title('Probability Density Function u=0,s=1')
plot(x,cdfx,type="l",xlab="X",ylab="F(x)",col="red")
title('Cumulative Distribution Function u=0,s=1')
#(1.4)
x=seq(-10,10,0.01)
u=-1;s1=1;s2=2
z1=(x-u)/s1;z2=(x-u)/s2
pdfx1=exp(z1)/(s1*(1+exp(z1))^2)
cdfx1=1/(1+exp(-z1))
pdfx2=exp(z2)/(s2*(1+exp(z2))^2)
cdfx2=1/(1+exp(-z2))
par(mfrow=c(3,2))
plot(x,pdfx1,type="l",xlab="X",ylab="f(x)",col="blue",lwd=2)
lines(x,pdfx2,type="l",xlab="X",ylab="f(x)",col="cyan",lwd=2)
title('Probability Density Function u=-1,s=1,2')
plot(x,cdfx1,type="l",xlab="X",ylab="F(x)",col="red",lwd=2)
lines(x,cdfx2,type="l",xlab="X",ylab="F(x)",col="orange",lwd=2)
title('Cumulative Distribution Function u=-1,s=1,2')
u=0;s1=1;s2=2
z1=(x-u)/s1;z2=(x-u)/s2
pdfx1=exp(z1)/(s1*(1+exp(z1))^2)
cdfx1=1/(1+exp(-z1))
pdfx2=exp(z2)/(s2*(1+exp(z2))^2)
cdfx2=1/(1+exp(-z2))
#par(mfrow=c(1,2))
plot(x,pdfx1,type="l",xlab="X",ylab="f(x)",col="blue",lwd=2)
lines(x,pdfx2,type="l",xlab="X",ylab="f(x)",col="cyan",lwd=2)
title('Probability Density Function u=0,s=1,2')
plot(x,cdfx1,type="l",xlab="X",ylab="F(x)",col="red",lwd=2)
lines(x,cdfx2,type="l",xlab="X",ylab="F(x)",col="orange",lwd=2)
title('Cumulative Distribution Function u=0,s=1,2')
u=1;s1=1;s2=2
z1=(x-u)/s1;z2=(x-u)/s2
pdfx1=exp(z1)/(s1*(1+exp(z1))^2)
cdfx1=1/(1+exp(-z1))
pdfx2=exp(z2)/(s2*(1+exp(z2))^2)
cdfx2=1/(1+exp(-z2))
#par(mfrow=c(1,2))
plot(x,pdfx1,type="l",xlab="X",ylab="f(x)",col="blue",lwd=2)
lines(x,pdfx2,type="l",xlab="X",ylab="f(x)",col="cyan",lwd=2)
title('Probability Density Function u=1,s=1,2')
plot(x,cdfx1,type="l",xlab="X",ylab="F(x)",col="red",lwd=2)
lines(x,cdfx2,type="l",xlab="X",ylab="F(x)",col="orange",lwd=2)
title('Cumulative Distribution Function u=1,s=1,2')
Observamos que se trata de una distribución simétrica. Asimismo, notamos que el parámetro µ
nos indica la posición de la función Logística; y el parámetro determina la forma de la curva, a
medida que aumenta la función se ensancha para los costados y se achata en el centro.
prob = pbinom(3,6,0.5)
> prob
[1] 0.65625
Por lo tanto la probabilidad de que a lo más 3 de las personas seleccionadas tengan algún
desorden es del 65.6%.
Observamos que la distribución binomial con parámetros n=6 y p=0.5 se distribuye de forma
simétrica con respecto a la media. Y el valor esperado de personas con algún desorden
psiquiátrico es 3.
Solución:
Graficamos la función de densidad normal en R mediante la ejecución de los comandos
siguientes:
x=seq(-5,5,0.1)
u=-1
s1=0.5;s2=1;s3=2
pdfx1=dnorm(x,u,s1);pdfx2=dnorm(x,u,s2);pdfx3=dnorm(x,u,s3)
h1=dnorm(u,u,s1);h1
h2=dnorm(u,u,s2);h2
h3=dnorm(u,u,s3);h3
par(mfrow=c(1,3))
plot(x,pdfx1,type="l",xlab="X",ylab="f(x)",col="blue",lwd=2)
lines(x,pdfx2,type="l",xlab="X",ylab="f(x)",col="red",lwd=2)
lines(x,pdfx3,type="l",xlab="X",ylab="f(x)",col="orange",lwd=2)
title('Probability Density Function u=-1,s=0.5,1,2')
u=0
pdfx1=dnorm(x,u,s1);pdfx2=dnorm(x,u,s2);pdfx3=dnorm(x,u,s3)
h1=dnorm(u,u,s1);h1
h2=dnorm(u,u,s2);h2
h3=dnorm(u,u,s3);h3
plot(x,pdfx1,type="l",xlab="X",ylab="f(x)",col="blue",lwd=2)
lines(x,pdfx2,type="l",xlab="X",ylab="f(x)",col="red",lwd=2)
lines(x,pdfx3,type="l",xlab="X",ylab="f(x)",col="orange",lwd=2)
title('Probability Density Function u=0,s=0.5,1,2')
u=1
pdfx1=dnorm(x,u,s1);pdfx2=dnorm(x,u,s2);pdfx3=dnorm(x,u,s3)
h1=dnorm(u,u,s1);h1
h2=dnorm(u,u,s2);h2
h3=dnorm(u,u,s3);h3
plot(x,pdfx1,type="l",xlab="X",ylab="f(x)",col="blue",lwd=2)
lines(x,pdfx2,type="l",xlab="X",ylab="f(x)",col="red",lwd=2)
lines(x,pdfx3,type="l",xlab="X",ylab="f(x)",col="orange",lwd=2)
title('Probability Density Function u=1,s=0.5,1,2')
Cree una secuencia de función de densidad de la t de student para diferentes grados de libertad
gl = 5; 15; 25; 35 usando las funciones correspondientes del programa que use. Compare
entonces con la distribución normal estándar. Use gráficos y medidas estadísticas.
Solución:
x=seq(-5,5,0.1)
gl1=5;gl2=15;gl3=25;gl4=35
pdftx1=dt(x,gl1);pdftx2=dt(x,gl2);pdftx3=dt(x,gl3);pdftx4=dt(x,gl4)
pdfzx=dnorm(x,0,1)
par(mfrow=c(2,2))
plot(x,pdftx1,type="l",xlab="X",ylab="f(x)",col="blue",lwd=2)
lines(x,pdfzx ,type="l",col="red",lwd=2)
title('Probability Density Function t(5),z(0,1)')
plot(x,pdftx2,type="l",xlab="X",ylab="f(x)",col="blue",lwd=2)
lines(x,pdfzx ,type="l",col="red",lwd=2)
title('Probability Density Function t(15),z(0,1)')
plot(x,pdftx3,type="l",xlab="X",ylab="f(x)",col="blue",lwd=2)
lines(x,pdfzx ,type="l",col="red",lwd=2)
title('Probability Density Function t(25),z(0,1)')
plot(x,pdftx4,type="l",xlab="X",ylab="f(x)",col="blue",lwd=2)
lines(x,pdfzx ,type="l",col="red",lwd=2)
title('Probability Density Function t(35),z(0,1)')
Observamos que a medida que aumentan los grados de libertad de la función de densidad de
probabilidades de la T de Student se asemeja más a la distribución normal estándar.
II. Capítulo 3
Generate 500 random samples from the standard normal distribution for sample sizes of n = 2,
15, and 45. At each sample size, calculate the sample mean for all 500 samples. How are the
means distributed as n gets large? Look at a histogram of the sample means to help answer this
question. What is the mean and variance of the sample means for each n? Is this what you would
expect from the Central Limit Theorem?
Solución:
Construimos una función en R para tomar gran cantidad de muestras y almacenar sus resultados.
zsamples=function(n) {
i=1
xhats=seq(1:500)
for (i in 1:500) {
x=rnorm(n,0,1)
xhats[i]=mean(x)
i=i+1}
return(xhats)
}
n1=2;n2=15;n3=45
xhat1=mean(zsamples(n1));xhat1
xhat2=mean(zsamples(n2));xhat2
xhat3=mean(zsamples(n3));xhat3
par(mfrow=c(1,3))
hist(zsamples(n1),xlab="Xbar (n=2)",col="red",
main="Histograma de medias, 500 muestras")
hist(zsamples(n2),xlab="Xbar (n=15)",col="orange",
main="Histograma de medias, 500 muestras")
hist(zsamples(n3),xlab="Xbar (n=45)",col="skyblue",
main="Histograma de medias, 500 muestras")
En este ejemplo, generamos una muestra aleatoria de una distribución normal estándar. Use la
función correspondiente para generar sus muestras. Que sucede con el coeficiente de asimetría y
curtosis cuando el tamaño de muestra crece?.
Solución:
Según la teoría de la distribución normal estándar, la simetría debe ser cero y la curtosis igual a 3.
En este ejercicio se puede notar que a medida que aumenta el tamaño de muestra, los valores de
la asimetría y la curtosis se aproximan mejor a los valores teóricos.
Compare los valores obtenidos para los cuartiles estimados en el ejemplo 3.6 con las cantidades
teóricas. Incremente el tamaño de muestra a n = 1000. Los estimados mejoran?.
Solución:
require(signal)
x=rnorm(500)
xs=sort(x)
# Now get the observed values for the abscissa (X_obs).
n=length(x)
phat=((1:n)-0.5)/n
# We want to get the quartiles.
p=c(0.25, 0.5, 0.75)
# The following provides the estimates of the quartiles
# using linear interpolation.
qhat1=interp1(phat,xs,p,method = "linear");qhat1
qhat2=interp1(phat,xs,p,method = "nearest");qhat2
qhat3=interp1(phat,xs,p,method = "pchip");qhat3
qhat4=interp1(phat,xs,p,method = "pchip");qhat4
qhat5=interp1(phat,xs,p,method = "cubic");qhat5
qhat6=interp1(phat,xs,p,method = "spline");qhat6
#Cuartiles Teóricos
qhat=qnorm(p,0,1);qhat
Podemos apreciar que la estimación de los cuartiles cuando n=1000 es la que más se aproxima a
los valores teóricos, por lo tanto se vuelven más precisos a medida que aumenta el tamaño de
muestra.
Investigate the bias in the maximum likelihood estimate of the variance that is given in Equation
3.28. Generate a random sample from the standard normal distribution. Calculate 2 using
Equation 3.28 and record the value in a vector. Repeat this process (generate a random sample
from the standard normal distribution, estimate the variance, save the value) many times. Once
you are done with this procedure, you should have many estimates for the variance.
Take the mean of these estimates to get an estimate of the expected value of 2 . How does this
compare with the known value of 2=1? Does this indicate that the maximum likelihood estimate
for the variance is biased? What is the estimated bias from this procedure?
Solución:
Salida del R:
> shat=mean(zsamples(n))
> shat
[1] 0.9880203
> bias=1-shat
> bias
[1] 0.01197965
Lo que nos indica que existe un sesgo de 0.01198 para dicho estimador de la variancia, obtenido
por el método de máxima verosimilitud.