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.3314"
## [1] "RS"
## [1] "p-value 0.2872"
## [1] "VS"
## [1] "p-value 0.0944"
## [1] "KS"
## [1] "p-value 0.337"
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.6868"
## [1] "RS"
## [1] "p-value 0.8878"
## [1] "VS"
## [1] "p-value 0.498"
## [1] "KS"
## [1] "p-value 0.8652"
rownames(pvmatrix) = c("plug","diff")
colnames(pvmatrix) = c("KPSS","RS","VS","KS")
knitr::kable(pvmatrix,type="latex")
KPSS | RS | VS | KS | |
---|---|---|---|---|
plug | 0.3314 | 0.2872 | 0.0944 | 0.3370 |
diff | 0.6868 | 0.8878 | 0.4980 | 0.8652 |
## % latex table generated in R 4.4.2 by xtable 1.8-4 package
## % Fri Nov 29 08:54:08 2024
## \begin{table}[ht]
## \centering
## \begin{tabular}{rrrrr}
## \hline
## & KPSS & RS & VS & KS \\
## \hline
## plug & 0.331 & 0.287 & 0.094 & 0.337 \\
## diff & 0.687 & 0.888 & 0.498 & 0.865 \\
## \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.4324"
## [1] "RS"
## [1] "p-value 0.4052"
## [1] "VS"
## [1] "p-value 0.1078"
## [1] "KS"
## [1] "p-value 0.56"
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.85 69.15 134.49 225.72 283.47 2114.91
## [1] "p-value 0.4828"
## [1] "RS"
## [1] "gcv 0.193398841583897"
## [1] "m 18 tau_n 0.382134206312301"
## [1] "test statistic: 1067.76713443354"
## [1] "Bootstrap distribution"
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 597.4 1118.9 1332.1 1395.1 1609.6 3395.6
## [1] "p-value 0.8044"
## [1] "VS"
## [1] "gcv 0.193398841583897"
## [1] "m 17 tau_n 0.332134206312301"
## [1] "test statistic: 103.342038019402"
## [1] "Bootstrap distribution"
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 16.81 70.69 109.98 151.99 189.32 1059.14
## [1] "p-value 0.536"
## [1] "KS"
## [1] "gcv 0.193398841583897"
## [1] "m 17 tau_n 0.332134206312301"
## [1] "test statistic: 671.676091515896"
## [1] "Bootstrap distribution"
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 341.5 715.8 923.3 1000.5 1210.7 2932.0
## [1] "p-value 0.8074"
rownames(pvmatrix) = c("plug","diff")
colnames(pvmatrix) = c("KPSS","RS","VS","KS")
knitr::kable(pvmatrix,type="latex")
KPSS | RS | VS | KS | |
---|---|---|---|---|
plug | 0.4324 | 0.4052 | 0.1078 | 0.5600 |
diff | 0.4828 | 0.8044 | 0.5360 | 0.8074 |
## % latex table generated in R 4.4.2 by xtable 1.8-4 package
## % Fri Nov 29 08:54:41 2024
## \begin{table}[ht]
## \centering
## \begin{tabular}{rrrrr}
## \hline
## & KPSS & RS & VS & KS \\
## \hline
## plug & 0.432 & 0.405 & 0.108 & 0.560 \\
## diff & 0.483 & 0.804 & 0.536 & 0.807 \\
## \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.233"
## [1] "RS"
## [1] "p-value 0.1844"
## [1] "VS"
## [1] "p-value 0.1264"
## [1] "KS"
## [1] "p-value 0.273"
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.
## 11.68 102.67 196.68 326.02 409.87 3222.47
## [1] "p-value 0.5664"
## [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.
## 487.8 998.0 1213.0 1271.1 1487.2 3555.3
## [1] "p-value 0.7498"
## [1] "VS"
## [1] "gcv 0.128932561055931"
## [1] "m 18 tau_n 0.332134206312301"
## [1] "test statistic: 78.0587445148257"
## [1] "Bootstrap distribution"
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 26.40 94.77 156.45 208.72 259.30 1743.69
## [1] "p-value 0.8364"
## [1] "KS"
## [1] "gcv 0.128932561055931"
## [1] "m 9 tau_n 0.332134206312301"
## [1] "test statistic: 709.345279801765"
## [1] "Bootstrap distribution"
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 296.3 695.1 903.6 982.6 1202.1 3561.7
## [1] "p-value 0.7346"
rownames(pvmatrix) = c("plug","diff")
colnames(pvmatrix) = c("KPSS","RS","VS","KS")
knitr::kable(pvmatrix,type="latex")
KPSS | RS | VS | KS | |
---|---|---|---|---|
plug | 0.2330 | 0.1844 | 0.1264 | 0.2730 |
diff | 0.5664 | 0.7498 | 0.8364 | 0.7346 |
## % latex table generated in R 4.4.2 by xtable 1.8-4 package
## % Fri Nov 29 08:55:09 2024
## \begin{table}[ht]
## \centering
## \begin{tabular}{rrrrr}
## \hline
## & KPSS & RS & VS & KS \\
## \hline
## plug & 0.233 & 0.184 & 0.126 & 0.273 \\
## diff & 0.566 & 0.750 & 0.836 & 0.735 \\
## \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.364293094094381"
## [1] 10464.35
## V1
## Min. : 1790
## 1st Qu.: 3772
## Median : 4860
## Mean : 5235
## 3rd Qu.: 6315
## Max. :14624
## [1] 0.0154