Learn R Programming

SimIndep (version 0.1.2)

wise_test: Conducts the serial independence test (WISE) based on a similarity matrix

Description

Returns the p-value of WISE, the squared test statistic, and related quantities (the chi-square critical value, permutation mean, permutation variance).

Usage

wise_test(sim, dependence = "proximity", alpha = 0.05, weight = NULL, h = 4)

Value

A list containing:

p_value

The p-value of the test.

test_statistic_sq

The value of the squared test statistic.

critical_value

The chi-square critical value at the given significance level.

t

The unstandardized test statistic.

permutation_mean

The mean of t under the permutation null.

permutation_variance

The variance of t under the permutation null.

Arguments

sim

an n by n similarity matrix, typically generated from wise_sim().

dependence

design for the weight matrix W: if "proximity", \(W_{ij} = (1 / (|i - j|^2 + 1))-1\); if "periodicity", then \(W_{ij} = |cos(|i-j|\pi/h)|-1\); If "customized", users should input their self-defined weight matrix through the parameter "weight". The default is "proximity"

alpha

the nominal significance level (default is 0.05).

weight

an n by n weight matrix with zero diagonal (only used if dependence = "customized").

h

the estimated periodicity (default is 4). The parameter is used only if dependence = "periodicity".

Examples

Run this code
library(MASS)
n <- 100
p <- 50

# Example 1: iid data
set.seed(123)
data_iid <- mvrnorm(n = n, mu = rep(0, p) , Sigma = diag(p))
wise_test(
 wise_sim(data_iid, measure = "distance", metric = "manhattan"),
 dependence = "proximity",
 alpha = 0.05
)

# Example 2: AR(1)
set.seed(123)
data_ar <- matrix(0, nrow = n, ncol = p)
error <- mvrnorm(n = n, mu = rep(0,p), Sigma = diag(p))
data_ar[1,] <- error[1,]
phi <- 0.1 * diag(p)
for (t in 2:n) {
  data_ar[t, ] <- phi %*% data_ar[t - 1, ] + error[t,]
}
wise_test(
 wise_sim(data_ar, measure = "distance", metric = "manhattan"),
 dependence = "proximity",
 alpha = 0.05
)

# Example 3: NMA(2)
set.seed(123)
data_nma <- matrix(0, nrow = n, ncol = p)
error <- mvrnorm(n = n, mu = rep(0,p), Sigma = diag(p))
data_nma[1:2, 1:p] <-error[1:2,1:p]
for (i in 3:n) {
  data_nma[i, ] <- error[i,]*error[i-1,]*error[i-2,]
}
wise_test(
 wise_sim(data_nma, measure = "distance", metric = "manhattan"),
 dependence = "proximity",
 alpha = 0.05
)

Run the code above in your browser using DataLab