I want to study the distribution (histogram of the values of S greater than 0 for n=10000 replicated 10000 times. However, I'm not getting the correct output, how can I go about obtaining the histogram? Here's what I have:
rwlength=function(nsims,n){
t=numeric(nsims)
for( i in (1:nsims))
{
t[i]=aboveaxis(n)
}
return(t)
}
hist(rwlength(10000,10000))
Note:
aboveaxis = function(n) {
if (n<=0){ return(cat("n must be greater than 0"))}
else
step = c(1, -1)
S = c(0, cumsum(sample(step,n, prob=c(.5, .5), replace=T)))
above=sum(S[S > 0])
return(above)
}
aboveaxis is a function that returns the sum of the S values greater than 0
Thanks!