Data analysis in the paper of Bai and Wu (2023b).
Hong Kong circulatory and respiratory data.
library(mlrv)
library(foreach)
library(magrittr)
data(hk_data)
colnames(hk_data) = c("SO2","NO2","Dust","Ozone","Temperature",
"Humidity","num_circu","num_respir","Hospital Admission",
"w1","w2","w3","w4","w5","w6")
n = nrow(hk_data)
t = (1:n)/n
hk = list()
hk$x = as.matrix(cbind(rep(1,n), scale(hk_data[,1:3])))
hk$y = hk_data$`Hospital Admission`
pvmatrix = matrix(nrow=2, ncol=4)
###inistialization
setting = list(B = 5000, gcv = 1, neighbour = 1)
setting$lb = floor(10/7*n^(4/15)) - setting$neighbour
setting$ub = max(floor(25/7*n^(4/15))+ setting$neighbour,
setting$lb+2*setting$neighbour+1)
setting$lrvmethod =0.
i=1
# print(rule_of_thumb(y= hk$y, x = hk$x))
for(type in c("KPSS","RS","VS","KS")){
setting$type = type
print(type)
result_reg = heter_covariate(list(y= hk$y, x = hk$x), setting, mvselect = -2)
print(paste("p-value",result_reg))
pvmatrix[1,i] = result_reg
i = i + 1
}
## [1] "KPSS"
## [1] "p-value 0.312"
## [1] "RS"
## [1] "p-value 0.2952"
## [1] "VS"
## [1] "p-value 0.136"
## [1] "KS"
## [1] "p-value 0.405"
setting$lrvmethod =1
i=1
for(type in c("KPSS","RS","VS","KS"))
{
setting$type = type
print(type)
result_reg = heter_covariate(list(y= hk$y, x = hk$x), setting, mvselect = -2)
print(paste("p-value",result_reg))
pvmatrix[2,i] = result_reg
i = i + 1
}
## [1] "KPSS"
## [1] "p-value 0.5032"
## [1] "RS"
## [1] "p-value 0.91"
## [1] "VS"
## [1] "p-value 0.7324"
## [1] "KS"
## [1] "p-value 0.6394"
rownames(pvmatrix) = c("plug","diff")
colnames(pvmatrix) = c("KPSS","RS","VS","KS")
knitr::kable(pvmatrix,type="latex")
KPSS | RS | VS | KS | |
---|---|---|---|---|
plug | 0.3120 | 0.2952 | 0.1360 | 0.4050 |
diff | 0.5032 | 0.9100 | 0.7324 | 0.6394 |
## % latex table generated in R 4.4.2 by xtable 1.8-4 package
## % Thu Feb 27 07:36:46 2025
## \begin{table}[ht]
## \centering
## \begin{tabular}{rrrrr}
## \hline
## & KPSS & RS & VS & KS \\
## \hline
## plug & 0.312 & 0.295 & 0.136 & 0.405 \\
## diff & 0.503 & 0.910 & 0.732 & 0.639 \\
## \hline
## \end{tabular}
## \end{table}
Using parameter `shift’ to multiply the GCV selected bandwidth by a factor. - Shift = 1.2 with plug-in estimator.
pvmatrix = matrix(nrow=2, ncol=4)
setting$lrvmethod = 0
i=1
for(type in c("KPSS","RS","VS","KS")){
setting$type = type
print(type)
result_reg = heter_covariate(list(y= hk$y, x = hk$x),
setting,
mvselect = -2, shift = 1.2)
print(paste("p-value",result_reg))
pvmatrix[1,i] = result_reg
i = i + 1
}
## [1] "KPSS"
## [1] "p-value 0.4488"
## [1] "RS"
## [1] "p-value 0.3598"
## [1] "VS"
## [1] "p-value 0.1234"
## [1] "KS"
## [1] "p-value 0.5694"
setting$lrvmethod =1
i=1
for(type in c("KPSS","RS","VS","KS"))
{
setting$type = type
print(type)
result_reg = heter_covariate(list(y= hk$y, x = hk$x),
setting,
mvselect = -2, verbose_dist = TRUE, shift = 1.2)
print(paste("p-value",result_reg))
pvmatrix[2,i] = result_reg
i = i + 1
}
## [1] "KPSS"
## [1] "gcv 0.193398841583897"
## [1] "m 8 tau_n 0.382134206312301"
## [1] "test statistic: 141.654657280932"
## [1] "Bootstrap distribution"
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 10.10 69.61 139.66 225.35 294.26 2128.11
## [1] "p-value 0.4946"
## [1] "RS"
## [1] "gcv 0.193398841583897"
## [1] "m 15 tau_n 0.382134206312301"
## [1] "test statistic: 1067.76713443354"
## [1] "Bootstrap distribution"
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 535.3 1016.1 1227.2 1291.8 1497.2 3033.7
## [1] "p-value 0.688"
## [1] "VS"
## [1] "gcv 0.193398841583897"
## [1] "m 18 tau_n 0.382134206312301"
## [1] "test statistic: 103.342038019402"
## [1] "Bootstrap distribution"
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 16.72 76.03 117.69 156.78 194.33 1570.88
## [1] "p-value 0.5774"
## [1] "KS"
## [1] "gcv 0.193398841583897"
## [1] "m 14 tau_n 0.332134206312301"
## [1] "test statistic: 671.676091515896"
## [1] "Bootstrap distribution"
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 297.4 687.9 910.5 979.0 1196.2 2896.3
## [1] "p-value 0.7708"
rownames(pvmatrix) = c("plug","diff")
colnames(pvmatrix) = c("KPSS","RS","VS","KS")
knitr::kable(pvmatrix,type="latex")
KPSS | RS | VS | KS | |
---|---|---|---|---|
plug | 0.4488 | 0.3598 | 0.1234 | 0.5694 |
diff | 0.4946 | 0.6880 | 0.5774 | 0.7708 |
## % latex table generated in R 4.4.2 by xtable 1.8-4 package
## % Thu Feb 27 07:37:21 2025
## \begin{table}[ht]
## \centering
## \begin{tabular}{rrrrr}
## \hline
## & KPSS & RS & VS & KS \\
## \hline
## plug & 0.449 & 0.360 & 0.123 & 0.569 \\
## diff & 0.495 & 0.688 & 0.577 & 0.771 \\
## \hline
## \end{tabular}
## \end{table}
pvmatrix = matrix(nrow=2, ncol=4)
setting$lrvmethod =0
i=1
for(type in c("KPSS","RS","VS","KS")){
setting$type = type
print(type)
result_reg = heter_covariate(list(y= hk$y, x = hk$x),
setting,
mvselect = -2, shift = 0.8)
print(paste("p-value",result_reg))
pvmatrix[1,i] = result_reg
i = i + 1
}
## [1] "KPSS"
## [1] "p-value 0.173"
## [1] "RS"
## [1] "p-value 0.1992"
## [1] "VS"
## [1] "p-value 0.0908"
## [1] "KS"
## [1] "p-value 0.2608"
setting$lrvmethod =1
i=1
for(type in c("KPSS","RS","VS","KS"))
{
setting$type = type
print(type)
result_reg = heter_covariate(list(y= hk$y, x = hk$x),
setting,
mvselect = -2, verbose_dist = TRUE, shift = 0.8)
print(paste("p-value",result_reg))
pvmatrix[2,i] = result_reg
i = i + 1
}
## [1] "KPSS"
## [1] "gcv 0.128932561055931"
## [1] "m 8 tau_n 0.382134206312301"
## [1] "test statistic: 166.543448031108"
## [1] "Bootstrap distribution"
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 16.31 100.54 192.85 323.39 399.68 4463.93
## [1] "p-value 0.5526"
## [1] "RS"
## [1] "gcv 0.128932561055931"
## [1] "m 9 tau_n 0.332134206312301"
## [1] "test statistic: 998.08124125936"
## [1] "Bootstrap distribution"
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 430.5 1007.0 1212.3 1278.1 1485.7 3244.3
## [1] "p-value 0.759"
## [1] "VS"
## [1] "gcv 0.128932561055931"
## [1] "m 9 tau_n 0.332134206312301"
## [1] "test statistic: 78.0587445148257"
## [1] "Bootstrap distribution"
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 9.864 64.254 110.357 157.890 200.452 1718.512
## [1] "p-value 0.6654"
## [1] "KS"
## [1] "gcv 0.128932561055931"
## [1] "m 10 tau_n 0.382134206312301"
## [1] "test statistic: 709.345279801765"
## [1] "Bootstrap distribution"
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 294.1 713.0 928.0 998.9 1215.5 2829.4
## [1] "p-value 0.7558"
rownames(pvmatrix) = c("plug","diff")
colnames(pvmatrix) = c("KPSS","RS","VS","KS")
knitr::kable(pvmatrix,type="latex")
KPSS | RS | VS | KS | |
---|---|---|---|---|
plug | 0.1730 | 0.1992 | 0.0908 | 0.2608 |
diff | 0.5526 | 0.7590 | 0.6654 | 0.7558 |
## % latex table generated in R 4.4.2 by xtable 1.8-4 package
## % Thu Feb 27 07:37:53 2025
## \begin{table}[ht]
## \centering
## \begin{tabular}{rrrrr}
## \hline
## & KPSS & RS & VS & KS \\
## \hline
## plug & 0.173 & 0.199 & 0.091 & 0.261 \\
## diff & 0.553 & 0.759 & 0.665 & 0.756 \\
## \hline
## \end{tabular}
## \end{table}
Test if the coefficient function of “SO2”,“NO2”,“Dust” of the second year is constant.
hk$x = as.matrix(cbind(rep(1,n), (hk_data[,1:3])))
hk$y = hk_data$`Hospital Admission`
setting$type = 0
setting$bw_set = c(0.1, 0.35)
setting$eta = 0.2
setting$lrvmethod = 1
setting$lb = 10
setting$ub = 15
hk1 = list()
hk1$x = hk$x[366:730,]
hk1$y = hk$y[366:730]
p1 <- heter_gradient(hk1, setting, mvselect = -2, verbose = T)
## [1] "m 12 tau_n 0.414293094094381"
## [1] 10464.35
## V1
## Min. : 1405
## 1st Qu.: 3824
## Median : 4853
## Mean : 5203
## 3rd Qu.: 6214
## Max. :14718
## [1] 0.016