[R-sig-eco] Generic test function for distribution errors

ASANTOS alexandresantosbr at yahoo.com.br
Sat Oct 31 12:24:59 CET 2015


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.santos at cas.ifmt.edu.br
Lattes: http://lattes.cnpq.br/1360403201088680
======================================================================


	[[alternative HTML version deleted]]



More information about the R-sig-ecology mailing list