Sorry -- I made a complete mess of my first suggestion below: On 13-Mar-10 21:27:28, Ted Harding wrote: > For testing whether x comes from a binomial distribution, > I would suggest just using a straight chi-squared test. > I'm not aware of a version of chisq.test() in R aimed at > seeing whether data match a fitted binomial (or other > specific) distribution, but it is easy to construct one; > > x<-rbinom(10000,10,0.5) > phat<-sum(x)/length(x) ####!! phat will be wrong by *10!! > dhat <- dbinom((0:10),10,0.5) ####!! Uses p=0,5 instead of phat!! > Freq <- table(x) > Exp <- 10000*dhat > ChiSq <- sum(((Freq-Exp)^2)/Exp); DF <- (11-1-1) > 1-pchisq(ChiSq,DF) > # [1] 0.6788829
Instead: N <- 10000 n <- 10 x<-rbinom(N,n,0.5) phat<-sum(x)/(N*n) dhat <- dbinom((0:n),n,phat) Freq <- table(x) Exp <- N*dhat ChiSq <- sum(((Freq-Exp)^2)/Exp); DF <- (n-1-1) 1-pchisq(ChiSq,DF) # [1] 0.8537699 (I think the rest of my previous response is OK ... ). Ted. [All contributions to my Hypocaffeinemia Appeal gratefull received] -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.hard...@manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 13-Mar-10 Time: 21:52:33 ------------------------------ XFMail ------------------------------ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.