[R] Need some help

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Tue Oct 16 20:00:49 CEST 2007

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of azzza
> Sent: Tuesday, October 16, 2007 9:06 AM
> To: r-help at r-project.org
> Subject: Re: [R] Need some help
> You are right, I was a bit too vague. I am trying to simulate 
> 1000 coin
> Tosses. Then to write a code for the number of 
> heads/Tails.....naturally, we
> would expect the proportion of heads to be 50% so the number 
> of heads would
> be around 500. Secondly, I'm trying to look at the number of 
> sign changes in
> 1000 tosses. The example in the book shows that the number of 
> sign changes
> is WAY less than 50%. so I was  trying to look for a code 
> that shows the
> number of sign changes, which someone pointed out would be to use
> rle(x).....my concern however is that when the rle(x) is used, the
> proportion of sign changes is about 50% (around 500), which 
> would be logical
> to expect, however, real life experiments have shown that the 
> number of sign
> changes is actually much less than 50%. The other thing I was 
> trying to do
> is to plot a line graph of number of sign changes versus the number of
> tosses. Yes, the number of tosses should begin at zero, and 
> at zero coin
> toss, the sign change is zero. The range of the number of 
> sign changes in
> the Y-axis should include negative values of Y. So, for toss 
> number zero,
> the sign change is 0, for the first toss, the sign change may 
> be +3 for
> instance, 

I guess I don't understand what you mean by "sign change".  It seems to me that on any given toss there either is or there isn't a change from heads to tails (or tails to head).  How then would it be possible to get a +3 sign change on the first toss?  Also, I might guess as to what you mean by a negative sign change but my crystal ball is in the shop :-).

Again, I would recommend that you simulate 10 coin tosses, and then by hand determine your negative and positive sign changes, and then show us the tosses, the sign changes, and the y value that you want plotted for each toss.  That would at least clarify for me (if for no one else) what the issues are. 

Sorry I don't have any better advice at the moment,


Daniel J. Nordlund
Research and Data Analysis
Washington State Department of Social and Health Services
Olympia, WA  98504-5204

More information about the R-help mailing list