u <- read.csv("data/UNRATE.csv")$UNRATE; N <- length(u); du <- c(NA, diff(u)); tt <- 14:N
yy <- du[tt]; Z <- cbind(1, du[tt - 1], du[tt - 2]); qq <- round(u[tt - 1] - u[tt - 13], 1)
TT <- length(yy); G <- sort(unique(qq)); G <- G[G >= quantile(qq, 0.15) & G <= quantile(qq, 0.85)]
s2_tar <- function(y) sapply(G, function(g) { I <- qq <= g
mean(.lm.fit(cbind(Z * I, Z * !I), y)$residuals^2) })
s2 <- s2_tar(yy); LRu <- TT * (s2 - min(s2)) / min(s2)
supF_of <- function(y) { s2l <- mean(.lm.fit(Z, y)$residuals^2); s2u <- min(s2_tar(y))
TT * (s2l - s2u) / s2u }
supF <- supF_of(yy); boot <- replicate(1000, supF_of(rnorm(TT))) # fixed regressors
s2_lstar <- function(g, d) { Gq <- 1 / (1 + exp(-d * (qq - g)))
mean(.lm.fit(cbind(Z, Z * Gq), yy)$residuals^2) }
dgrid <- exp(seq(log(0.5), log(300), length.out = 40)); ggrid <- seq(-0.8, 1.2, by = 0.02)
prof <- sapply(dgrid, function(d) min(sapply(ggrid, s2_lstar, d = d)))
cat("gamma_hat:", G[which.min(s2)], " 95% LR set:", G[LRu <= crit(0.05)], "\n")
cat("sup F:", round(supF, 1), " bootstrap 95% point:", round(quantile(boot, 0.95), 1),
" p-value:", mean(boot >= supF), "\n")
cat("LSTAR best delta:", round(dgrid[which.min(prof)], 1), " s2 LSTAR:", signif(min(prof), 4),
" s2 TAR:", signif(min(s2), 4), "\n")