Predict the node id of MrSGUIDE regression tree
predictTree(mrsobj, dataframe, type = "node")
mrsobj | MrSGUIDE object |
---|---|
dataframe | data used for prediction |
type | node id |
A data frame of each object node id and outcome
library(MrSGUIDE) set.seed(1234) N = 200 np = 3 numX <- matrix(rnorm(N * np), N, np) ## numerical features gender <- sample(c('Male', 'Female'), N, replace = TRUE) country <- sample(c('US', 'UK', 'China', 'Japan'), N, replace = TRUE) z <- sample(c(0, 1), N, replace = TRUE) # Binary treatment assignment y1 <- numX[, 1] + 1 * z * (gender == 'Female') + rnorm(N) y2 <- numX[, 2] + 2 * z * (gender == 'Female') + rnorm(N) train <- data.frame(numX, gender, country, z, y1, y2) role <- c(rep('n', 3), 'c', 'c', 'r', 'd', 'd') mrsobj <- MrSFit(dataframe = train, role = role) newX = train[1:10,] predictTree(mrsobj, newX, type='outcome')#> node y1 y2 #> 1 2 -1.2358836 0.57827341 #> 2 2 1.1014766 2.83066375 #> 3 2 1.1103315 0.22108787 #> 4 2 -1.5842757 2.83538876 #> 5 3 0.3856782 0.43281142 #> 6 3 0.4894534 0.73928086 #> 7 2 0.2289624 4.19605585 #> 8 2 0.2577416 3.32595170 #> 9 2 -0.5779279 0.03892756 #> 10 3 -0.8608377 -1.08340771predictTree(mrsobj, newX, type='node')#> [1] 2 2 2 2 3 3 2 2 2 3