Please provide the code in the language R. (请提供语言R的代码)
Suppose the incubation period, T , of a certain disease can be modeled by an exponential distribution with a mean of 4.5 days
1. Run a simulation to estimate the probability that, among 100 people who have contracted the disease, 80 or more people will develop symptoms within 5 days.
2. Suppose the number of new cases contracting the disease today follows a Poisson distribution with a mean of 100 people. Modify your simulation in (1) to estimate the probability that, among people who have contracted the disease today, 80 or more people will show symptoms within 5 days.
3. Generate a histogram of the distribution of the number of people that will show symptoms within 5 days, under the setup in (2).
1.
R code:
n=100000
a=0
count=0
for(k in 1:n)
{
for(i in 1:100)
{
x=rexp(100,(1/4.5))
if(x[i]<5)a=a+1
}
if(a>80)count=count+1
a=0
}
cat("The required probability is ",count/n)
Result:
[1] The required probability is 0.00151
2.
R code:
n=100000
a=0
count=0
x=rpois(n,100)
y=rexp(n,1/4.5)
for(i in 1:n)
{
if(x[i]>80 && y[i]<5 ) count=count+1
}
cat("The required probability is",count/n,"\n")
Result:
The required probability is 0.65526
3.
R code:
n=10000
k=1
z=c()
x=rpois(n,100)
y=rexp(n,1/4.5)
for(i in 1:n)
{
if(y[i]<5)
{
z[k]=x[i]
k=k+1
}
}
hist(z)
Graph:
Get Answers For Free
Most questions answered within 1 hours.