# under the null
set.seed(1234)
rv <- sr_equality_test(matrix(rnorm(500*5),ncol=5))
# under the alternative (but with identity covariance)
ope <- 253
nyr <- 10
nco <- 5
set.seed(909)
rets <- 0.01 * sapply(seq(0,1.7/sqrt(ope),length.out=nco),
function(mu) { rnorm(ope*nyr,mean=mu,sd=1) })
rv <- sr_equality_test(rets)
# using real data
if (require(xts)) {
data(stock_returns)
pvs <- sr_equality_test(stock_returns)
}
# test for uniformity
pvs <- replicate(1024,{ x <- sr_equality_test(matrix(rnorm(400*5),400,5),type="chisq")
x$p.value })
plot(ecdf(pvs))
abline(0,1,col='red')
# \donttest{
if (require(sandwich)) {
set.seed(as.integer(charToRaw("0b2fd4e9-3bdf-4e3e-9c75-25c6d18c331f")))
n.manifest <- 10
n.latent <- 4
n.day <- 1024
snr <- 0.95
la_A <- matrix(rnorm(n.day*n.latent),ncol=n.latent)
la_B <- matrix(runif(n.latent*n.manifest),ncol=n.manifest)
latent.rets <- la_A %*% la_B
noise.rets <- matrix(rnorm(n.day*n.manifest),ncol=n.manifest)
some.rets <- snr * latent.rets + sqrt(1-snr^2) * noise.rets
# naive vcov
pvs0 <- sr_equality_test(some.rets)
# HAC vcov
pvs1 <- sr_equality_test(some.rets,vcov.func=vcovHAC)
# more elaborately:
pvs <- sr_equality_test(some.rets,vcov.func=function(amod) {
vcovHAC(amod,prewhite=TRUE) })
}
# }
Run the code above in your browser using DataLab