# 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))
c <- rnorm(n, mean(y)*1.2, sd(y)*0.5)
data <- dplyr::tibble(x = x, z = pmin(y,c), delta = as.numeric(y <= c))
# Fit the correct model
model$fit(data, params_init=list(beta=c(1,1), sd=3), inplace = TRUE, loglik = loglik_xzd)
# Print value of test statistic and plot corresponding process
ts <- CondKolmY_RCM$new()
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, loglik = loglik_xzd)
# Print value of test statistic and plot corresponding process
ts2 <- CondKolmY_RCM$new()
ts2$calc_stat(data, model2)
print(ts2)
plot(ts2)
Run the code above in your browser using DataLab