[R] What can I use instead of ks.test for the binomial distr

(Ted Harding) Ted.Harding at manchester.ac.uk
Sat Mar 13 22:52:37 CET 2010


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.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 13-Mar-10                                       Time: 21:52:33
------------------------------ XFMail ------------------------------



More information about the R-help mailing list