How to use simulation in R to compute probability of 2 people meeting in a cafe
ID: 2934400 • Letter: H
Question
How to use simulation in R to compute probability of 2 people meeting in a cafe between 2 times , eg 9 and 10. They stay for 20 mins per visit.Independent, arrival time between 9 and 10 is equally likely.
I am Using runif (n, 9, 10) to calculate proportion the two people meet up. How to use simulation in R to compute probability of 2 people meeting in a cafe between 2 times , eg 9 and 10. They stay for 20 mins per visit.
Independent, arrival time between 9 and 10 is equally likely.
I am Using runif (n, 9, 10) to calculate proportion the two people meet up.
Independent, arrival time between 9 and 10 is equally likely.
I am Using runif (n, 9, 10) to calculate proportion the two people meet up.
Explanation / Answer
n=100
x=runif(n,9,10)
y=runif(n,9,10)
sum=rep(0,n)
t1=x-.33
t2=x+.33
data.frame(x,y)
for(i in 1:n)
{
if((t1[i]>y[i])|(t2[i]<y[i]))
{sum[i]=1}
else
{sum[i]=0}
}
l=length(which(sum==1))
l/n
#required proportion
is required prodgram
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.