Running ‘test-graphs-for-known-bounds.R’
  Running ‘testR-interface.R’
Running the tests in ‘tests/test-graphs-for-known-bounds.R’ failed.
Complete output:
  > library(causaloptim)
  Loading required package: igraph
  
  Attaching package: 'igraph'
  
  The following objects are masked from 'package:stats':
  
      decompose, spectrum
  
  The following object is masked from 'package:base':
  
      union
  
  > 
  > 
  > ## simple unconfounded X -> Y
  > 
  > b <- readRDS("test-graphs/simple-unconfounded.RData")
  > eff <- "p{Y(X = 1) = 1} - p{Y(X = 0) = 1}"
  > obj <- analyze_graph(b, constraints = NULL, effectt = eff)
  > bound <- optimize_effect(obj)
  > 
  > all(bound$bounds == c("\nMAX {\np0_0 - p0_1\n}\n\n", "\nMIN {\np0_0 - p0_1\n}\n\n"))
  [1] TRUE
  > 
  > # with new version of optimize_effect:
  > new_version_bound <- optimize_effect_2(obj)
  > all(new_version_bound$bounds == c("\nMAX {\n  p0_0 - p0_1\n}\n", "\nMIN {\n  p0_0 - p0_1\n}\n"))
  [1] TRUE
  > # visual comparison:
  > cat(bound$bounds) # old version output string
  
  MAX {
  p0_0 - p0_1
  }
  
   
  MIN {
  p0_0 - p0_1
  }
  
  > cat(new_version_bound$bounds) # new version output string
  
  MAX {
    p0_0 - p0_1
  }
   
  MIN {
    p0_0 - p0_1
  }
  > 
  > ## simple confounded X -> Y
  > 
  > b <- readRDS("test-graphs/simple-confounded.RData")
  > eff <- "p{Y(X = 1) = 1} - p{Y(X = 0) = 1}"
  > obj <- analyze_graph(b, constraints = NULL, effectt = eff)
  > bound <- optimize_effect(obj)
  > 
  > all(bound$bounds == c("\nMAX {\n- p10_ - p01_\n}\n\n", "\nMIN {\n- p10_ - p01_ + 1\n}\n\n"))
  [1] TRUE
  > 
  > # with new version of optimize_effect:
  > new_version_bound <- optimize_effect_2(obj)
  > all(new_version_bound$bounds == c("\nMAX {\n  -p10_ - p01_\n}\n", "\nMIN {\n  1 - p10_ - p01_\n}\n"))
  [1] TRUE
  > # visual comparison:
  > cat(bound$bounds) # old version output string
  
  MAX {
  - p10_ - p01_
  }
  
   
  MIN {
  - p10_ - p01_ + 1
  }
  
  > cat(new_version_bound$bounds) # new version output string
  
  MAX {
    -p10_ - p01_
  }
   
  MIN {
    1 - p10_ - p01_
  }
  > 
  > ## instrument Z -> X -> Y
  > 
  > b <- readRDS("test-graphs/instrument.RData")
  > eff <- "p{Y(X = 1) = 1} - p{Y(X = 0) = 1}"
  > 
  > obj <- analyze_graph(b, constraints = NULL, effectt = eff)
  > bound <- optimize_effect(obj)
  > 
  > all(bound$bounds == c("\nMAX {\np00_0 - p00_1 + p10_0 - 2 p10_1 - 2 p01_1\n- p00_0 + p00_1 - p10_0 - p01_0\n- p00_0 + p00_1 - 2 p10_0 + p10_1 - 2 p01_0\np00_0 - p00_1 - p10_1 - p01_1\n- p10_0 - p01_0\n- p10_1 - p01_1\np00_0 - p00_1 - p10_0 - p10_1 - p01_0\n- p00_0 + p00_1 - p10_0 - p10_1 - p01_1\n}\n\n", "\nMIN {\n- p00_0 - p10_0 - p10_1 - 2 p01_1 + 2\n- p00_1 - p10_0 - p10_1 - 2 p01_0 + 2\n- p10_0 - p01_1 + 1\np00_1 - 2 p10_0 + p10_1 - p01_0 + 1\n- p10_0 - p01_0 + 1\n- p10_1 - p01_0 + 1\n- p10_1 - p01_1 + 1\np00_0 + p10_0 - 2 p10_1 - p01_1 + 1\n}\n\n" ))
  [1] TRUE
  > 
  > # with new version of optimize_effect:
  > new_version_bound <- optimize_effect_2(obj)
  > all(new_version_bound$bounds == c("\nMAX {\n  p00_0 - p00_1 - p10_1 - p01_1,\n  p00_0 - p00_1 - p10_0 - p10_1 - p01_0,\n  p00_0 - p00_1 + p10_0 - 2p10_1 - 2p01_1,\n  -p10_1 - p01_1,\n  -p10_0 - p01_0,\n  -p00_0 + p00_1 - 2p10_0 + p10_1 - 2p01_0,\n  -p00_0 + p00_1 - p10_0 - p10_1 - p01_1,\n  -p00_0 + p00_1 - p10_0 - p01_0\n}\n", "\nMIN {\n  1 - p10_1 - p01_0,\n  1 + p00_0 + p10_0 - 2p10_1 - p01_1,\n  2 - p00_1 - p10_0 - p10_1 - 2p01_0,\n  1 - p10_1 - p01_1,\n  1 - p10_0 - p01_0,\n  1 + p00_1 - 2p10_0 + p10_1 - p01_0,\n  2 - p00_0 - p10_0 - p10_1 - 2p01_1,\n  1 - p10_0 - p01_1\n}\n"))
  [1] TRUE
  > # visual comparison:
  > cat(bound$bounds) # old version output string
  
  MAX {
  p00_0 - p00_1 + p10_0 - 2 p10_1 - 2 p01_1
  - p00_0 + p00_1 - p10_0 - p01_0
  - p00_0 + p00_1 - 2 p10_0 + p10_1 - 2 p01_0
  p00_0 - p00_1 - p10_1 - p01_1
  - p10_0 - p01_0
  - p10_1 - p01_1
  p00_0 - p00_1 - p10_0 - p10_1 - p01_0
  - p00_0 + p00_1 - p10_0 - p10_1 - p01_1
  }
  
   
  MIN {
  - p00_0 - p10_0 - p10_1 - 2 p01_1 + 2
  - p00_1 - p10_0 - p10_1 - 2 p01_0 + 2
  - p10_0 - p01_1 + 1
  p00_1 - 2 p10_0 + p10_1 - p01_0 + 1
  - p10_0 - p01_0 + 1
  - p10_1 - p01_0 + 1
  - p10_1 - p01_1 + 1
  p00_0 + p10_0 - 2 p10_1 - p01_1 + 1
  }
  
  > cat(new_version_bound$bounds) # new version output string
  
  MAX {
    p00_0 - p00_1 - p10_1 - p01_1,
    p00_0 - p00_1 - p10_0 - p10_1 - p01_0,
    p00_0 - p00_1 + p10_0 - 2p10_1 - 2p01_1,
    -p10_1 - p01_1,
    -p10_0 - p01_0,
    -p00_0 + p00_1 - 2p10_0 + p10_1 - 2p01_0,
    -p00_0 + p00_1 - p10_0 - p10_1 - p01_1,
    -p00_0 + p00_1 - p10_0 - p01_0
  }
   
  MIN {
    1 - p10_1 - p01_0,
    1 + p00_0 + p10_0 - 2p10_1 - p01_1,
    2 - p00_1 - p10_0 - p10_1 - 2p01_0,
    1 - p10_1 - p01_1,
    1 - p10_0 - p01_0,
    1 + p00_1 - 2p10_0 + p10_1 - p01_0,
    2 - p00_0 - p10_0 - p10_1 - 2p01_1,
    1 - p10_0 - p01_1
  }
  > 
  > ## functional version
  > 
  > f1 <- interpret_bounds(new_version_bound$bounds, obj$parameters)
  > f1.new <- interpret_bounds(bound$bounds, obj$parameters)
  > 
  > set.seed(12354)
  > pr1 <- runif(length(obj$parameters))
  > pr1[seq(1, 7, by = 2)] <- pr1[seq(1, 7, by = 2)] / sum(pr1[seq(1, 7, by = 2)])
  > pr1[seq(2, 8, by = 2)] <- pr1[seq(2, 8, by = 2)] / sum(pr1[seq(2, 8, by = 2)])
  > 
  > pr1 <- as.list(pr1)
  > names(pr1) <- obj$parameters
  > all(abs(do.call(f1, pr1) - do.call(f1.new, pr1)) < 1e-6)
  [1] TRUE
  > 
  > ## with monotonocity
  > 
  > mono <- list("X(Z = 1) >= X(Z = 0)")
  > 
  > obj <- analyze_graph(b, constraints = mono, effectt = eff)
  Error in within.list(tmpenv.left, eval(parse(text = iin$leftcond))) : 
    object 'nl' not found
  Calls: analyze_graph -> create_q_matrix -> within -> within.list
  Execution halted