Skip to content

Commit

Permalink
updated ex
Browse files Browse the repository at this point in the history
  • Loading branch information
borishejblum committed Sep 26, 2023
1 parent 43cd00b commit a0383ae
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
14 changes: 13 additions & 1 deletion R/cit_asymp.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,20 @@
#' @examples
#'
#'X <- as.factor(rbinom(n=100, size = 1, prob = 0.5))
#'Y <- ((X==1)*rnorm(n = 50,0,1)) + ((X==0)*rnorm(n = 50,0.5,1))
#'Y <- ((X==1)*rnorm(n = 100,0,1)) + ((X==0)*rnorm(n = 100,0.5,1))
#'res_asymp <- cit_asymp(Y,data.frame(X=X))
#'
#'
#' Z <- as.factor(rbinom(n=100, size = 1, prob = 0.5))
#' X <- as.numeric(Z)-1 + rnorm(n=100, sd=1)
#' r <- 1000
#' Y <- replicate(r, as.numeric(Z)-1)
#' YY <- (Y==1)*rnorm(n = 100*r,0,1) + (Y==0)*rnorm(n = 100*r,0.5,1)
#'pvals_sim <- pbapply::pbsapply(1:1000, function(i){
#' res_asymp <- cit_asymp(YY[,i],data.frame(X=X), data.frame(Z=Z))
#' return(res_asymp$raw_pval)
#'})
#'hist(pvals_sim)


cit_asymp <- function(Y, X, Z = NULL, space_y = FALSE, number_y = length(unique(Y))){
Expand Down
18 changes: 17 additions & 1 deletion R/cit_multi.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,43 @@
#'
#'@examples
#'
#'
#'Z <- as.factor(rbinom(n=100, size = 1, prob = 0.5))
#'X <- as.numeric(Z)-1 + rnorm(n=100, sd=1)
#'r <- 1000
#'Y <- replicate(r, as.numeric(Z)-1)
#'Y <- (Y==1)*rnorm(n = 100*r,0,1) + (Y==0)*rnorm(n = 100*r,0.5,1)
#'res_asymp_unadj <- cit_multi(M = data.frame(Y=Y),
#' X = data.frame(X1=X1, X2=X2),
#' test="asymptotic", parallel=FALSE)
#'mean(res_asymp_unadj$pvals$raw_pval<0.05)
#'hist(res_asymp_unadj$pvals$raw_pval)
#'
#'set.seed(123)
#'n <- 100
#'r <- 200
#'Z1 <- rnorm(n)
#'Z1 <- rbinom(n, size=1, prob=0.5)
#'Z2 <- rnorm(n)#rbinom(n, size=1, prob=0.5) + rnorm(n, sd=0.05)
#'X1 <- Z2 + rnorm(n, sd=0.2)
#'X2 <- rnorm(n)
#'cor(X1, Z2)
#'Y <- replicate(r, Z2) + rnorm(n*r, 0, 0.5)
#'Y <- replicate(r, as.numeric(Z1)-1)
#'YY <- (Y==1)*rnorm(n = 100*r,0,1) + (Y==0)*rnorm(n = 100*r,0.5,1)
#'range(cor(Y, Z2))
#'range(cor(Y, X2))
#'res_asymp_unadj <- cit_multi(M = data.frame(Y=Y),
#' X = data.frame(X1=X1, X2=X2),
#' test="asymptotic", parallel=FALSE)
#'mean(res_asymp_unadj$pvals$raw_pval<0.05)
#'hist(res_asymp_unadj$pvals$raw_pval)
#'
#'res_asymp_adj <- cit_multi(M = data.frame(Y=Y),
#' X = data.frame(X1=X1, X2=X2),
#' Z = data.frame(Z1=Z1, Z2=Z2),
#' test="asymptotic", parallel=FALSE)
#'mean(res_asymp_adj$pvals$raw_pval<0.05)
#'hist(res_asymp_adj$pvals$raw_pval)
#'
#'if(interactive()){
#'res_perm_unadj <- cit_multi(M = data.frame(Y=Y),
Expand Down
14 changes: 13 additions & 1 deletion man/cit_asymp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion man/cit_multi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a0383ae

Please sign in to comment.