library(moments)
library(ecostats)
## Loading required package: mvabund
library(nortest)
library(vcd)
## Loading required package: grid
library(Rgof)
datos=read.table("Datos1.txt")
hist(datos$x)
boxplot(datos$x)
stem(datos$x)
##
## The decimal point is 1 digit(s) to the right of the |
##
## 5 | 578
## 6 | 13
## 6 | 5567788899
## 7 | 001112233333334444
## 7 | 555556666666677777888888888999999999999
## 8 | 000000012222222222333333334444444444444
## 8 | 555555555555555555566666677777777788888888888889999999999999999
## 9 | 0000000000111111111111111222222222222223333333344444
## 9 | 5555555555566666777778888888889999999
## 10 | 01222344
## 10 | 69
## 11 | 234
summary(datos$x)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 55.10 79.22 86.77 85.92 92.04 113.67
mean(datos$x)
## [1] 85.91785
median(datos$x)
## [1] 86.77045
skewness(datos$x)
## [1] -0.2700988
kurtosis(datos$x)
## [1] 3.480321
hist(datos$x,freq=F,ylab="Densidad",col="whitesmoke",ylim=c(0,0.045),main="Distribución de frecuencias de X",xlab="X")
lines(density(datos$x),col="#BF3EFF",lwd=3)
curve(dnorm(x, mean = 87.80697, sd = 9.780568),60,130,col="midnightblue",add=T,lwd=3)
curve(dgamma(x, shape = 71.444, scale=1.212),60,130,col="chocolate",add=T,lwd=3)
legend("topright",col=c("#BF3EFF","midnightblue","chocolate"),c("Densidad","Normal teórica","Gamma teórica"),lty=1,lwd=3)
hist(datos$x,freq=F,ylab="Densidad",col="whitesmoke",ylim=c(0,0.045))
lines(density(datos$x),col="midnightblue",lwd=3)
curve(dgamma(x, shape = 71.444, scale=1.212),60,130,col="chocolate",add=T,lwd=3)
Intervalos=c(mean(datos$x)-4*sd(datos$x),mean(datos$x)-3*sd(datos$x),mean(datos$x)-2*sd(datos$x),mean(datos$x)-sd(datos$x), mean(datos$x),mean(datos$x)+sd(datos$x),mean(datos$x)+2*sd(datos$x),mean(datos$x)+3*sd(datos$x),mean(datos$x)+4*sd(datos$x))
hist(datos$x,freq=F,ylab="Densidad",breaks=Intervalos,col="whitesmoke",ylim=c(0,0.045))
hist(datos$x,breaks=Intervalos,plot=F)
## $breaks
## [1] 47.04248 56.76132 66.48017 76.19901 85.91785 95.63669 105.35554
## [8] 115.07438 124.79322
##
## $counts
## [1] 2 6 35 88 106 34 5 0
##
## $density
## [1] 0.0007456008 0.0022368023 0.0130480134 0.0328064338 0.0395168407
## [6] 0.0126752131 0.0018640019 0.0000000000
##
## $mids
## [1] 51.90190 61.62074 71.33959 81.05843 90.77727 100.49612 110.21496
## [8] 119.93380
##
## $xname
## [1] "datos$x"
##
## $equidist
## [1] TRUE
##
## attr(,"class")
## [1] "histogram"
##Gráfico de cuantiles teóricos vs cuantiles muestrales, envolvente
qqnorm(datos$x)
qqenvelope(datos$x)
##Comparación de los datos de la muestra, con una muestra simulada de la distribución normal teórica propuesta
mu=mean(datos$x)
desvest=sd(datos$x)
yy=rnorm(276,mu,desvest)
qqplot(datos$x,yy)
####Comparación de los datos de la muestra, con una muestra simulada de la distribución teórica Gamma propuesta
yygam=rgamma(276,shape=72,scale=1.2)
qqplot(datos$x,yygam,col=2)
##Prueba de hipótesis de Kolmogorov Smirnov
ks.test(datos$x, "pnorm", mean=86, sd=10)
##
## Asymptotic one-sample Kolmogorov-Smirnov test
##
## data: datos$x
## D = 0.05457, p-value = 0.3837
## alternative hypothesis: two-sided
ks.test(datos$x, "pgamma",shape=71.444, scale=10)
##
## Asymptotic one-sample Kolmogorov-Smirnov test
##
## data: datos$x
## D = 1, p-value < 2.2e-16
## alternative hypothesis: two-sided
##Pruebas de hipótesis de normalidad del paquete nortest. Ejercicio consultar los estadísticos de todas las pruebas ejecutadas a continuación
ks.test(datos$x, "pnorm", mean=86, sd=10)
##
## Asymptotic one-sample Kolmogorov-Smirnov test
##
## data: datos$x
## D = 0.05457, p-value = 0.3837
## alternative hypothesis: two-sided
shapiro.test(datos$x)
##
## Shapiro-Wilk normality test
##
## data: datos$x
## W = 0.98956, p-value = 0.04492
ad.test(datos$x)
##
## Anderson-Darling normality test
##
## data: datos$x
## A = 0.83144, p-value = 0.03165
cvm.test(datos$x)
##
## Cramer-von Mises normality test
##
## data: datos$x
## W = 0.14178, p-value = 0.03039
lillie.test(datos$x)
##
## Lilliefors (Kolmogorov-Smirnov) normality test
##
## data: datos$x
## D = 0.054862, p-value = 0.04351
pearson.test(datos$x)
##
## Pearson chi-square normality test
##
## data: datos$x
## P = 16.159, p-value = 0.4419
sf.test(datos$x)
##
## Shapiro-Francia normality test
##
## data: datos$x
## W = 0.98913, p-value = 0.03678