####Example 1: mean of a normal with known scale
n <- 20
mu <- 1
set.seed(1)
##contributions obtained from the score function
gr <- rnorm(n, mu) - mu
OBJ.Ib <- Iboot(gradient=gr, B=500, M=500, kB=0.01, alpha=c(0.1, 0.05, 0.01), seed=1)
##critical values for testing H0: mu=1, H1: mu!=1
OBJ.Ib
summary(OBJ.Ib)
#####exceeded number of convex hull condition failures in the outer level (kB=0)
OBJ.Ib <- Iboot(gradient=gr, B=500, M=500, kB=0, alpha=c(0.1, 0.05, 0.01), seed=1)
OBJ.Ib
summary(OBJ.Ib)
####Example 2: example 1 of Lunardon (2013)
n <- 20
q <- 10
##parameter
mu <- 0
sig2 <- 1
rho <- 0.5
theta <- c(mu, sig2, rho)
##function to compute the pairwise score contributions
pscore_theta <- function(theta, data)
{
n <- nrow(data)
q <- ncol(data)
mu <- theta[1]
sig2 <- theta[2]
rho <- theta[3]
A <- matrix(rho, q, q)
diag(A) <- -(q-1)
A <- A/((1-rho^2)*sig2^2)
B <- matrix(-(1+rho^2), q, q)
diag(B) <- 2*rho*(q-1)
B <- B/(sig2*(1-rho^2)^2)
x_dot <- apply(data, 1, sum)
p_mu <- ((q-1)/(sig2*(1+rho)))*(x_dot-q*mu)
p_sig2 <- -0.5*apply(((data-mu) p_rho <- q*(q-1)*rho*0.5/(1-rho^2)-0.5*apply(((data-mu) RES <- cbind(p_mu, p_sig2, p_rho)
colnames(RES) <- c("mu", "sig2", "rho")
RES
}
###data simulation
##correlation matrix
S <- matrix(rho*sig2, q, q)
diag(S) <- sig2
##cholesky
cholS <- chol(S)
##generation from multivariate normal
set.seed(3)
Y <- matrix(rnorm(n*q), n, q)
##compute pairwise score conributions
gr <- pscore_theta(theta, Y)
OBJ.Ib <- Iboot(gradient=gr, B=500, M=500, kB=0.01, alpha=c(0.1, 0.05, 0.01), seed=3)
##critical values for testing H0: theta=(0, 1, 0.5), H1: theta!=(0, 1, 0.5)
OBJ.Ib
summary(OBJ.Ib)
##sampe size too small: convex hull failure at the beginning
n <- 10
set.seed(3)
Y <- matrix(rnorm(n*q), n, q)
##compute pairwise score conributions
gr <- pscore_theta(theta, Y)
OBJ.Ib <- Iboot(gradient=gr, B=500, M=500, kB=0.01, alpha=c(0.1, 0.05, 0.01), seed=3)
OBJ.Ib
summary(OBJ.Ib)
Run the code above in your browser using DataLab