Probability that we have recovered at or before time $N$
"""
plot_cumulative!(p, N, δ=1)
- `p` is prob to decay at each time step
- `N` is total number of time steps
- `δ` is time between steps
Prob mass function is ``f_X(n) = p (1 - p)^{n-1}``
"""
function plot_cumulative!(p, N, δ=1; label="")
ps = [p * (1 - p)^(n-1) for n in 1:N]
cumulative = cumsum(ps)
ys = [0; reduce(vcat, [ [cumulative[n], cumulative[n]] for n in 1:N ])]
pop!(ys)
pushfirst!(ys, 0)
xs = [0; reduce(vcat, [ [n*δ, n*δ] for n in 1:N ])];
plot!(xs, ys, label=label)
scatter!([n*δ for n in 1:N], cumulative, label="")
end
plot_cumulative!
?plot_cumulative!
search: plot_cumulative!
plot_cumulative!(p, N, δ=1)
p
is prob to decay at each time stepN
is total number of time stepsδ
is time between stepsProb mass function is $f_X(n) = p (1 - p)^{n-1}$
using Plots
plot_cumulative!(0.1, 20)
xlabel!("n")
ylabel!("cum. prob. <= n")
p = 0.1
N = 50
δ = 0.4
plot()
plot_cumulative!(p, N, 1.0, label="delta = 1")
plot_cumulative!(p, N, δ, label="delta = $(δ)") # $a inserts value of variable a
using Interact
Unable to load WebIO. Please make sure WebIO works for your Jupyter client. For troubleshooting, please see the WebIO/IJulia documentation.
p = 0.1
N = 100
δ = 0.5
@manipulate for p2 in 0.01:0.01:1.0
plot()
plot_cumulative!(p, 40, 1.0, label="delta = 1")
plot_cumulative!(p2, N, δ, label="delta = $(δ)") # $a inserts value of variable a
xlims!(0, 40)
ylims!(0, 1)
end
Cumulative distribution function for geometric random variable $X \sim \text{Geom}(p)$
$$F_X(n) = 1 - (1 - p)^n$$$F_{Y_\delta}(n) = 1 - [1 - p(\delta)]^n$
Fix time $t = n$. Find $p(\delta)$ such that probabilities are the same at time $t$
$t = n \delta$
So $n = t / \delta$
Exercise: Solve for $p(\delta)$
Limit $\delta \to 0$
Need $p(\delta) \to 0$
If $x$ is small, $1 - x \simeq \exp(-x)$
$\exp(x) = 1 + x + \frac{1}{2} x^2 + \frac{1}{3!} x^3 + \cdots + \frac{1}{n!} x^n + \cdots$
$\exp(x) = \sum_{n=0}^\infty \frac{1}{n!} x^n$
Define $\exp{}$ as the function which is equal to its derivative and suppose that I can write as a power series in $x$
x = 0.01
0.01
1 - x
0.99
exp(-x)
0.9900498337491681
x^2 / 2
5.0e-5
Need $p(\delta) / \delta \to \lambda$ when $\delta \to 0$
End result: $F(t) = 1 - \exp[-\lambda t]$
$\lambda$ is rate -- probability per unit time
$1 - (1 - p)^t$
Choose $\lambda$ such that $1 - p = \exp(- \lambda)$
plot()
p = 0.1
λ = -log(1 - p)
plot_cumulative!(p, 50)
plot!(0:0.01:20, t -> 1 - exp(-λ*t), lw=3)
Exponential random variable $Z$
$F_Z(t) = \mathbb{P}(Z \le t)$