[R] Simulation of data
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Tue Oct 21 08:43:24 CEST 2008
2008/10/21 Marcioestat <marcioestat at pop.com.br>:
>
> Hi listers,
> I am working on a program of statistical analysis of simulated data and I've
> been searching the error at the program, but I didn't find it!
> It is something about the WHILE procedure, the error says: Error in while
> (ecart >= d) { : missing value where TRUE/FALSE needed
How much do you know about debugging programs? Read the R help for
"debug" and "browser". These tools let you inspect your program at any
point so you can see what the values of variables are.
Anyway, for you error message, I'd guess there was a missing value in
'ecart' or 'd' or both:
> ecart
[1] NaN
> d
[1] 0.00112
so, ecart is Not A Number. How could that happen? Well, ecart is a
square root of something, so maybe that something is negative:
> proportion*(1-proportion)
[1] -0.01874365
Hmmm
> proportion
[1] 1.018405
I would bet that proportion isn't supposed to be more than 1 (or less
than 0). How did that happen?
This line looks a bit dodgy:
proportion<-proportion+(prop[k+1]-proportion/(k+1))
since you're adding something to a proportion... Should that division
be outside the parentheses? Hard to tell without knowing exactly what
the code is trying to do. The proportion goes >1 when w is over your
1.75 threshold. Are you just trying to update proportion=mean(prop)
again? Why not do that? If I replace your line with proportion =
mean(prop) then it runs and terminates after about 32000 iterations.
Protip: Updating a mean like this is probably quicker but if you ever
write a tricky bit of code test it first!
Barry
More information about the R-help
mailing list