# Minimal example: continuous outcome
n <- 25
p <- 5
X <- matrix(rnorm(n * p), ncol = p)
y <- X[, 1] + rnorm(n)
fit1 <- HorseTrees(y = y, X_train = X, outcome_type = "continuous",
number_of_trees = 5, N_post = 75, N_burn = 25,
verbose = FALSE)
# Minimal example: binary outcome
X <- matrix(rnorm(n * p), ncol = p)
y <- ifelse(X[, 1] + rnorm(n) > 0, 1, 0)
fit2 <- HorseTrees(y = y, X_train = X, outcome_type = "binary",
number_of_trees = 5, N_post = 75, N_burn = 25,
verbose = FALSE)
# Minimal example: right-censored outcome
X <- matrix(rnorm(n * p), ncol = p)
time <- rexp(n, rate = 0.1)
status <- rbinom(n, 1, 0.7)
fit3 <- HorseTrees(y = time, status = status, X_train = X,
outcome_type = "right-censored", number_of_trees = 5,
N_post = 75, N_burn = 25, verbose = FALSE)
# Larger continuous example (not run automatically)
# \donttest{
n <- 100
p <- 100
X <- matrix(rnorm(100 * p), ncol = p)
X_test <- matrix(rnorm(50 * p), ncol = p)
y <- X[, 1] + X[, 2] - X[, 3] + rnorm(100, sd = 0.5)
fit4 <- HorseTrees(y = y,
X_train = X,
X_test = X_test,
outcome_type = "continuous",
number_of_trees = 200,
N_post = 2500,
N_burn = 2500,
store_posterior_sample = TRUE,
verbose = TRUE)
plot(fit4$sigma, type = "l", ylab = expression(sigma),
xlab = "Iteration", main = "Sigma traceplot")
hist(fit4$train_predictions_sample[, 1],
main = "Posterior distribution of prediction outcome individual 1",
xlab = "Prediction", breaks = 20)
# }
Run the code above in your browser using DataLab