Compute equality test between correlation coefficient estimates at two time points
Source:R/ttest.R
test_equality.Rd
This function tests whether smoothed correlation values at two time points are equal (H0) or not. The test is described page 341 in Choi & Shin (2021).
Arguments
- tcor_obj
the output of a call to
tcor()
withCI = TRUE
.- t1
the first time point used by the test (by default, the first time point in the time series).
- t2
the second time point used by the test (by default, the last time point in the time series).
- test
a character string indicating which test to use ("student", the default; or "chi2").
Value
a data.frame with the result of the test, including the effect size (delta_r = r[t2] - r[t1]
).
Details
Two different test statistics can be used, one is asymptotically Student-t distributed under H0 and one is chi-square distributed. In practice, it seems to give very similar results.
Examples
## Simple example
res <- with(stockprice, tcor(x = SP500, y = FTSE100, t = DateID, h = 50, CI = TRUE))
test_equality(res)
#> The bandwidth stored in `tcor_obj` and used by `test_equality()` has not been automatically selected but was set by the user. Rerun `tcor()` without specifying `h` if you want otherwise.
#> t1 r1 t2 r2 delta_r SE_delta_r T_stat df
#> 1 2000-04-03 0.3484362 2017-12-04 0.5800026 0.2315664 0.1798866 1.287291 8650
#> p
#> 1 0.1980274
## Chi2 instead of Student's t-test
test_equality(res, test = "chi2")
#> The bandwidth stored in `tcor_obj` and used by `test_equality()` has not been automatically selected but was set by the user. Rerun `tcor()` without specifying `h` if you want otherwise.
#> t1 r1 t2 r2 delta_r SE_delta_r chi2_stat df
#> 1 2000-04-03 0.3484362 2017-12-04 0.5800026 0.2315664 0.1798866 1.657118 1
#> p
#> 1 0.1979929
## Time point can be dates or indices (mixing possible) but output as in input data
test_equality(res, t1 = "2000-04-04", t2 = 1000)
#> The bandwidth stored in `tcor_obj` and used by `test_equality()` has not been automatically selected but was set by the user. Rerun `tcor()` without specifying `h` if you want otherwise.
#> t1 r1 t2 r2 delta_r SE_delta_r T_stat
#> 1 2000-04-04 0.3485947 2004-06-04 0.260934 -0.08766079 0.1766849 -0.4961421
#> df p
#> 1 8650 0.6198068
res[1000, "t"] ## t2 matches with date in `res`
#> [1] "2004-06-04"
stockprice[1000, "DateID"] ## t2 does not match with date `stockprice` due to missing values
#> # A tibble: 1 × 1
#> DateID
#> <date>
#> 1 2004-02-02
## It could be useful to use `keep.missing = TRUE` for index to match original data despite NAs
res2 <- with(stockprice, tcor(x = SP500, y = FTSE100, t = DateID,
h = 50, CI = TRUE, keep.missing = TRUE))
test_equality(res2, t1 = "2000-04-04", t2 = 1000)
#> The bandwidth stored in `tcor_obj` and used by `test_equality()` has not been automatically selected but was set by the user. Rerun `tcor()` without specifying `h` if you want otherwise.
#> t1 r1 t2 r2 delta_r SE_delta_r T_stat
#> 1 2000-04-04 0.3485947 2004-02-02 0.06689227 -0.2817025 0.180182 -1.563433
#> df p
#> 1 8650 0.1179874
res[1000, "t"] ## t2 matches with date in `res`
#> [1] "2004-06-04"
stockprice[1000, "DateID"] ## t2 does match with date `stockprice` despite missing values
#> # A tibble: 1 × 1
#> DateID
#> <date>
#> 1 2004-02-02