Skip to content

Relative Cumulative Frequency of Event Occurence

5 messages · Burhan ul haq, arun

1 day later
#
Hi Burhan,

No problem.? One suggestion in this code would be:
? with(df.1, cumsum(E.Occur==TRUE)/(seq_len(nrow(df.1))))? ##==TRUE is not needed
?identical( with(df.1, cumsum(E.Occur)/(seq_len(nrow(df.1)))),?? with(df.1, cumsum(E.Occur==TRUE)/(seq_len(nrow(df.1)))) )


?is.logical(TRUE)
#[1] TRUE


is.logical("Yes")
#[1] FALSE
A.K.
On Friday, November 29, 2013 12:36 PM, Burhan ul haq <ulhaqz at gmail.com> wrote:
Hi Arun,

Thanks a lot. It works perfectly.

Here is the complete code - for all those who are interested to see "Rel Cum Freq oscillating to reach the Expected Value"

# Bernouilli Trial where:
v.fly=c("G","B") # Outcome is Green or Blue fly
n=100 # No of Events / Trials
v.smp = seq(1:n) # Event Id
v.fst = sample(v.fly,n,rep=T) # Simulating First Draw
v.sec = sample(v.fly,n,rep=T) ?# Simulating Second Draw
df.1 = data.frame(sample = v.smp, fst=v.fst, sec = v.sec) # Clumping in a DF
df.1$E.Occur = with(df.1, ifelse(fst==sec,TRUE,FALSE)) # Event Occurs, if color is same in both the the draws
df.1$Rel.Freq = with(df.1, cumsum(E.Occur==TRUE)/(seq_len(nrow(df.1)))) # Relative Frequency?
df.1$Rel.Freq = round(df.1$Rel.Freq,2)

ggplot(df.1, aes(x=sample,y=Rel.Freq))+geom_line(col="green",size=2)+geom_abline(intercept=0.5,slope=0)+geom_point(col="blue")+labs(x="Sample No",y="Relative Cum Freq",title="Rel Cum Freq approaching 0.5 Value") + annotate("text",x=60,y=0.53,label="Probability of 0.5") ?



Cheers !?
On Thu, Nov 28, 2013 at 9:40 PM, arun <smartpink111 at yahoo.com> wrote:
HI,