9. Experiment on orthogonal Learning#

9.1. Simulation Design 2#

# install.packages("librarian", quiet = T)
librarian::shelf(hdm, quiet = T)

set.seed(1)
B= 100 # trials
Naive = rep(0, B)
Orthogonal = rep(0, B)

for (i in 1:B){
    
  n = 10000
  p = 100
  beta = 1 / (1:p)^2
  gamma =1 / (1:p)^2

  X = matrix(rnorm(n*p), n, p)


  D = X%*%gamma + rnorm(n)/4

  Y = D + X%*%beta + rnorm(n)

  # single selection method

  SX.IDs = which(rlasso(Y~ D+X)$coef[-c(1,2)] !=0)  #select covariates by Lasso


  if (sum(SX.IDs)==0) {Naive[i] = lm(Y~ D)$coef[2]}

  if (sum(SX.IDs)>0) {Naive[i] = lm(Y~ D + X[,SX.IDs])$coef[2]}



  #partialling out

  resY = rlasso(Y~ X, Post=F)$res
  resD = rlasso(D~ X, Post=F)$res
  Orthogonal[i]= lm(resY ~ resD)$coef[2]

}
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)

also installing the dependency ‘BiocManager’



  These packages will be installed:

  'hdm'

  It may take some time.

also installing the dependencies ‘iterators’, ‘foreach’, ‘shape’, ‘Rcpp’, ‘RcppEigen’, ‘glmnet’, ‘checkmate’, ‘Formula’
hist(Orthogonal-1,col=4, freq=F, xlim= c(-2, 2), xlab= "Orhtogonal -True ", main="Orthogonal")
hist(Naive-1, col=2, freq=F, xlim= c(-2,2), xlab= "Naive- True", main = "Naive")
../_images/a7d8503539d9d1460606461c64b8878a0a93c6c61a1a5a155a62ef5f24518ee4.png ../_images/bd406503aeeac69cfa60888807d49b1956241e70efd7e09c66fb4ca47a25656a.png

9.2. Simulation Design 2#

# library(hdm)

set.seed(1)
B= 1000 # trials 
Naive = rep(0, B)
Orthogonal = rep(0, B)

for (i in 1:B){
      
  n =100
  p = 100
  beta = 1/(1:p)^2
  gamma = 1/(1:p)^2

  X = matrix(rnorm(n*p), n, p)
      
      
  D = X%*%gamma + rnorm(n)/4

  Y = D+ X%*%beta + rnorm(n)

  # single selection method

  SX.IDs = which(rlasso(Y~ D+X)$coef[-c(1,2)] !=0)  #select covariates by Lasso


  if (sum(SX.IDs)==0) {Naive[i] = lm(Y~ D)$coef[2]}

  if (sum(SX.IDs)>0) {Naive[i] = lm(Y~ D + X[,SX.IDs])$coef[2]}

  #partialling out

  resY = rlasso(Y~ X, Post=T)$res
  resD = rlasso(D~ X, Post=T)$res
  Orthogonal[i]= lm(resY ~ resD)$coef[2]

}
hist(Orthogonal-1,col=4, freq=F, xlim= c(-2, 2), xlab= "Orhtogonal -True ", main="Orthogonal")
hist(Naive-1, col=2, freq=F, xlim= c(-2,2), xlab= "Naive- True", main = "Naive")
../_images/bd59aaba28c5a85f44879de6517dfa59816614a7061a7575d55fd00b4b056e2a.png ../_images/b4cf5642f4583e98dbe7c52691ff294fe8bdbeb444a38b34e0cca998773b6493.png