I would like to add a parabola line denoting 95% confidence limits to this coin toss plot using R:
x <- sample(c(-1,1), 60000, replace = TRUE)
plot.ts(cumsum(x), ylim=c(-250,250))
Here is an example of what I'm looking for:
UPDATE: @bill_080's answer is excellent. However I have already calculated 100,000 coin tosses:
str(100ktoss)
num [1:100000] -1 1 1 1 -1 -1 1 -1 -1 -1 ...
and I really want to just add the 95% limit to that plot:
plot.ts(cumsum(100ktoss))
It took several hours to calculate my 100K coin tosses and when I try and replicate with @bill_080's code I run out of memory (for 100,000).
FINAL UPDATE: Okay. Last problem. I have a plot of several rounds of cummulative hits, on a single graph with the start of each round clamped at zero (actually 1 or -1 depending on if it was a win or lose).
>str(1.ts)
Time-Series [1:35] from 1 to 35: 1 2 1 2 3 4 5 4 5 6 ...
>str(2.ts)
Time-Series [1:150] from 36 to 185: -1 0 1 0 -1 -2 -1 0 1 2 ...
I would like to add the same 95% limit to each segment, like thus. Now solved:
@bill_080 Many thanks. This is the the end product:
Try this. All loops are
for
loops, so you can easily add more calculations.Edit 1 ==========================================================
If you're just trying to draw the +/- 5% lines, it's just a square root function. Here's the code:
Edit 2 ==================================================
To add the parabolas at the right locations, it is probably easier if you define a function. Keep in mind that because the new function (
dralim
) useslines
, the plot has to exist before you calldralim
. Using some of the same variables as the code in Edit 1: