Vous êtes sur la page 1sur 2

Generando datos:

> set.seed(28)
> datos1<-rpois(50,3)
> datos1
[1] 0 1 3 5 1 4 0 5 3 6 4 4 3 5 3 2 2 4 7 3 2 2 6 1 3 3 2 2 0 1 5 3 5 5 2 5 3 2
4 2 3 3 2 0 2
[46] 4 4 2 1 3
> tbl<-table(datos1)
> tbl
datos1
0 1 2 3 4 5 6 7
4 5 12 12 7 7 2 1
> mean(datos1)
[1] 2.94

Prueba de Kolmogorov
a)
> ks.test(datos1,"ppois",3)

One-sample Kolmogorov-Smirnov test

data: datos1
D = 0.2432, p-value = 0.005402
alternative hypothesis: two-sided

Warning message:
In ks.test(datos1, "ppois", 3) :
ties should not be present for the Kolmogorov-Smirnov test

b)
> ks.test(datos1,"ppois",mean(datos1))

One-sample Kolmogorov-Smirnov test

data: datos1
D = 0.2568, p-value = 0.00274
alternative hypothesis: two-sided

Warning message:
In ks.test(datos1, "ppois", mean(datos1)) :
ties should not be present for the Kolmogorov-Smirnov test

Calculando probabilidades
> a<-dpois(0,mean(datos1))
> b<-dpois(1,mean(datos1))
> c<-dpois(2,mean(datos1))
> d<-dpois(3,mean(datos1))
> e<-dpois(4,mean(datos1))
> f<-dpois(5,mean(datos1))
> g<-1-ppois(5,mean(datos1))

Creando la matriz
> e<-c(a*50,b*50,c*50,d*50,e*50,f*50,g*50)
> e
[1] 2.643286 7.771262 11.423755 11.195280 8.228531 4.838376 3.899509
> x<-c(4,5,12,12,7,7,3)
> y<-c(a,b,c,d,e,f,g)
> y
[1] 0.05286573 0.15542524 0.22847511 0.22390560 2.64328644 7.77126212
11.42375532
[8] 11.19528022 8.22853096 4.83837620 3.89950874 0.09676752 0.07799017
> z<-matrix(c(x,y),ncol=2)
> z
[,1] [,2]
[1,] 4.00000000 0.22390560
[2,] 5.00000000 2.64328644
[3,] 12.00000000 7.77126212
[4,] 12.00000000 11.42375532
[5,] 7.00000000 11.19528022
[6,] 7.00000000 8.22853096
[7,] 3.00000000 4.83837620
[8,] 0.05286573 3.89950874
[9,] 0.15542524 0.09676752
[10,] 0.22847511 0.07799017

Prueba Chi-cuadrado
> chisq.test (z)

Pearson's Chi-squared test

data: z
X-squared = 10.3499, df = 9, p-value = 0.3229

Warning message:
In chisq.test(z) : Chi-squared approximation may be incorrect

Sin usar la función chisq.test


> x2<-sum(((x-e)^2)/e)
> x2
[1] 3.128165
> pvalor<-1-pchisq(x2,6)
> pvalor
[1] 0.7925975

Vous aimerez peut-être aussi