1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/scale.R
3\name{step_scale}
4\alias{step_scale}
5\title{Scaling Numeric Data}
6\usage{
7step_scale(
8  recipe,
9  ...,
10  role = NA,
11  trained = FALSE,
12  sds = NULL,
13  factor = 1,
14  na_rm = TRUE,
15  skip = FALSE,
16  id = rand_id("scale")
17)
18}
19\arguments{
20\item{recipe}{A recipe object. The step will be added to the
21sequence of operations for this recipe.}
22
23\item{...}{One or more selector functions to choose variables
24for this step. See \code{\link[=selections]{selections()}} for more details.}
25
26\item{role}{Not used by this step since no new variables are
27created.}
28
29\item{trained}{A logical to indicate if the quantities for
30preprocessing have been estimated.}
31
32\item{sds}{A named numeric vector of standard deviations. This
33is \code{NULL} until computed by \code{\link[=prep.recipe]{prep.recipe()}}.}
34
35\item{factor}{A numeric value of either 1 or 2 that scales the
36numeric inputs by one or two standard deviations. By dividing
37by two standard deviations, the coefficients attached to
38continuous predictors can be interpreted the same way as with
39binary inputs. Defaults to \code{1}. More in reference below.}
40
41\item{na_rm}{A logical value indicating whether \code{NA}
42values should be removed when computing the standard deviation.}
43
44\item{skip}{A logical. Should the step be skipped when the
45recipe is baked by \code{\link[=bake.recipe]{bake.recipe()}}? While all operations are baked
46when \code{\link[=prep.recipe]{prep.recipe()}} is run, some operations may not be able to be
47conducted on new data (e.g. processing the outcome variable(s)).
48Care should be taken when using \code{skip = TRUE} as it may affect
49the computations for subsequent operations.}
50
51\item{id}{A character string that is unique to this step to identify it.}
52}
53\value{
54An updated version of \code{recipe} with the new step added to the
55sequence of any existing operations.
56}
57\description{
58\code{step_scale} creates a \emph{specification} of a recipe
59step that will normalize numeric data to have a standard
60deviation of one.
61}
62\details{
63Scaling data means that the standard deviation of a
64variable is divided out of the data. \code{step_scale} estimates
65the variable standard deviations from the data used in the
66\code{training} argument of \code{prep.recipe}.
67\code{bake.recipe} then applies the scaling to new data sets
68using these standard deviations.
69
70When you \code{\link[=tidy]{tidy()}} this step, a tibble with columns \code{terms} (the
71selectors or variables selected) and \code{value} (the
72standard deviations) is returned.
73}
74\examples{
75library(modeldata)
76data(biomass)
77
78biomass_tr <- biomass[biomass$dataset == "Training",]
79biomass_te <- biomass[biomass$dataset == "Testing",]
80
81rec <- recipe(HHV ~ carbon + hydrogen + oxygen + nitrogen + sulfur,
82              data = biomass_tr)
83
84scaled_trans <- rec \%>\%
85  step_scale(carbon, hydrogen)
86
87scaled_obj <- prep(scaled_trans, training = biomass_tr)
88
89transformed_te <- bake(scaled_obj, biomass_te)
90
91biomass_te[1:10, names(transformed_te)]
92transformed_te
93tidy(scaled_trans, number = 1)
94tidy(scaled_obj, number = 1)
95
96}
97\references{
98Gelman, A. (2007) "Scaling regression inputs by
99dividing by two standard deviations." Unpublished. Source:
100\url{http://www.stat.columbia.edu/~gelman/research/unpublished/standardizing.pdf}.
101}
102\seealso{
103Other normalization steps:
104\code{\link{step_center}()},
105\code{\link{step_normalize}()},
106\code{\link{step_range}()}
107}
108\concept{normalization steps}
109