---
title: "Getting Started"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Getting Started}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
```

`fastgbm` is a compact gradient boosting engine with a compiled (Rcpp +
RcppParallel) backend, covering three task types with one interface:
regression (squared error), binary classification (logistic), and
right-censored survival analysis (Cox, AFT, or piecewise-exponential
objectives), with native missing-value routing throughout. See
`vignette("regression")`, `vignette("classification")`, and
`vignette("survival")` for task-specific examples; this vignette walks
through the survival interface end to end since it has the most moving
parts (baseline hazard, survival-probability prediction).

## Matrix interface

```{r}
library(fastgbm)
library(survival)

lung_dat <- na.omit(lung[, c("time", "status", "age", "sex", "ph.ecog")])
x <- as.matrix(lung_dat[, c("age", "sex", "ph.ecog")])

fit <- fastgbm(
  x,
  time = lung_dat$time,
  status = lung_dat$status,
  objective = "cox",
  ntrees = 100L,
  learning_rate = 0.05,
  max_depth = 3L,
  seed = 1L,
  verbose = FALSE
)
fit
```

## Predictions

```{r}
# Linear predictor (log relative risk)
lp <- predict(fit, x, type = "link")
head(lp)

# Survival probabilities at specific horizons
predict(fit, x[1:5, ], type = "survival", times = c(90, 180, 365))
```

## Formula interface

```{r}
fit2 <- fastgbm(Surv(time, status) ~ age + sex + ph.ecog, data = lung_dat, ntrees = 100L, verbose = FALSE)
```

## Evaluation and importance

```{r}
metrics(fit, y = Surv(lung_dat$time, lung_dat$status))
importance(fit)
```

## Partial dependence

```{r, fig.width = 5, fig.height = 3.5}
pd <- pdp(fit, "age", data = as.data.frame(x), grid_resolution = 15)
plot(pd)
```
