In this vignette, we will introduce the main functions provided in ortest package, including psi_hat_linear(), psi_hat_sl(), basic_function(),multi_level() and ortest().

psi_hat

In our package, we have two types of basic odds ratio estimation functions. The first one is psi_hat_linear(), using linear model for estimation. The second one is psi_hat_sl(), using super learner method for estimation. The users can assign the model used in super learner and the default models has already been assigned. Cross-fitting is also allowed for psi_hat_sl().

For these two psi_hat estimation method, the user needs to indicate whether the variable is binary or numeric. The following are some examples. The estimation and standard error of odds ratio will be returned.

This is the example of continuous outcome and binary exposure.

L1 <- runif(n,0,1)
L2 <- runif(n,0,1)
L3 <- runif(n,0,1)
L4 <- runif(n,0,1)
L5 <- runif(n,0,1)
L_vec <- tibble(
  L1 = L1,
  L2 = L2,
  L3 = L3,
  L4 = L4,
  L5 = L5)
  L.true <- 2*L1 + L2^2 + L1*L3 + 3*L4 + L1 * L5

Z <- 0.5 + 0.5*L.true
pr <- 1/(1+8*exp(-Z))
summary(pr)
# control the probability close to 0.5
Y.true <- 2*Z + rnorm(n,0,1)
A.true <- rbinom(n,1,pr)
dat <- tibble(
  Y = Y.true,
  A = A.true
) %>% cbind(L_vec)
psi_hat_linear(y = dat$Y,x = dat$A,S = c(), subset = NULL, out_bin = FALSE, exp_bin = TRUE)
psi_hat_linear_int(y = dat$Y,x = dat$A,S = L_vec, subset = NULL, out_bin = FALSE, exp_bin = TRUE,two_way = TRUE,three_way = TRUE)
psi_hat_sl(y = dat$Y,x = dat$A,S = L_vec, subset = NULL, out_bin = FALSE, exp_bin = TRUE, sl=NULL,cross_fitting = FALSE,kfolds=5)
psi_hat_sl(y = dat$Y,x = dat$A,S = L_vec, subset = NULL, out_bin = FALSE, exp_bin = TRUE,sl=NULL,cross_fitting = TRUE, kfolds=5)

This is the example of continuous outcome and continuous exposure.

L1 <- runif(n,0,1)
L2 <- runif(n,0,1)
L3 <- runif(n,0,1)
L4 <- runif(n,0,1)
L5 <- runif(n,0,1)
L_vec <- tibble(
  L1 = L1,
  L2 = L2,
  L3 = L3,
  L4 = L4,
  L5 = L5)
L.true <- 2*L1 + L2^2 + L1*L3 + 3*L4 + L1 * L5
# L.true <- 2*L1 + 3*L2 + 4*L3
Z <- 0.5 + 0.5*L.true
Y.true <- 2*Z + rnorm(n,0,3)
A.true <- 2*Z + rnorm(n,0,3)
dat <- tibble(
  Y = Y.true,
  A = A.true
) %>% cbind(L_vec)

psi_hat_linear(y = dat$Y,x = dat$A,S = c(), subset = NULL, out_bin = FALSE, exp_bin = FALSE)
psi_hat_linear_int(y = dat$Y,x = dat$A,S = L_vec, subset = NULL, out_bin = FALSE, exp_bin = FALSE,two_way = TRUE,three_way = TRUE)
psi_hat_sl(y = dat$Y,x = dat$A,S = L_vec, subset = NULL, out_bin = FALSE, exp_bin = FALSE, sl=NULL,cross_fitting = FALSE,kfolds=5)
psi_hat_sl(y = dat$Y,x = dat$A,S = L_vec, subset = NULL, out_bin = FALSE, exp_bin = FALSE, sl=NULL,cross_fitting = TRUE,kfolds=5)

This is the example of binary outcome and binary exposure.

  L1 <- runif(n,0,1)
  L2 <- runif(n,0,1)
  L3 <- runif(n,0,1)
  L4 <- runif(n,0,1)
  L5 <- runif(n,0,1)
  L_vec <- tibble(
    L1 = L1,
    L2 = L2,
    L3 = L3,
    L4 = L4,
    L5 = L5)
  L.true <- 2*L1 + L2^2 + L1*L3 + 3*L4 + L1 * L5
  Z <- 0.5 + 0.5*L.true
  pr <- 1/(1+8*exp(-Z))
  summary(pr)
  Y.true <- rbinom(n,1,pr)
  A.true <- rbinom(n,1,pr)
  dat <- tibble(
    Y = Y.true,
    A = A.true
  ) %>% cbind(L_vec)

psi_hat_linear(y = dat$Y,x = dat$A,S = c(), subset = NULL, out_bin = TRUE, exp_bin = TRUE)
psi_hat_linear_int(y = dat$Y,x = dat$A,S = L_vec, subset = NULL, out_bin = TRUE, exp_bin = TRUE,two_way = TRUE,three_way = TRUE)
psi_hat_sl(y = dat$Y,x = dat$A,S = L_vec, subset = NULL, out_bin = TRUE, exp_bin = TRUE,sl=NULL,cross_fitting = FALSE,kfolds=5)
psi_hat_sl(y = dat$Y,x = dat$A,S = L_vec, subset = NULL, out_bin = TRUE, exp_bin = TRUE,sl=NULL,cross_fitting = TRUE,kfolds=5)

ortest

ortest() detect whether the variable is binary or numeric. Thus the user only needs to input the x,y and S. It can also be used for multi-level factor. For variables in S is more than 4, the super learner is used or the linear method is applied. Super learner models can be assigned in suffStat or user can use the default models. Cross fitting is only allowed in super learner or the error would be reported. The detail of Super learner is set in suffStat.

Moreover, ortest() also detect multi-level factor. The factor which the levels are more than two and less than five will be considered as multi-level factor. Multi-level factor will be converted dummy variable and multi model will be fit. The p-value based on largest estimation of odds ratio will be used.

ortest() will return the p-value for yx+Sy \sim x+S.

## c to m
ortest(1,5,c(2:4,6:10),list(dat = data,method="linear", sl=NULL,cross_fitting=FALSE,kfolds=5,two_way=FALSE,three_way=FALSE))
ortest(1,5,c(2:4,6:10),list(dat = data,method="sl", sl=NULL,cross_fitting=TRUE,kfolds=5,two_way=FALSE,three_way=FALSE))

## m to b 
ortest(5,2,c(1,3:4,6:10),list(dat = data,method="linear", sl=NULL,cross_fitting=FALSE,kfolds=5,two_way=FALSE,three_way=FALSE))
ortest(5,2,c(1,3:4,6:10),list(dat = data,method="sl", sl=NULL,cross_fitting=TRUE,kfolds=5,two_way=FALSE,three_way=FALSE))

## m to m
ortest(5,6,c(1:4,7:10),list(dat = data,method="linear", sl=NULL,cross_fitting=FALSE,kfolds=5,two_way=FALSE,three_way=FALSE))
ortest(5,6,c(1:4,7:10),list(dat = data,method="sl", sl=NULL,cross_fitting=TRUE,kfolds=5,two_way=FALSE,three_way=FALSE))

ortest() also can be used with pc algorithm

V <- colnames(data)
pc.fit <- pc(suffStat = list(dat = data,method="linear",sl=NULL,cross_fitting=FALSE,kfolds=5,two_way=FALSE,three_way=FALSE),
             indepTest = ortest, ## indep.test: partial correlations
             alpha=0.01, labels = V, verbose = FALSE)
Error encountered:  no sign change found in 1000 iterations 
Error encountered:  no sign change found in 1000 iterations 
Error encountered:  no sign change found in 1000 iterations 
Error encountered:  no sign change found in 1000 iterations 
Error encountered:  no sign change found in 1000 iterations 
Error encountered:  no sign change found in 1000 iterations 
Error encountered:  no sign change found in 1000 iterations 
Error encountered:  no sign change found in 1000 iterations 
PC Plot showing the potential relationship

PC Plot showing the potential relationship