# NOT RUN {
# Normal distribution with Headrick's fifth-order PMT:
N <- nonnormvar1("Polynomial", 0, 1, 0, 0, 0, 0)
# }
# NOT RUN {
# Use Headrick & Kowalchuk's (2007) steps to compare a simulated exponential
# (mean = 2) variable to the theoretical exponential(mean = 2) density:
# 1) Obtain the standardized cumulants:
stcums <- calc_theory(Dist = "Exponential", params = 0.5) # rate = 1/mean
# 2) Simulate the variable:
H_exp <- nonnormvar1("Polynomial", means = 2, vars = 2, skews = stcums[3],
skurts = stcums[4], fifths = stcums[5],
sixths = stcums[6], n = 10000, seed = 1234)
H_exp$constants
# c0 c1 c2 c3 c4 c5
# 1 -0.3077396 0.8005605 0.318764 0.03350012 -0.00367481 0.0001587076
# 3) Determine whether the constants produce a valid power method pdf:
H_exp$valid.pdf
# [1] "TRUE"
# 4) Select a critical value:
# Let alpha = 0.05.
y_star <- qexp(1 - 0.05, rate = 0.5) # note that rate = 1/mean
y_star
# [1] 5.991465
# 5) Solve m_{2}^{1/2} * p(z') + m_{1} - y* = 0 for z', where m_{1} and
# m_{2} are the 1st and 2nd moments of Y*:
# The exponential(2) distribution has a mean and standard deviation equal
# to 2.
# Solve 2 * p(z') + 2 - y_star = 0 for z'
# p(z') = c0 + c1 * z' + c2 * z'^2 + c3 * z'^3 + c4 * z'^4 + c5 * z'^5
f_exp <- function(z, c, y) {
return(2 * (c[1] + c[2] * z + c[3] * z^2 + c[4] * z^3 + c[5] * z^4 +
c[6] * z^5) + 2 - y)
}
z_prime <- uniroot(f_exp, interval = c(-1e06, 1e06),
c = as.numeric(H_exp$constants), y = y_star)$root
z_prime
# [1] 1.644926
# 6) Calculate 1 - Phi(z'), the corresponding probability for the
# approximation Y to Y* (i.e. 1 - Phi(z') = 0.05), and compare to target
# value alpha:
1 - pnorm(z_prime)
# [1] 0.04999249
# 7) Plot a parametric graph of Y* and Y:
plot_sim_pdf_theory(sim_y = as.numeric(H_exp$continuous_variable[, 1]),
Dist = "Exponential", params = 0.5)
# Note we can also plot the empirical cdf and show the cumulative
# probability up to y_star:
plot_sim_cdf(sim_y = as.numeric(H_exp$continuous_variable[, 1]),
calc_cprob = TRUE, delta = y_star)
# }
Run the code above in your browser using DataLab