Skip to content

Commit c913f09

Browse files
committed
Deploying to gh-pages from @ 8adb5cc 🚀
1 parent 6a3ef2e commit c913f09

13 files changed

+164
-303
lines changed

dev/articles/Examples.html

Lines changed: 134 additions & 134 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ articles:
55
articles/Examples: Examples.html
66
parsnip: parsnip.html
77
articles/Submodels: Submodels.html
8-
last_built: 2025-01-29T13:11Z
8+
last_built: 2025-01-29T16:53Z
99
urls:
1010
reference: https://parsnip.tidymodels.org/reference
1111
article: https://parsnip.tidymodels.org/articles

dev/reference/contr_one_hot.html

Lines changed: 7 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,8 @@
1-
<!DOCTYPE html>
2-
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>Contrast function for one-hot encodings — contr_one_hot • parsnip</title><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/Source_Sans_Pro-0.4.9/font.css" rel="stylesheet"><link href="../deps/Source_Code_Pro-0.4.9/font.css" rel="stylesheet"><link href="../deps/font-awesome-6.5.2/css/all.min.css" rel="stylesheet"><link href="../deps/font-awesome-6.5.2/css/v4-shims.min.css" rel="stylesheet"><script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="../pkgdown.js"></script><meta property="og:title" content="Contrast function for one-hot encodings — contr_one_hot"><meta name="description" content="This contrast function produces a model matrix with indicator columns for
3-
each level of each factor."><meta property="og:description" content="This contrast function produces a model matrix with indicator columns for
4-
each level of each factor."><meta property="og:image" content="https://parsnip.tidymodels.org/logo.png"><meta name="robots" content="noindex"><script defer data-domain="parsnip.tidymodels.org,all.tidymodels.org" src="https://plausible.io/js/plausible.js"></script></head><body>
5-
<a href="#container" class="visually-hidden-focusable">Skip to content</a>
6-
7-
8-
<nav class="navbar navbar-expand-lg fixed-top bg-none" data-bs-theme="light" aria-label="Site navigation"><div class="container">
9-
10-
<a class="navbar-brand me-2" href="../index.html">parsnip</a>
11-
12-
<small class="nav-text text-danger me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="In-development version">1.2.1.9004</small>
13-
14-
15-
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
16-
<span class="navbar-toggler-icon"></span>
17-
</button>
18-
19-
<div id="navbar" class="collapse navbar-collapse ms-3">
20-
<ul class="navbar-nav me-auto"><li class="nav-item"><a class="nav-link" href="../articles/parsnip.html">Get started</a></li>
21-
<li class="active nav-item"><a class="nav-link" href="../reference/index.html">Reference</a></li>
22-
<li class="nav-item dropdown">
23-
<button class="nav-link dropdown-toggle" type="button" id="dropdown-articles" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true">Articles</button>
24-
<ul class="dropdown-menu" aria-labelledby="dropdown-articles"><li><a class="dropdown-item" href="../articles/Examples.html">Fitting and predicting with parsnip</a></li>
25-
<li><a class="dropdown-item" href="../articles/Submodels.html">Evaluating submodels with the same model object</a></li>
26-
</ul></li>
27-
<li class="nav-item dropdown">
28-
<button class="nav-link dropdown-toggle" type="button" id="dropdown-learn-more" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true">Learn more</button>
29-
<ul class="dropdown-menu" aria-labelledby="dropdown-learn-more"><li><a class="external-link dropdown-item" href="https://www.tidymodels.org/learn/models/parsnip-ranger-glmnet/">Regression modeling</a></li>
30-
<li><a class="external-link dropdown-item" href="https://www.tidymodels.org/learn/models/parsnip-nnet/">Classification modeling</a></li>
31-
<li><a class="external-link dropdown-item" href="https://www.tidymodels.org/learn/develop/models/">Making a parsnip model from scratch</a></li>
32-
</ul></li>
33-
<li class="nav-item"><a class="nav-link" href="../news/index.html">Changelog</a></li>
34-
</ul><ul class="navbar-nav"><li class="nav-item"><form class="form-inline" role="search">
35-
<input class="form-control" type="search" name="search-input" id="search-input" autocomplete="off" aria-label="Search site" placeholder="Search for" data-search-index="../search.json"></form></li>
36-
<li class="nav-item"><a class="external-link nav-link" href="https://github.com/tidymodels/parsnip/" aria-label="GitHub"><span class="fa fab fa-github fa-lg"></span></a></li>
37-
</ul></div>
38-
39-
40-
</div>
41-
</nav><div class="container template-reference-topic" id="container">
42-
<div class="row">
43-
<main id="main" class="col-md-9"><div class="page-header">
44-
<img src="../logo.png" class="logo" alt=""><h1>Contrast function for one-hot encodings</h1>
45-
<small class="dont-index">Source: <a href="https://github.com/tidymodels/parsnip/blob/main/R/contr_one_hot.R" class="external-link"><code>R/contr_one_hot.R</code></a></small>
46-
<div class="d-none name"><code>contr_one_hot.Rd</code></div>
47-
</div>
48-
49-
<div class="ref-description section level2">
50-
<p>This contrast function produces a model matrix with indicator columns for
51-
each level of each factor.</p>
52-
</div>
53-
54-
<div class="section level2">
55-
<h2 id="ref-usage">Usage<a class="anchor" aria-label="anchor" href="#ref-usage"></a></h2>
56-
<div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">contr_one_hot</span><span class="op">(</span><span class="va">n</span>, contrasts <span class="op">=</span> <span class="cn">TRUE</span>, sparse <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span></code></pre></div>
57-
</div>
58-
59-
<div class="section level2">
60-
<h2 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h2>
61-
62-
63-
<dl><dt id="arg-n">n<a class="anchor" aria-label="anchor" href="#arg-n"></a></dt>
64-
<dd><p>A vector of character factor levels (of length &gt;=1) or the number
65-
of unique levels (&gt;= 1).</p></dd>
66-
67-
68-
<dt id="arg-contrasts">contrasts<a class="anchor" aria-label="anchor" href="#arg-contrasts"></a></dt>
69-
<dd><p>This argument is for backwards compatibility and only the
70-
default of <code>TRUE</code> is supported.</p></dd>
71-
72-
73-
<dt id="arg-sparse">sparse<a class="anchor" aria-label="anchor" href="#arg-sparse"></a></dt>
74-
<dd><p>This argument is for backwards compatibility and only the
75-
default of <code>FALSE</code> is supported.</p></dd>
76-
77-
</dl></div>
78-
<div class="section level2">
79-
<h2 id="value">Value<a class="anchor" aria-label="anchor" href="#value"></a></h2>
80-
<p>A diagonal matrix that is <code>n</code>-by-<code>n</code>.</p>
81-
</div>
82-
<div class="section level2">
83-
<h2 id="details">Details<a class="anchor" aria-label="anchor" href="#details"></a></h2>
84-
<p>By default, <code><a href="https://rdrr.io/r/stats/model.matrix.html" class="external-link">model.matrix()</a></code> generates binary indicator variables for
85-
factor predictors. When the formula does not remove an intercept, an
86-
incomplete set of indicators are created; no indicator is made for the
87-
first level of the factor.</p>
88-
<p>For example, <code>species</code> and <code>island</code> both have three levels but
89-
<code><a href="https://rdrr.io/r/stats/model.matrix.html" class="external-link">model.matrix()</a></code> creates two indicator variables for each:</p>
90-
<p></p><div class="sourceCode r"><pre><code><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span></span>
91-
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://modeldata.tidymodels.org" class="external-link">modeldata</a></span><span class="op">)</span></span>
92-
<span><span class="fu"><a href="https://rdrr.io/r/utils/data.html" class="external-link">data</a></span><span class="op">(</span><span class="va">penguins</span><span class="op">)</span></span>
93-
<span></span>
94-
<span><span class="fu"><a href="https://rdrr.io/r/base/levels.html" class="external-link">levels</a></span><span class="op">(</span><span class="va">penguins</span><span class="op">$</span><span class="va">species</span><span class="op">)</span></span></code></pre><p></p></div>
95-
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="do">## [1] "Adelie" "Chinstrap" "Gentoo"</span></span></code></pre><p></p></div>
96-
<p></p><div class="sourceCode r"><pre><code><span><span class="fu"><a href="https://rdrr.io/r/base/levels.html" class="external-link">levels</a></span><span class="op">(</span><span class="va">penguins</span><span class="op">$</span><span class="va">island</span><span class="op">)</span></span></code></pre><p></p></div>
97-
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="do">## [1] "Biscoe" "Dream" "Torgersen"</span></span></code></pre><p></p></div>
98-
<p></p><div class="sourceCode r"><pre><code><span><span class="fu"><a href="https://rdrr.io/r/stats/model.matrix.html" class="external-link">model.matrix</a></span><span class="op">(</span><span class="op">~</span> <span class="va">species</span> <span class="op">+</span> <span class="va">island</span>, data <span class="op">=</span> <span class="va">penguins</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
99-
<span> <span class="fu"><a href="https://rdrr.io/r/base/colnames.html" class="external-link">colnames</a></span><span class="op">(</span><span class="op">)</span></span></code></pre><p></p></div>
100-
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="do">## [1] "(Intercept)" "speciesChinstrap" "speciesGentoo" "islandDream"</span></span>
101-
<span id="cb1-2"><a href="#cb1-2" tabindex="-1"></a><span class="do">## [5] "islandTorgersen"</span></span></code></pre><p></p></div>
102-
<p>For a formula with no intercept, the first factor is expanded to
103-
indicators for <em>all</em> factor levels but all other factors are expanded to
104-
all but one (as above):</p>
105-
<p></p><div class="sourceCode r"><pre><code><span><span class="fu"><a href="https://rdrr.io/r/stats/model.matrix.html" class="external-link">model.matrix</a></span><span class="op">(</span><span class="op">~</span> <span class="fl">0</span> <span class="op">+</span> <span class="va">species</span> <span class="op">+</span> <span class="va">island</span>, data <span class="op">=</span> <span class="va">penguins</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
106-
<span> <span class="fu"><a href="https://rdrr.io/r/base/colnames.html" class="external-link">colnames</a></span><span class="op">(</span><span class="op">)</span></span></code></pre><p></p></div>
107-
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="do">## [1] "speciesAdelie" "speciesChinstrap" "speciesGentoo" "islandDream"</span></span>
108-
<span id="cb1-2"><a href="#cb1-2" tabindex="-1"></a><span class="do">## [5] "islandTorgersen"</span></span></code></pre><p></p></div>
109-
<p>For inference, this hybrid encoding can be problematic.</p>
110-
<p>To generate all indicators, use this contrast:</p>
111-
<p></p><div class="sourceCode r"><pre><code><span><span class="co"># Switch out the contrast method</span></span>
112-
<span><span class="va">old_contr</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/options.html" class="external-link">options</a></span><span class="op">(</span><span class="st">"contrasts"</span><span class="op">)</span><span class="op">$</span><span class="va">contrasts</span></span>
113-
<span><span class="va">new_contr</span> <span class="op">&lt;-</span> <span class="va">old_contr</span></span>
114-
<span><span class="va">new_contr</span><span class="op">[</span><span class="st">"unordered"</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"contr_one_hot"</span></span>
115-
<span><span class="fu"><a href="https://rdrr.io/r/base/options.html" class="external-link">options</a></span><span class="op">(</span>contrasts <span class="op">=</span> <span class="va">new_contr</span><span class="op">)</span></span>
116-
<span></span>
117-
<span><span class="fu"><a href="https://rdrr.io/r/stats/model.matrix.html" class="external-link">model.matrix</a></span><span class="op">(</span><span class="op">~</span> <span class="va">species</span> <span class="op">+</span> <span class="va">island</span>, data <span class="op">=</span> <span class="va">penguins</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
118-
<span> <span class="fu"><a href="https://rdrr.io/r/base/colnames.html" class="external-link">colnames</a></span><span class="op">(</span><span class="op">)</span></span></code></pre><p></p></div>
119-
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="do">## [1] "(Intercept)" "speciesAdelie" "speciesChinstrap" "speciesGentoo"</span></span>
120-
<span id="cb1-2"><a href="#cb1-2" tabindex="-1"></a><span class="do">## [5] "islandBiscoe" "islandDream" "islandTorgersen"</span></span></code></pre><p></p></div>
121-
<p></p><div class="sourceCode r"><pre><code><span><span class="fu"><a href="https://rdrr.io/r/base/options.html" class="external-link">options</a></span><span class="op">(</span>contrasts <span class="op">=</span> <span class="va">old_contr</span><span class="op">)</span></span></code></pre><p></p></div>
122-
<p>Removing the intercept here does not affect the factor encodings.</p>
123-
</div>
124-
125-
</main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>
126-
</nav></aside></div>
127-
128-
129-
</div>
130-
<footer><div class="container">
131-
<div class="pkgdown-footer-left">
132-
<p>Developed by <a href="https://github.com/topepo" class="external-link">Max Kuhn</a>, <a href="https://github.com/DavisVaughan" class="external-link">Davis Vaughan</a>, <a href="https://www.posit.co" class="external-link"><img src="https://www.tidyverse.org/posit-logo.svg" alt="Posit" height="16" width="62" style="margin-bottom: 3px;"></a>.</p>
133-
</div>
134-
135-
<div class="pkgdown-footer-right">
136-
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.1.1.</p>
137-
</div>
138-
139-
</div></footer></body></html>
1+
<html>
2+
<head>
3+
<meta http-equiv="refresh" content="0;URL=https://parsnip.tidymodels.org/dev/reference/reexports.html" />
4+
<meta name="robots" content="noindex">
5+
<link rel="canonical" href="https://parsnip.tidymodels.org/dev/reference/reexports.html">
6+
</head>
7+
</html>
1408

dev/reference/details_linear_reg_glmnet.html

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/reference/details_logistic_reg_glmnet.html

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/reference/details_multinom_reg_glmnet.html

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)