## Local alternatives diagnostics
loc_alt_diagnostic <- function(p, type, thre = 1e-3, K_max = 1e3) {
# Coefficients of the alternative
uk <- cutoff_locdev(K_max = K_max, p = p, type = type, thre = thre,
N = 640)
old_par <- par(mfrow = c(2, 2))
# Construction of f
z <- seq(-1, 1, l = 1e3)
f <- function(z) f_locdev(z = z, p = p, uk = uk)
plot(z, f(z), type = "l", xlab = expression(z), ylab = expression(f(z)),
main = paste0("Local alternative f, ", type, ", p = ", p), log = "y")
# Projected density on [-1, 1]
f_proj <- function(z) rotasym::w_p(p = p - 1) * f(z) *
(1 - z^2)^((p - 3) / 2)
plot(z, f_proj(z), type = "l", xlab = expression(z),
ylab = expression(omega[p - 1] * f(z) * (1 - z^2)^{(p - 3) / 2}),
main = paste0("Projected density, ", type, ", p = ", p), log = "y",
sub = paste("Integral:", round(con_f(f = f, p = p), 4)))
# Quantile function for projected density
mu <- c(rep(0, p - 1), 1)
F_inv <- F_inv_from_f(f = f, p = p, K = 5e2)
plot(F_inv, xlab = expression(x), ylab = expression(F^{-1}*(x)),
main = paste0("Quantile function, ", type, ", p = ", p))
# Sample from the alternative and plot the projected sample
n <- 5e4
samp <- r_locdev(n = n, mu = mu, f = f, kappa = 1, F_inv = F_inv)
plot(z, f_proj(z), col = 2, type = "l",
main = paste0("Simulated projected data, ", type, ", p = ", p),
ylim = c(0, 1.75))
hist(samp %*% mu, freq = FALSE, breaks = seq(-1, 1, l = 50), add = TRUE)
par(old_par)
}
# \donttest{
## Local alternatives for the PCvM test
loc_alt_diagnostic(p = 2, type = "PCvM")
loc_alt_diagnostic(p = 3, type = "PCvM")
loc_alt_diagnostic(p = 4, type = "PCvM")
loc_alt_diagnostic(p = 5, type = "PCvM")
loc_alt_diagnostic(p = 11, type = "PCvM")
## Local alternatives for the PAD test
loc_alt_diagnostic(p = 2, type = "PAD")
loc_alt_diagnostic(p = 3, type = "PAD")
loc_alt_diagnostic(p = 4, type = "PAD")
loc_alt_diagnostic(p = 5, type = "PAD")
loc_alt_diagnostic(p = 11, type = "PAD")
## Local alternatives for the PRt test
loc_alt_diagnostic(p = 2, type = "PRt")
loc_alt_diagnostic(p = 3, type = "PRt")
loc_alt_diagnostic(p = 4, type = "PRt")
loc_alt_diagnostic(p = 5, type = "PRt")
loc_alt_diagnostic(p = 11, type = "PRt")
# }
Run the code above in your browser using DataLab