Sie sind auf Seite 1von 8

XS-2110 Mtodos Estadsticos

Laboratorio 3. Pruebas de hiptesis para la media de una poblacin


El objetivo del laboratorio es probar hiptesis para una poblacin utilizando las siguientes
pruebas en R:
Kolmogorov Smirnov
Shapiro Wilks
Jarque Bera
Prueba t
Prueba binomial exacta
Prueba para una proporcin
Test de Wilcoxon
Prueba de aleatoriedad
#Para correr:
#Se utilizar la base de datos antropomexicano
names(antropomexicano)
attach(antropomexicano)
mean(edad)
sd(edad)
#Prueba kolmogorov smirnov
ks.test(edad,"pnorm",mean(edad),sd(edad))
summary(edad)
sd(edad)
ks.test(edad,"pnorm",60.31,10.64586)
#Prueba Shapiro Wilks
shapiro.test(edad)
#Prueba kolmogoro smirnov distribucin exponencial
ks.test(edad,"pexp",1/mean(edad))

#Prueba Jarque Bera


hist(edad)
length(edad)
library(tseries)
jarque.bera.test(edad)
#Prueba t
t.test(edad)
t.test(edad , mu=60.5)
###Con este planteamiento es que es correcto realizar Kolmogorov-Smirnov
ks.test(edad,"pnorm",60.5,11)
#Prueba t de una cola
t.test(edad,mu=55.5, alternative="less")
#Prueba Kolmogorov smirnov de una cola
ks.test(edad,"pnorm",55.5,11, alternative="less")
#Para una proporcin con prueba t
table(urbano)
t.test(urbano, mu=0.65)
#Para una proporcin con prueba binomial exacta
urbano.vector=table(urbano)
urbano.2=1-urbano
urbano.vector=table(urbano.2)
urbano.vector
#Se debe cambiar porque R toma el primer nmero como xitos
binom.test(urbano.vector, p=0.65)

#Prueba para una proporcin


prop.test(1706, n=2573, p=0.65)
#Test Wilcoxon
median(edad)
wilcox.test(edad, mu=59)
#Prueba de aleatoriedad
library(lawstat)
runs.test(edad)
runs.test(urbano)
########################################################################
#Salidas
names(antropomexicano)
[1] "id"
"ps3"
"numentrev" "sexo"
"edad"
[6] "escola" "ent_tip" "ponderador" "peso"
"altura"
[11] "cintura" "cadera" "tobillo" "rodilla" "urbano"
attach(antropomexicano)
mean(edad)
sd(edad)
#Prueba kolmogorov smirnov
ks.test(edad,"pnorm",mean(edad),sd(edad))
One-sample Kolmogorov-Smirnov test
data: edad
D = 0.0791, p-value = 2.032e-14
alternative hypothesis: two-sided
Warning message:
In ks.test(edad, "pnorm", mean(edad), sd(edad)) :
cannot compute correct p-values with ties

summary(edad)
Min. 1st Qu. Median Mean 3rd Qu. Max.
22.00 53.00 59.00 60.31 67.00 104.00
sd(edad)
[1] 10.64586
ks.test(edad,"pnorm",60.31,10.64586)
One-sample Kolmogorov-Smirnov test
data: edad
D = 0.0793, p-value = 1.787e-14
alternative hypothesis: two-sided
Warning message:
In ks.test(edad, "pnorm", 60.31, 10.64586) :
cannot compute correct p-values with ties
#Prueba Shapiro Wilks
shapiro.test(edad)
Shapiro-Wilk normality test
data: edad
W = 0.9788, p-value < 2.2e-16
#Prueba kolmogorov smirnov distribucin exponencial
ks.test(edad,"pexp",1/mean(edad))
Warning in ks.test(edad, "pexp", 1/mean(edad)) :
cannot compute correct p-values with ties
One-sample Kolmogorov-Smirnov test
data: edad
D = 0.4882, p-value < 2.2e-16
alternative hypothesis: two-sided

#Prueba Jarque Bera


hist(edad)
length(edad)
library(tseries)
jarque.bera.test(edad)
Jarque Bera Test
data: edad
X-squared = 101.2574, df = 2, p-value < 2.2e-16
#Prueba t
t.test(edad)
One Sample t-test
data: edad
t = 287.3399, df = 2572, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
59.89394 60.71702
sample estimates:
mean of x
60.30548
t.test(edad ,

mu=60.5)

One Sample t-test


data: edad
t = -0.9268, df = 2572, p-value = 0.3541
alternative hypothesis: true mean is not equal to 60.5
95 percent confidence interval:
59.89394 60.71702
sample estimates:
mean of x
60.30548

###Con este planteamiento es que es correcto realizar Kolmogorov-Smirnov


ks.test(edad,"pnorm",60.5,11)
Warning in ks.test(edad, "pnorm", 60.5, 11) :
ties should not be present for the Kolmogorov-Smirnov test
One-sample Kolmogorov-Smirnov test
data: edad
D = 0.0832, p-value = 6.661e-16
alternative hypothesis: two-sided
#Prueba t de una cola
t.test(edad,mu=55.5, alternative="less")
One Sample t-test
data: edad
t = 22.8969, df = 2572, p-value = 1
alternative hypothesis: true mean is less than 55.5
95 percent confidence interval:
-Inf 60.65082
sample estimates:
mean of x
60.30548
#Prueba Kolmogorov smirnov de una cola
ks.test(edad,"pnorm",55.5,11, alternative="less")
Warning in ks.test(edad, "pnorm", 55.5, 11, alternative = "less") :
ties should not be present for the Kolmogorov-Smirnov test
One-sample Kolmogorov-Smirnov test
data: edad
D^- = 0.2013, p-value < 2.2e-16
alternative hypothesis: the CDF of x lies below the null hypothesis
#Para una proporcin con prueba t
table(urbano)
t.test(urbano, mu=0.65)

One Sample t-test


data: urbano
t = 1.399, df = 2572, p-value = 0.1619
alternative hypothesis: true mean is not equal to 0.65
95 percent confidence interval:
0.6447635 0.6813151
sample estimates:
mean of x
0.6630393
#Para una proporcin con binomial exacta
urbano.vector=table(urbano)
urbano.2=1-urbano
urbano.vector=table(urbano.2)
urbano.vector
#Se debe cambiar porque R toma el primer nmero como xitos
binom.test(urbano.vector, p=0.65)
Exact binomial test
data: urbano.vector
number of successes = 1706, number of trials = 2573, p-value = 0.1726
alternative hypothesis: true probability of success is not equal to 0.65
95 percent confidence interval:
0.6444037 0.6813031
sample estimates:
probability of success
0.6630393
#Para una proporcin
prop.test(1706, n=2573, p=0.65)
1-sample proportions test with continuity correction
data: 1706 out of 2573, null probability 0.65
X-squared = 1.866, df = 1, p-value = 0.1719
alternative hypothesis: true p is not equal to 0.65
95 percent confidence interval:
0.6443479 0.6812393
sample estimates:
p

0.6630393
#Test Wilcoxon
median(edad)
[1] 59
wilcox.test(edad, mu=59)
Wilcoxon signed rank test with continuity correction
data: edad
V = 1685726, p-value = 0.0001917
alternative hypothesis: true location is not equal to 59
#Prueba de aleatoriedad
library(lawstat)
runs.test(edad)
Runs Test - Two sided
data: edad
Standardized Runs Statistic = -12.2801, p-value < 2.2e-16
runs.test(urbano)
Runs Test - Two sided
data: urbano
Standardized Runs Statistic = -Inf, p-value < 2.2e-16

Das könnte Ihnen auch gefallen