set.seed(1)
n = 10000
alpha = 1
beta = 4
# W = alpha [-log(1 - U)]^{1/beta}
U = runif(n,0,1)
W = alpha*(-log(1-U))^(1/beta)
# Part (a):
# PDF:
hist(W,probability = TRUE)
# CDF:
plot(ecdf(W))
# Part (b):
# From empirical proportion
prob_emp = mean(W<0>0.2)
# From cdf
F = function(x){ # CDF function
1 - exp(-(x/alpha)^beta)
}
prop_act = F(0.8) - F(0.2)
prop_act - prob_emp
# Part (c):
# From emperical
Q1_emp = quantile(W,0.25)
M_emp = quantile(W,0.5)
Q3_emp = quantile(W,0.75)
# Inverse quantile
F_inv = function(x){ # Inverse function for quantile
alpha*(-log(1-x))^(1/beta)
}
Q1_act = F_inv(0.25)
M_act = F_inv(0.50)
Q3_act = F_inv(0.75)
Q1_act - Q1_emp
M_act - M_emp
Q3_act - Q3_emp