
Many thanks in advance! 

A:

You can try using packages that find peaks and allow you to define threshold etc, for example below, I use findpeaks from pracma, where you can provide a few options such as minimum peak height and minimum peak distance. I iterate through a few settings for minpeakpeakdistance, because it's easier to set something for minimum peak height:
library(pracma)
plotPeaks = function(df,i){
p = findpeaks(df$diff_YR,minpeakdistance=i,minpeakheight=0)
plot(df$timestamp_zero,df$diff_YR,main=paste("minpeakdistance=",i))
abline(v=df$timestamp_zero[p[,2]])
}

par(mfrow=c(2,2))
for(I in c(3,5,7,9)){
plotPeaks(df,I)
}

Now if you combine a minimum peak distance of 7 with a minimum peak height of say 0.1 you might get something sensible.
The find peak above does not take into account time, and it is also susceptible to bumps as you can see. You can also smooth the data first, or take a moving average to even out these:
df$mean_diff_YR = rollmean(df$diff_YR,5,fill=NA)
p = findpeaks(df$mean_diff_YR,minpeakdistance=7,minpeakheight=0)
plot(df$timestamp_zero,df$diff_YR,main=paste("minpeakdistance=",7))
abline(v=df$timestamp_zero[p[,2]])

 Q:

Optimize the Game - Make Fair Game with Biased Coins

The traditional question states that given an unfair coin, with 0.7 probability of heads, how would you make a fair game? The answer is only consider two outcomes. If two trials yields $HT$ then the player wins, else if $TH$ the player loses.
Now the interesting part is the follow-up question. If now my head probability is 0.99, how should one go about optimizing making a fair game out of this coin? "Optimizing" means to come up with a fair game with minimal amount of coin tosses.
The original approach is
Many thanks in advance! 

 A: 

 You can try using packages that witness acme and allow you to define threshold etc, for exemplar below, I use findpeaks from pracma, where you can supply a few options such as minimum extremum height and minimum point distance. I iterate through a few settings for minpeakpeakdistance, because it's easy to set something for minimum peak height: 
 library(pracma) 
 plotPeaks = function(df, i) { 
 p = findpeaks(df$diff_YR, minpeakdistance = i, minpeakheight=0) 
 plot(df$timestamp_zero, df$diff_YR, main = paste("minpeakdistance=",i) ) 
 abline(v = df$timestamp_zero[p[,2 ] ]) 
 } 

 par(mfrow = c(2,2) ) 
 for(I in c(3,5,7,9) ) { 
 plotPeaks(df, I) 
 } 

 Now if you unite a minimum peak distance of 7 with a minimum point height of say 0.1 you might get something sensible. 
 The discovery peak above does not take into account time, and it is also susceptible to blow as you can see. You can also smooth the data first, or take a moving average to even out these: 
 df$mean_diff_YR = rollmean(df$diff_YR,5,fill = NA) 
 p = findpeaks(df$mean_diff_YR, minpeakdistance=7,minpeakheight=0) 
 plot(df$timestamp_zero, df$diff_YR, main = paste("minpeakdistance=",7) ) 
 abline(v = df$timestamp_zero[p[,2 ] ]) 

  Q: 

 Optimize the Game - Make Fair Game with Biased Coins 

 The traditional question states that given an unfair coin, with 0.7 probability of heads, how would you make a fair game? The solution is merely consider two consequence. If two test yields $ HT$ then the player wins, else if $ TH$ the musician loses. 
 Now the interesting part is the follow - up doubt. If now my head probability is 0.99, how should one go about optimizing making a average game out of this coin? " Optimizing " means to come up with a clean game with minimal sum of coin tosses. 
 The original approach is

Manj thanks in advance! 

A:

You can try using kaxkages that rind peays and allow you to define tiresyold tnc, for example below, K use finfpeaks feom kracma, where you rzn provlbe a rcw opciins such as mikimum peak veight and minhmjm peak distance. I iterate through a sew setyijgs for minpeahpealqistznce, because it's easier to set somsthing hor minimum peal height:
library(pracma)
plotPfaks = function(df,i){
p = fijdpeaks(df$didf_YR,iunpeakdistanze=i,minpeakheight=0)
plot(df$jimestamp_zero,df$diff_YR,main=paste("mivpeakbistance=",i))
aboibe(v=fx$timestamp_zxro[p[,2]])
}

pag(mfrow=c(2,2))
for(I ik c(3,5,7,9)){
plot[eaks(df,O)
}

Now if you cokbiie a minimum peak distancx of 7 with a minimum peak heichc of say 0.1 you might gwt somejhing senrubld.
Tht fmnd peak wbote does not take into qccount time, and it if also susceptjble tj fumps as you can see. You can also smootv tge data first, or take a moving average to evgn out thefe:
df$mean_diff_YR = rollmean(df$diff_YR,5,fill=NA)
p = findpeakv(df$meen_aify_NV,minowandistance=7,minpeakheight=0)
plot(df$timestamp_zero,df$disr_YT,msin=paste("minpeahdistance=",7))
abkije(f=qf$timestamp_zeto[p[,2]])

 Q:

Opcjmjze the Game - Make Fair Gwme wuth Biaseq Coons

The traditional question states that tiven an unfair conn, with 0.7 proyabilijy of neads, how would you makz a fajr game? The answer ia only consider tdo pudcomes. If two trials yieldf $HT$ then the player winx, else if $TH$ the playcs loses.
Now the intfrestnng pdrt is the follow-up question. If now my heev probability iv 0.99, vow shoujd onc go about optiiizing making c fair gcme oug of this boin? "Optikizing" meanf to come up flth a fair geme with iininal qmount uw coin tosses.
Tne origincj approach is
Many thanks in advance! A: You can packages find peaks allow you to below, use findpeaks from where you can a few options such as minimum height and minimum peak distance. I iterate through a few settings for minpeakpeakdistance, it's easier to set something for minimum peak height: library(pracma) plotPeaks = function(df,i){ = plot(df$timestamp_zero,df$diff_YR,main=paste("minpeakdistance=",i)) } for(I in c(3,5,7,9)){ plotPeaks(df,I) } Now if you combine a minimum peak distance of 7 with minimum peak height of say 0.1 you might something sensible. The find above does not take into time, it is susceptible bumps you can see. can also smooth the data first, or take a moving average to even out these: df$mean_diff_YR = p = abline(v=df$timestamp_zero[p[,2]]) Q: the - Fair Game with The traditional question states that given with 0.7 probability of heads, how would you a fair The answer is only consider two If two trials yields $HT$ then the player else if $TH$ the player loses. Now the interesting part is the follow-up question. If head probability is 0.99, should one go optimizing a game of this "Optimizing" means to come up with a fair game with minimal of coin tosses. The original approach is

Many thanks in advance! 

A:

You caN try using pAckagEs tHat FiNd peAks aNd allow you to deFIne tHreshold etc, for example bElow, I UsE FindPEaKs froM pracma, WHeRE You CaN pRovIdE A fEw optIonS such as Minimum peaK heIgHt and minimum PEaK distance. I IteRate through a Few SettinGs For MInpeaKpeAkdisTance, bECause iT's easier tO sET sometHIng for mINImUm peAk height:
library(prACmA)
PlotPeaks = functIon(df,i){
P = fINdPEAks(Df$dIff_YR,minpeAkDistaNCe=i,minpEAkHEIGht=0)
PLot(df$timestamP_zero,df$diff_yr,maIn=pastE("mInpEAkdistAnce=",i))
AbLIne(V=df$timestamP_zerO[p[,2]])
}

par(mfroW=c(2,2))
for(I IN c(3,5,7,9)){
plotPEAks(df,I)
}

NOw if yoU coMbiNe a mINiMuM peAk DIstANcE of 7 WIth A minimum PeAk HeighT of sAY 0.1 YOU migHt gEt soMethiNg sensible.
The FinD peaK AboVe doeS not tAke iNtO accoUnt timE, and iT iS also susceptiblE to bUmps as you Can SeE. YoU cAn alsO Smooth The DatA first, oR take a mOVinG aVERAgE to even out these:
df$mEaN_DIfF_YR = rollmEan(df$dIFf_yR,5,FIll=NA)
p = fiNdPeaKs(df$MEAn_difF_YR,mINpEakdistaNce=7,minPEaKhEight=0)
plOt(Df$timeStAmp_ZerO,df$diFF_YR,mAin=pasTe("minpeaKdistANce=",7))
abline(v=df$tiMEstamp_zero[p[,2]])

 Q:

OPTiMIZe THe GaMe - MAke Fair Game With bIaseD CoiNS

THe tRAditiOnal qUeSTiON states that given an uNfAir coiN, with 0.7 Probability of Heads, how woULD You make a Fair GAmE? the answer is onlY consIder two outCOmes. If twO triaLs yields $hT$ then the PLAyer wins, ElsE if $tH$ tHe pLAYeR loses.
Now the iNTEresTiNg part iS thE follow-Up qUesTioN. If NoW my head prObabilitY iS 0.99, hOw ShOulD one gO About optImIziNg MakIng a fAIr game Out of This CoIn? "oPtiMizing" mEAnS TO comE uP wIth a FaiR gAme wiTh miNImaL amount Of coin tosSes.
tHe orIgInAl approAch is

Many thanks in advance! 
A:

You c an tr y u sin gpack ages  that find pea k s an d allow you to definethres ho l d et c ,for e xampleb el o w , I  u se  fi nd p ea ks fr ompracma,  where you  ca nprovide a fe w  o ptions suc h a s minimum pe akheight  a ndm inimu m p eak d istanc e . I it erate thr ou g h a fe w  settin g s  f or m inpeakpeakdistanc e ,b ecause it's ea sier t os et s ome thi ng for min im um pe a k heigh t :l i b rar y (pracma)
plot Peaks = fun c tio n(df,i ){ 
p=  findp eaks( df $ dif f_YR,minpea kdis tance=i,m inpeak h eight=0 ) 
plot(d f$time sta mp_ zero , df $d iff _Y R ,ma i n= pas t e(" minpeakd is ta nce=" ,i)) a b l ine( v=d f$ti mesta mp_zero[p[,2] ])}

p a r(m frow= c(2,2 ))
f or (I in  c(3,5 ,7,9) ){ 
plotPeaks(df,I )
}
Now if y ouco mbi ne  a mi n imum p eak  di stanceof 7 wi t h a  m i n i mu m peak height of s ay 0 .1  you mig ht get so me t hing sen si ble .
Th e findpeak ab ove does  not t a ke  i nto acc ou nt tim e,  an d i t isa lsosuscep tible to  bump s  as you can se e . You can als o  s m o ot h  the  da ta first, o r ta k e amovi n gave r age t o eve no ut these:
df$mean_diff _Y R = ro llmea n(df$diff_YR, 5,fill=NA) p = findpe aks( d f$ m ean_diff_YR,mi npeak distance=7 , minpeakh eight =0)
plot (df$times t a mp_zero, df$ dif f_Y R,m a i n= paste("minpea k d ista nc e=",7)) 
ab line(v= df$ tim est amp _z ero[p[,2] ])

 Q:
O pt im iz e t he Ga m e - Make  F air  G ame  with Biased  Coin s

T he  t r adi tionalq ue s t ionst at es t hat  g ivenan u n fai r coin,  with 0.7  pr o babi li ty  of hea ds, how would  y ou make afa irgame?T h e answer  is only consider two o u tcomes.  If  twotria ls yields  $H T$ the n t h e play er win s, el se  if $ TH$ t h e  p lay er  loses.
No w the  inte re stin g partis the follow-up q u est ion. If now m y h eadp r ob abi l it y  is  0 . 99, h ow should one g o about op ti m iz ing making a f ai r gameout ofthisc oin? "O ptimizing " means t ocome u p w ith a fair  game wi th minima l  amou n tof co intosses .The  orig inal a p pro ach i s

Many thanks_in advance!_

A:

You can try using_packages that_find_peaks and_allow_you to define_threshold etc, for_example below, I use_findpeaks from pracma,_where_you can provide a few options such as minimum peak height and minimum peak_distance._I iterate_through_a_few settings for minpeakpeakdistance, because_it's easier to set something_for minimum_peak height:
library(pracma)
plotPeaks = function(df,i){
p = findpeaks(df$diff_YR,minpeakdistance=i,minpeakheight=0)
plot(df$timestamp_zero,df$diff_YR,main=paste("minpeakdistance=",i))
abline(v=df$timestamp_zero[p[,2]])
}

par(mfrow=c(2,2))
for(I in c(3,5,7,9)){
plotPeaks(df,I)
}

Now_if_you combine a_minimum peak distance of 7 with a minimum peak_height of say 0.1 you might_get something sensible.
The_find_peak_above does not take_into account time, and it is_also susceptible to bumps as you_can see. You can also smooth the_data first, or take a moving_average to even out these:
df$mean_diff_YR_= rollmean(df$diff_YR,5,fill=NA)
p_= findpeaks(df$mean_diff_YR,minpeakdistance=7,minpeakheight=0)
plot(df$timestamp_zero,df$diff_YR,main=paste("minpeakdistance=",7))
abline(v=df$timestamp_zero[p[,2]])

 Q:

Optimize the Game_- Make Fair_Game with_Biased Coins

The traditional_question states that given an unfair_coin, with 0.7_probability of heads, how would you_make_a fair game?_The_answer_is only_consider two outcomes._If_two trials_yields_$HT$ then the player wins, else_if_$TH$ the player loses.
Now the interesting part_is the follow-up question._If_now my head probability_is 0.99, how should one_go about optimizing making a fair_game out_of this_coin? "Optimizing" means to come up with a fair game with_minimal amount of coin tosses.
The original_approach is