# EXAMPLE WITH EQUAL INCLUSION PROBABILITES AND SUM IN EACH STRATA INTEGER
N <- 100
n <- 10
p <- 4
X <- matrix(rgamma(N*p,4,25),ncol = p)
strata <- rep(1:n,each = N/n)
pik <- rep(n/N,N)
s <- stratifiedcube(X,strata,pik)
t(X/pik)%*%s
t(X/pik)%*%pik
Xcat <- disj(strata)
t(Xcat)%*%s
t(Xcat)%*%pik
# EXAMPLE WITH UNEQUAL INCLUSION PROBABILITES AND SUM IN EACH STRATA INTEGER
N <- 100
n <- 10
X <- cbind(rgamma(N,4,25),rbinom(N,20,0.1),rlnorm(N,9,0.1),runif(N))
colSums(X)
strata <- rbinom(N,10,0.7)
strata <- sampling::cleanstrata(strata)
pik <- as.vector(sampling::inclusionprobastrata(strata,ceiling(table(strata)*0.10)))
EPS = 1e-7
s <- stratifiedcube(X,strata,pik)
test <- stratifiedcube(X,strata,pik,landing = FALSE)
t(X/pik)%*%s
t(X/pik)%*%test
t(X/pik)%*%pik
Xcat <- disj(strata)
t(Xcat)%*%s
t(Xcat)%*%test
t(Xcat)%*%pik
# EXAMPLE WITH UNEQUAL INCLUSION PROBABILITES AND SUM IN EACH STRATA NOT INTEGER
set.seed(3)
N <- 100
n <- 10
X <- cbind(rgamma(N,4,25),rbinom(N,20,0.1),rlnorm(N,9,0.1),runif(N))
strata <- rbinom(N,10,0.7)
strata <- sampling::cleanstrata(strata)
pik <- runif(N)
EPS = 1e-7
tapply(pik,strata,sum)
table(strata)
s <- stratifiedcube(X,strata,pik,landing = TRUE)
test <- stratifiedcube(X,strata,pik,landing = FALSE)
t(X/pik)%*%s
t(X/pik)%*%test
t(X/pik)%*%pik
Xcat <- disj(strata)
t(Xcat)%*%s
t(Xcat)%*%pik
t(Xcat)%*%test
Run the code above in your browser using DataLab