首页 > 解决方案 > 如何估计 R 中的 Quantile-on-Quantile 回归?

问题描述

我需要使用 Sim 和 Zhou (2015) [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。另外,我不确定如何指定分位数回归...

标签: rquantile-regression

解决方案


推荐阅读