我需要使用Sim and Zhou(2015)提出的分位数分位数(QQ)方法估计模型[Sim,N.,Zhou,H.,2015。石油价格,美国股票收益和分位数之间的依赖性。银行与金融杂志55,1–8]。
我有两个变量X和Y,分别代表增长率。我估计了分位数回归,但没有估计QQ。尝试使用两个软件包:quantreg和quantreg.nonpar。
## Data preparation
data <- read.csv("data.csv", header = TRUE)
data [, 2:3] <- log(data [, 2:3])
# Calclating growth rates
Y <- diff(data[,"Y"])/data[-nrow(data), "Y"]
X <- diff(data[,"X"])/data[-nrow(data), "X"]
data.growth = cbind(Y, X)
## Quantile Regression =======================================
require("quantreg")
fit.rq <- rq(Y ~ X, tau = c(.1, .2, .3, .4, .5, .6, .7, .8, .9))
# Khmaladze test
kt <- KhmaladzeTest(formula = y ~ x, taus = -1)
KhmaladzeFormat(kt, 0.05)
#Goodness of fit
gof.rq <- GOFTest(fit.rq, alpha = 0.05, B = 1000, seed = 123)
gof.rq
# Transformation models
fit.rqt <- tsrq(Y ~ X, tsf = "ao", symm = FALSE, dbounded = FALSE,
conditional = FALSE, tau = c(.1, .2, .3, .4, .5, .6, .7,.8, .9))
fit.rqt; summary (fit.rqt)
# Non parametric
require (quantreg.nonpar)
form.par <- Y ~ X
basis.bsp <- create.bspline.basis(breaks = quantile(X, c(0:10)/10))
n=length (Y)
B <- 500 #500 simulations for the pivotal and Gaussian methods
B.boot <- 100 #00 repetitions for the weighted and gradient bootstrap methods
taus <- c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9)
print.taus <- c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9)
alpha <- 0.05
data.growth = as.data.frame(data.growth)
piv.bsp <- npqr(formula = form.par, data = data.growth, basis = basis.bsp, var = "X", taus = taus, nderivs = 1, average = 1, B = B, alpha = alpha, process="none", rearrange=FALSE, uniform=TRUE, se="conditional", printOutput=TRUE, method="fn") # doesn`t work..
gaus.bsp <- update(piv.bsp, process = "gaussian", printOutput = FALSE)
wboot.bsp <- update(gaus.bsp, process = "wbootstrap", B = B.boot)
gboot.bsp <- update(wboot.bsp, process = "gbootstrap")
# QQR - don`t know... ======================================
分位数回归是通过quantreg
进行估算的,但不适用于quantreg.nonpar
(执行piv.bsp <- npqr(formula = form.par, data = data.growth,...
会导致错误:Error in rq.fit.br(x, y, tau = tau, ...) : Singular design matrix
)。另外,我不确定如何指定分位数上的分位数回归...