SICM | R Documentation |
This class inherits from TestStatistic and implements a function to calculate the test statistic (and x-y-values that can be used to plot the underlying process).
The process underlying the test statistic is given in Bierens & Wang (2012) \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1017/S0266466611000168")} and defined by
\hat{T}_n^{(s)}(c) = \frac{1}{(2c)^{p+1}} \int_{[-c,c]^p}
\int_{-c}^c \left|\frac{1}{\sqrt{n}} \sum_{j=1}^n \Big(\exp(i \tau Y_j) -
\exp(i \tau \tilde{Y}_j)\Big) \exp(i \xi^T X_j)\right|^2 d\tau d\xi
gofreg::TestStatistic
-> SICM
new()
Initialize an instance of class SICM.
SICM$new( c, transx = function(values) { tvals <- atan(scale(values)) tvals[, apply(values, 2, sd) == 0] <- 0 return(tvals) }, transy = function(values, data) { array(atan(scale(values, center = mean(data$y), scale = sd(data$y)))) } )
c
chosen value for integral boundaries (see Bierens & Wang (2012))
transx
function(values)
used to transform x-values to be
standardized and bounded; default is standardization by subtracting the
mean and dividing by the standard deviation and then applying arctan
transy
function(values, data)
used to transform y-values to be
standardized and bounded (same method is used for simulated y-values);
default is standardization by subtracting the mean and dividing by the
standard deviation and then applying arctan
a new instance of the class
calc_stat()
Calculate the value of the test statistic for given data and a model to test for.
SICM$calc_stat(data, model)
data
data.frame()
with columns x and y containing the data
model
ParamRegrModel to test for
The modified object (self
), allowing for method chaining.
clone()
The objects of this class are cloneable with this method.
SICM$clone(deep = FALSE)
deep
Whether to make a deep clone.
# Create an example dataset
n <- 100
x <- cbind(runif(n), rbinom(n, 1, 0.5))
model <- NormalGLM$new()
y <- model$sample_yx(x, params=list(beta=c(2,3), sd=1))
data <- dplyr::tibble(x = x, y = y)
# Fit the correct model
model$fit(data, params_init=list(beta=c(1,1), sd=3), inplace = TRUE)
# Print value of test statistic and plot corresponding process
ts <- SICM$new(c = 5)
ts$calc_stat(data, model)
print(ts)
plot(ts)
# Fit a wrong model
model2 <- NormalGLM$new(linkinv = function(u) {u+10})
model2$fit(data, params_init=list(beta=c(1,1), sd=3), inplace = TRUE)
# Print value of test statistic and plot corresponding process
ts2 <- SICM$new(c = 5)
ts2$calc_stat(data, model2)
print(ts2)
plot(ts2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.