Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Suppressing causal tree to print in console

I am using the causalTree package. When I launch the causalTree function, something is printed in the console.

library(causalTree)

n <- 1000
p <- 2
y <- rnorm(n)
X <- matrix(rnorm(n * p), ncol = p)
D <- rbinom(n, 1, 0.5)

tree <- causalTree(y ~ ., data = data.frame(y, X), treatment = D, split.Rule = "CT", cv.option = "CT", split.Honest = T, cv.Honest = T, split.Bucket = F, xval = 5, cp = 0, minsize = 20, propensity = 0.5)

# [1] 2
# [1] "CT"

Is there a way to avoid this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Probably the causalTree has multiple print statements. You can prevent this to use invisible(capture.output(...)) like this:

library(causalTree)

n <- 1000
p <- 2
y <- rnorm(n)
X <- matrix(rnorm(n * p), ncol = p)
D <- rbinom(n, 1, 0.5)

invisible(capture.output(tree <- causalTree(y ~ ., data = data.frame(y, X), 
                                           treatment = D, split.Rule = "CT", 
                                           cv.option = "CT", split.Honest = T, 
                                           cv.Honest = T, split.Bucket = F, xval = 5, 
                                           cp = 0, minsize = 20, propensity = 0.5)))

Created on 2022-07-19 by the reprex package (v2.0.1)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading