Remember: Look for the negative values in your data: Exponential, Weibull, Poisson, Geometric, do NOT take negative values.
vector <- c(4640,4967,4640,4967,4640,4957,5169,4957,5169,4957,5064,5033,5064,5033,5064,5062,4514,5062,4514,5062,5217,4883,5217,4883,5217,4658,4998,4658,4998,4658,5557,4843,5557,4843,5557,5510,5112,5510,5112,5510,5005,5111,5005,5111,5005,4967,4865,4967,4865,4967)
plot(table(vector))
hist(vector)
plot(ecdf(vector))
boxplot(vector)
library(MASS)
Fitting the data to the various distributions
norm1 <- fitdistr(vector,"normal")
exp1 <- fitdistr(vector,"exponential")
wei1 <- fitdistr(vector,"weibull")
geo1 <- fitdistr(vector,"geometric")
poi1 <- fitdistr(vector,"poisson")
Checking the Goodness of Fit
ksnorm <- ks.test(vector,"pnorm",mean=norm1$estimate[1],sd=norm1$estimate[2])
## Warning in ks.test(vector, "pnorm", mean = norm1$estimate[1], sd =
## norm1$estimate[2]): ties should not be present for the Kolmogorov-Smirnov
## test
ksexp1 <- ks.test(vector,"pexp",rate=exp1$estimate[1])
## Warning in ks.test(vector, "pexp", rate = exp1$estimate[1]): ties should
## not be present for the Kolmogorov-Smirnov test
kwei1 <- ks.test(vector,"pweibull",shape=wei1$estimate[1],scale=wei1$estimate[2])
## Warning in ks.test(vector, "pweibull", shape = wei1$estimate[1], scale =
## wei1$estimate[2]): ties should not be present for the Kolmogorov-Smirnov
## test
kgeo1 <- ks.test(vector,"pgeom",prob=geo1$estimate[1])
## Warning in ks.test(vector, "pgeom", prob = geo1$estimate[1]): ties should
## not be present for the Kolmogorov-Smirnov test
kpoi1 <- ks.test(vector,"ppois",lambda=poi1$estimate[1])
## Warning in ks.test(vector, "ppois", lambda = poi1$estimate[1]): ties should
## not be present for the Kolmogorov-Smirnov test
Now calculating the p-value
pvalue <- c(ksnorm$p.value,ksexp1$p.value,kwei1$p.value,kgeo1$p.value,kpoi1$p.value)
distribution <- c("normal","exponential","Weibull","Geometric","Poisson")
result <- cbind(distribution,pvalue)
result
## distribution pvalue
## [1,] "normal" "0.302095007679725"
## [2,] "exponential" "9.99200722162641e-16"
## [3,] "Weibull" "0.055498497967188"
## [4,] "Geometric" "9.99200722162641e-16"
## [5,] "Poisson" "0.00355905956179214"
As can be seen p value is more than 0.05 for the normal distribution .Means the two distributions are the same and null hypothesis is retained.