% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/gg_partial.R
\name{gg_partial}
\alias{gg_partial}
\title{Split partial dependence data into continuous or categorical datasets}
\usage{
gg_partial(part_dta, nvars = NULL, cat_limit = 10, model = NULL)
}
\arguments{
\item{part_dta}{partial plot data from \code{rfsrc::plot.variable}}

\item{nvars}{how many of the partial plot variables to calculate}

\item{cat_limit}{Categorical features are built when there are fewer than
\code{cat_limit} unique feature values.}

\item{model}{a label name applied to all features. Useful when combining
multiple partial plot objects in figures.}
}
\value{
A named list with two elements:
\describe{
\item{continuous}{data.frame with columns \code{x}, \code{yhat},
\code{name} (and optionally \code{model}) for continuous variables}
\item{categorical}{data.frame with the same columns but with \code{x}
as a factor, for low-cardinality / categorical variables}
}
}
\description{
A partial dependence curve answers a what-if question about a forest: hold
every other predictor at its observed value, sweep one of them across its
range, and watch how the ensemble prediction moves.  Marginalized over the
joint distribution of the other variables, the resulting curve isolates the
average effect of the swept predictor alone.
}
\details{
\code{gg_partial} handles the bookkeeping step after you've already called
\code{rfsrc::plot.variable(partial = TRUE)}: it takes the list that function
returns and separates the variables into two tidy data frames -- one for
continuous predictors (plotted as lines) and one for categorical predictors
(plotted as bar charts).  The split is controlled by \code{cat_limit}:
variables with more unique x-values than this threshold are treated as
continuous; all others are categorical.

If you'd rather skip the \code{plot.variable} step and pass the fitted
forest directly, see \code{\link{gg_partial_rfsrc}}, which calls
\code{partial.rfsrc} for you.
}
\note{
Partial-dependence extraction is \code{randomForestSRC}-only;
there is no \code{randomForest} method (the \code{randomForest} package
provides no comparable partial-dependence interface).
}
\examples{
## Build a small regression forest on the airquality dataset
set.seed(42)
airq <- na.omit(airquality)
rf <- randomForestSRC::rfsrc(Ozone ~ ., data = airq, ntree = 50)

## Compute partial dependence via plot.variable (show.plots = FALSE to
## suppress the base-graphics output, we only want the data)
pv <- randomForestSRC::plot.variable(rf, partial = TRUE,
                                      show.plots = FALSE)

## Split into continuous and categorical data frames
result <- gg_partial(pv)
head(result$continuous)

## Label this model for later comparison with a second forest
result_labelled <- gg_partial(pv, model = "airq_model")
unique(result_labelled$continuous$model)

}
\seealso{
\code{\link{gg_partial_rfsrc}} \code{\link{gg_partialpro}}
}
