Dear Members, I try to create a generic test function for distribution error for binomial negative, Poisson and normal. But my function doesn't work (NA's produced and don't realize the test) and I don't know why, any member can help me? My function is:
require(MASS) BD<-rpois(1000,10) ### Data set for test Dist<-c("negative binomial","normal","Poisson") for(typeD in 1:Dist){ k <- fitdistr(BD,typeD[Dist]) par <- k$estimate size <- par[1]#Parameter mu <- par[2]#Mean SD<-sd(BD) N <- length(BD) if (typeD[Dist]=='negative binomial'){ ### For binomial negativa est <-N*dnbinom(BD,size=size,mu=mu) ## Estimates fecdf <- ecdf(BD) ###ecdf- Empiric cumulative function knotsX <- knots(fecdf) emp <- fecdf(c(knotsX,Inf)) # Empiric chisq.test(table(emp),table(est),correct=TRUE) ##Chi test } if (typeD[Dist]=='normal'){ ### For normal est <-N*dnorm(BD,mean=mu, sd=SD) ## Estimates fecdf <- ecdf(BD) ###ecdf- Empiric cumulative function knotsX <- knots(fecdf) emp <- fecdf(c(knotsX,Inf)) # Empiric chisq.test(table(emp),table(est),correct=TRUE) ##Chi test } if (typeD[Dist]=='Poisson'){ ### For Poisson est <-N*dpois(BD,lambda=mu) ## Estimate fecdf <- ecdf(BD) ###cdf- Empiric cumulative function knotsX <- knots(fecdf) emp <- fecdf(c(knotsX,Inf)) # Empiric chisq.test(table(emp),table(est),correct=TRUE) ## Chi test } } # Thanks, -- ====================================================================== Alexandre dos Santos Prote��o Florestal IFMT - Instituto Federal de Educa��o, Ci�ncia e Tecnologia de Mato Grosso Campus C�ceres Caixa Postal 244 Avenida dos Ramires, s/n Bairro: Distrito Industrial C�ceres - MT CEP: 78.200-000 Fone: (+55) 65 8132-8112 (TIM) (+55) 65 9686-6970 (VIVO) alexandre.san...@cas.ifmt.edu.br Lattes: http://lattes.cnpq.br/1360403201088680 ====================================================================== [[alternative HTML version deleted]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology