samedi 31 octobre 2015

Runs test function of RNG quality

I wrote the function that uses the runs test to access the quality of RNG. Is there a way to write it without "if" and "for"?

u=runif(10,0,1)
runs.test=function(u){
x=(u<0.5)
x=as.numeric(x)
count=1;
for (i in 1:(length(x)-1)){
  if (x[i]==x[i+1]){
    count=count;
  }else{
    count=count+1;
  }
  }
  return(count);
}




Aucun commentaire:

Enregistrer un commentaire