Browse Source

Re-built vignette

tags/0.1.0
Maxime Wack 7 years ago
parent
commit
00d72e4c57
1 changed files with 156 additions and 176 deletions
  1. +156
    -176
      inst/doc/desctable.html

+ 156
- 176
inst/doc/desctable.html View File

@@ -4,7 +4,7 @@

<head>

<meta charset="utf-8" />
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />

@@ -109,42 +109,42 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
<p><strong>desctable</strong> uses and exports the pipe (<code>%&gt;%</code>) operator (from packages <strong>magrittr</strong> and <strong>dplyr</strong> fame), though it is not mandatory to use it.</p>
<p>The single interface to the package is its eponymous <code>desctable</code> function.</p>
<p>When used on a data.frame, it returns a descriptive table:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris <span class="op">%&gt;%</span>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris %&gt;%
<span class="st"> </span>desctable</code></pre></div>
<pre><code>## N Mean/% sd Med IQR
## Sepal.Length 150 NA NA 5.80 1.3
## Sepal.Width 150 3.057333 0.4358663 NA NA
## Petal.Length 150 NA NA 4.35 3.5
## Petal.Width 150 NA NA 1.30 1.5
## Species 150 NA NA NA NA
## Species: setosa 50 33.333333 NA NA NA
## Species: versicolor 50 33.333333 NA NA NA
## Species: virginica 50 33.333333 NA NA NA</code></pre>
<pre><code>## N Mean/% sd Med IQR
## 1 Sepal.Length 150 NA NA 5.80 1.3
## 2 Sepal.Width 150 3.057333 0.4358663 NA NA
## 3 Petal.Length 150 NA NA 4.35 3.5
## 4 Petal.Width 150 NA NA 1.30 1.5
## 5 Species 150 NA NA NA NA
## 6 Species: setosa 50 33.333333 NA NA NA
## 7 Species: versicolor 50 33.333333 NA NA NA
## 8 Species: virginica 50 33.333333 NA NA NA</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">desctable</span>(mtcars)</code></pre></div>
<pre><code>## N Mean sd Med IQR
## mpg 32 20.090625 6.0269481 NA NA
## cyl 32 NA NA 6.000 4.00000
## disp 32 NA NA 196.300 205.17500
## hp 32 NA NA 123.000 83.50000
## drat 32 3.596563 0.5346787 NA NA
## wt 32 NA NA 3.325 1.02875
## qsec 32 17.848750 1.7869432 NA NA
## vs 32 NA NA 0.000 1.00000
## am 32 NA NA 0.000 1.00000
## gear 32 NA NA 4.000 1.00000
## carb 32 NA NA 2.000 2.00000</code></pre>
<pre><code>## N Mean sd Med IQR
## 1 mpg 32 20.090625 6.0269481 NA NA
## 2 cyl 32 NA NA 6.000 4.00000
## 3 disp 32 NA NA 196.300 205.17500
## 4 hp 32 NA NA 123.000 83.50000
## 5 drat 32 3.596563 0.5346787 NA NA
## 6 wt 32 NA NA 3.325 1.02875
## 7 qsec 32 17.848750 1.7869432 NA NA
## 8 vs 32 NA NA 0.000 1.00000
## 9 am 32 NA NA 0.000 1.00000
## 10 gear 32 NA NA 4.000 1.00000
## 11 carb 32 NA NA 2.000 2.00000</code></pre>
<p>As you can see with these two examples, <code>desctable</code> describes every variable, with individual levels for factors. It picks statistical functions depending on the type and distribution of the variables in the data, and applies those statistical functions only on the relevant variables.</p>
</div>
<div id="output" class="section level2">
<h2>Output</h2>
<p>The object produced by <code>desctable</code> is in fact a list of data.frames, with a “desctable” class.<br />
Methods for reduction to a simple dataframe (<code>as.data.frame</code>, automatically used for printing), conversion to markdown (<code>pander</code>), and interactive html output with <strong>DT</strong> (<code>datatable</code>) are provided:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris <span class="op">%&gt;%</span>
<span class="st"> </span>desctable <span class="op">%&gt;%</span>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris %&gt;%
<span class="st"> </span>desctable %&gt;%
<span class="st"> </span>pander</code></pre></div>
<table style="width:65%;">
<table style="width:63%;">
<colgroup>
<col width="23%"></col>
<col width="20%"></col>
<col width="5%"></col>
<col width="12%"></col>
<col width="6%"></col>
@@ -228,11 +228,11 @@ Methods for reduction to a simple dataframe (<code>as.data.frame</code>, automat
</tr>
</tbody>
</table>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mtcars <span class="op">%&gt;%</span>
<span class="st"> </span>desctable <span class="op">%&gt;%</span>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mtcars %&gt;%
<span class="st"> </span>desctable %&gt;%
<span class="st"> </span>datatable</code></pre></div>
<p><div id="htmlwidget-bf5b0cbbc5dcaecf678c" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-bf5b0cbbc5dcaecf678c">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["mpg","cyl","disp","hp","drat","wt","qsec","vs","am","gear","carb"],["32","32","32","32","32","32","32","32","32","32","32"],["20","","","","3.6","","18","","","",""],["6","","","","0.53","","1.8","","","",""],["","6","196","123","","3.3","","0","0","4","2"],["","4","205","84","","1","","1","1","1","2"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th><\/th>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false,"columnDefs":[{"orderable":false,"targets":0}]},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br> You need to load these two packages first (and prior to <strong>desctable</strong> for <strong>DT</strong>) if you want to use them.</p>
<p><div id="htmlwidget-e071d4334f5177c93363" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-e071d4334f5177c93363">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["mpg","cyl","disp","hp","drat","wt","qsec","vs","am","gear","carb"],["32","32","32","32","32","32","32","32","32","32","32"],["20","","","","3.6","","18","","","",""],["6","","","","0.53","","1.8","","","",""],["","6","196","123","","3.3","","0","0","4","2"],["","4","205","84","","1","","1","1","1","2"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th><\/th>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br> You need to load these two packages first (and prior to <strong>desctable</strong> for <strong>DT</strong>) if you want to use them.</p>
<p>Calls to <code>pander</code> and <code>datatable</code> with “regular” dataframes will not be affected by the defaults used in the package, and you can modify these defaults for <strong>desctable</strong> objects.</p>
<p>Subsequent outputs in this vignette section will use <strong>DT</strong>. The <code>datatable</code> wrapper function for desctable objects comes with some default options and formatting such as freezing the row names and table header, export buttons, and rounding of values. Both <code>pander</code> and <code>datatable</code> wrapper take a <em>digits</em> argument to set the number of decimals to show. (<code>pander</code> uses the <em>digits</em>, <em>justify</em> and <em>missing</em> arguments of <code>pandoc.table</code>, whereas <code>datatable</code> calls <code>prettyNum</code> with the <code>digits</code> parameter, and removes <code>NA</code> values. You can set <code>digits = NULL</code> if you want the full table and format it yourself)</p>
</div>
@@ -266,22 +266,22 @@ Methods for reduction to a simple dataframe (<code>as.data.frame</code>, automat
<li>return a named list of statistical functions to use, as defined in the subsequent paragraphs.</li>
</ul>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Strictly equivalent to iris %&gt;% desctable %&gt;% datatable</span>
iris <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">stats =</span> stats_auto) <span class="op">%&gt;%</span>
iris %&gt;%
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">stats =</span> stats_auto) %&gt;%
<span class="st"> </span>datatable</code></pre></div>
<div id="htmlwidget-23a7ae297d869c65b646" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-23a7ae297d869c65b646">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","<b>Species<\/b>","    setosa","    versicolor","    virginica"],["150","150","150","150","150","50","50","50"],["","3.1","","","","33","33","33"],["","0.44","","","","","",""],["5.8","","4.3","1.3","","","",""],["1.3","","3.5","1.5","","","",""]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th><\/th>\n <th>N<\/th>\n <th>Mean/%<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false,"columnDefs":[{"orderable":false,"targets":0}]},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script>
<div id="htmlwidget-ed9ccd6994af6de31c15" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-ed9ccd6994af6de31c15">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","<b>Species<\/b>","    setosa","    versicolor","    virginica"],["150","150","150","150","150","50","50","50"],["","3.1","","","","33","33","33"],["","0.44","","","","","",""],["5.8","","4.3","1.3","","","",""],["1.3","","3.5","1.5","","","",""]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th><\/th>\n <th>N<\/th>\n <th>Mean/%<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script>
</div>
<div id="statistical-functions" class="section level3">
<h3>Statistical functions</h3>
<p>Statistical functions can be any function defined in R that you want to use, such as <code>length</code> or <code>mean</code>.</p>
<p>The only condition is that they return a single numerical value. One exception is when they return a vector of length <code>1 + nlevels(x)</code> when applied to factors, as is needed for the <code>percent</code> function.</p>
<p>As mentionned above, they need to be used inside a named list, such as</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mtcars <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">stats =</span> <span class="kw">list</span>(<span class="st">&quot;N&quot;</span> =<span class="st"> </span>length, <span class="st">&quot;Mean&quot;</span> =<span class="st"> </span>mean, <span class="st">&quot;SD&quot;</span> =<span class="st"> </span>sd)) <span class="op">%&gt;%</span>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mtcars %&gt;%
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">stats =</span> <span class="kw">list</span>(<span class="st">&quot;N&quot;</span> =<span class="st"> </span>length, <span class="st">&quot;Mean&quot;</span> =<span class="st"> </span>mean, <span class="st">&quot;SD&quot;</span> =<span class="st"> </span>sd)) %&gt;%
<span class="st"> </span>datatable</code></pre></div>
<p><div id="htmlwidget-2845bcdde667c848360b" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-2845bcdde667c848360b">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["mpg","cyl","disp","hp","drat","wt","qsec","vs","am","gear","carb"],["32","32","32","32","32","32","32","32","32","32","32"],["20","6.2","231","147","3.6","3.2","18","0.44","0.41","3.7","2.8"],["6","1.8","124","69","0.53","0.98","1.8","0.5","0.5","0.74","1.6"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th><\/th>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>SD<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false,"columnDefs":[{"orderable":false,"targets":0}]},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p><div id="htmlwidget-36daf501e79b4fbc9868" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-36daf501e79b4fbc9868">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["mpg","cyl","disp","hp","drat","wt","qsec","vs","am","gear","carb"],["32","32","32","32","32","32","32","32","32","32","32"],["20","6.2","231","147","3.6","3.2","18","0.44","0.41","3.7","2.8"],["6","1.8","124","69","0.53","0.98","1.8","0.5","0.5","0.74","1.6"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th><\/th>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>SD<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p>The names will be used as column headers in the resulting table, and the functions will be applied safely on the variables (errors return <code>NA</code>, and for factors the function will be used on individual levels).</p>
<p>Several convenience functions are included in this package. For statistical function we have: <code>percent</code>, which prints percentages of levels in a factor, and <code>IQR</code> which re-implements <code>stats::IQR</code> but works better with <code>NA</code> values.</p>
<p>Be aware that <strong>all functions will be used on variables stripped of their <code>NA</code> values!</strong><br />
@@ -290,7 +290,7 @@ This is necessary for most statistical functions to be useful, and makes <strong
<div id="conditional-formulas" class="section level3">
<h3>Conditional formulas</h3>
<p>The general form of these formulas is</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">predicate_function <span class="op">~</span><span class="st"> </span>stat_function_if_TRUE <span class="op">|</span><span class="st"> </span>stat_function_if_FALSE</code></pre></div>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">predicate_function ~<span class="st"> </span>stat_function_if_TRUE |<span class="st"> </span>stat_function_if_FALSE</code></pre></div>
<p>A predicate function is any function returning either <code>TRUE</code> or <code>FALSE</code> when applied on a vector, such as <code>is.factor</code>, <code>is.numeric</code>, and <code>is.logical</code>.<br />
<strong>desctable</strong> provides the <code>is.normal</code> function to test for normality (it is equivalent to <code>length(na.omit(x)) &gt; 30 &amp; shapiro.test(x)$p.value &gt; .1</code>).</p>
<p>The <em>FALSE</em> option can be omitted and <code>NA</code> will be produced if the condition in the predicate is not met.</p>
@@ -299,13 +299,13 @@ For example:</p>
<p><code>is.factor ~ percent | (is.normal ~ mean)</code></p>
<p>will either use <code>percent</code> if the variable is a factor, or <code>mean</code> if and only if the variable is normally distributed.</p>
<p>You can mix “bare” statistical functions and formulas in the list defining the statistics you want to use in your table.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris <span class="op">%&gt;%</span>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris %&gt;%
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">stats =</span> <span class="kw">list</span>(<span class="st">&quot;N&quot;</span> =<span class="st"> </span>length,
<span class="st">&quot;%/Mean&quot;</span> =<span class="st"> </span>is.factor <span class="op">~</span><span class="st"> </span>percent <span class="op">|</span><span class="st"> </span>(is.normal <span class="op">~</span><span class="st"> </span>mean),
<span class="st">&quot;Median&quot;</span> =<span class="st"> </span>is.normal <span class="op">~</span><span class="st"> </span><span class="ot">NA</span> <span class="op">|</span><span class="st"> </span>median)) <span class="op">%&gt;%</span>
<span class="st">&quot;%/Mean&quot;</span> =<span class="st"> </span>is.factor ~<span class="st"> </span>percent |<span class="st"> </span>(is.normal ~<span class="st"> </span>mean),
<span class="st">&quot;Median&quot;</span> =<span class="st"> </span>is.normal ~<span class="st"> </span><span class="ot">NA</span> |<span class="st"> </span>median)) %&gt;%
<span class="st"> </span>datatable</code></pre></div>
<p><div id="htmlwidget-06cc58836cd8cecb2c5c" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-06cc58836cd8cecb2c5c">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","<b>Species<\/b>","    setosa","    versicolor","    virginica"],["150","150","150","150","150","50","50","50"],["","3.1","","","","33","33","33"],["5.8","","4.3","1.3","","","",""]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th><\/th>\n <th>N<\/th>\n <th>%/Mean<\/th>\n <th>Median<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false,"columnDefs":[{"orderable":false,"targets":0}]},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p><div id="htmlwidget-4847720f3215ab6151e1" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-4847720f3215ab6151e1">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","<b>Species<\/b>","    setosa","    versicolor","    virginica"],["150","150","150","150","150","50","50","50"],["","3.1","","","","33","33","33"],["5.8","","4.3","1.3","","","",""]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th><\/th>\n <th>N<\/th>\n <th>%/Mean<\/th>\n <th>Median<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p>For reference, here is the body of the <code>stats_auto</code> function in the package:</p>
<pre><code>## function (data)
## {
@@ -356,12 +356,12 @@ You don’t need to provide labels for all the variables, and extra labels will
<span class="dt">gear =</span> <span class="st">&quot;Number of forward gears&quot;</span>,
<span class="dt">carb =</span> <span class="st">&quot;Number of carburetors&quot;</span>)

mtcars <span class="op">%&gt;%</span>
<span class="st"> </span>dplyr<span class="op">::</span><span class="kw">mutate</span>(<span class="dt">am =</span> <span class="kw">factor</span>(am, <span class="dt">labels =</span> <span class="kw">c</span>(<span class="st">&quot;Automatic&quot;</span>, <span class="st">&quot;Manual&quot;</span>))) <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">labels =</span> mtlabels) <span class="op">%&gt;%</span>
mtcars %&gt;%
<span class="st"> </span>dplyr::<span class="kw">mutate</span>(<span class="dt">am =</span> <span class="kw">factor</span>(am, <span class="dt">labels =</span> <span class="kw">c</span>(<span class="st">&quot;Automatic&quot;</span>, <span class="st">&quot;Manual&quot;</span>))) %&gt;%
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">labels =</span> mtlabels) %&gt;%
<span class="st"> </span>datatable</code></pre></div>
<p><div id="htmlwidget-9a1c731d856e167352e3" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-9a1c731d856e167352e3">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["Miles/(US) gallon","Number of cylinders","Displacement (cu.in.)","Gross horsepower","Rear axle ratio","Weight (1000 lbs)","¼ mile time","V/S","<b>Transmission<\/b>","    Automatic","    Manual","Number of forward gears","Number of carburetors"],["32","32","32","32","32","32","32","32","32","19","13","32","32"],["20","","","","3.6","","18","","","59","41","",""],["6","","","","0.53","","1.8","","","","","",""],["","6","196","123","","3.3","","0","","","","4","2"],["","4","205","84","","1","","1","","","","1","2"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th><\/th>\n <th>N<\/th>\n <th>Mean/%<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false,"columnDefs":[{"orderable":false,"targets":0}]},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p><div id="htmlwidget-74de48bbb9413f270ac6" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-74de48bbb9413f270ac6">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["Miles/(US) gallon","Number of cylinders","Displacement (cu.in.)","Gross horsepower","Rear axle ratio","Weight (1000 lbs)","¼ mile time","V/S","<b>Transmission<\/b>","    Automatic","    Manual","Number of forward gears","Number of carburetors"],["32","32","32","32","32","32","32","32","32","19","13","32","32"],["20","","","","3.6","","18","","","59","41","",""],["6","","","","0.53","","1.8","","","","","",""],["","6","196","123","","3.3","","0","","","","4","2"],["","4","205","84","","1","","1","","","","1","2"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th><\/th>\n <th>N<\/th>\n <th>Mean/%<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<hr />
</div>
</div>
@@ -372,71 +372,51 @@ mtcars <span class="op">%&gt;%</span>
<h2>Simple usage</h2>
<p>Creating a comparative table (between groups defined by a factor) using <code>desctable</code> is as easy as creating a descriptive table.</p>
<p>It uses the well known <code>group_by</code> function from <strong>dplyr</strong>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">group_by</span>(Species) <span class="op">%&gt;%</span>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris %&gt;%
<span class="st"> </span><span class="kw">group_by</span>(Species) %&gt;%
<span class="st"> </span>desctable -&gt;<span class="st"> </span>iris_by_Species

iris_by_Species</code></pre></div>
<pre><code>## Species: setosa (n=50) / N Species: setosa (n=50) / Mean
## Sepal.Length 50 5.006
## Sepal.Width 50 3.428
## Petal.Length 50 NA
## Petal.Width 50 NA
## Species: setosa (n=50) / sd Species: setosa (n=50) / Med
## Sepal.Length 0.3524897 NA
## Sepal.Width 0.3790644 NA
## Petal.Length NA 1.5
## Petal.Width NA 0.2
## Species: setosa (n=50) / IQR Species: versicolor (n=50) / N
## Sepal.Length NA 50
## Sepal.Width NA 50
## Petal.Length 0.175 50
## Petal.Width 0.100 50
## Species: versicolor (n=50) / Mean
## Sepal.Length 5.936
## Sepal.Width 2.770
## Petal.Length 4.260
## Petal.Width NA
## Species: versicolor (n=50) / sd
## Sepal.Length 0.5161711
## Sepal.Width 0.3137983
## Petal.Length 0.4699110
## Petal.Width NA
## Species: versicolor (n=50) / Med
## Sepal.Length NA
## Sepal.Width NA
## Petal.Length NA
## Petal.Width 1.3
## Species: versicolor (n=50) / IQR
## Sepal.Length NA
## Sepal.Width NA
## Petal.Length NA
## Petal.Width 0.3
## Species: virginica (n=50) / N
## Sepal.Length 50
## Sepal.Width 50
## Petal.Length 50
## Petal.Width 50
## Species: virginica (n=50) / Mean
## Sepal.Length 6.588
## Sepal.Width 2.974
## Petal.Length 5.552
## Petal.Width NA
## Species: virginica (n=50) / sd
## Sepal.Length 0.6358796
## Sepal.Width 0.3224966
## Petal.Length 0.5518947
## Petal.Width NA
## Species: virginica (n=50) / Med
## Sepal.Length NA
## Sepal.Width NA
## Petal.Length NA
## Petal.Width 2
## Species: virginica (n=50) / IQR tests / p tests / test
## Sepal.Length NA 8.918734e-22 kruskal.test
## Sepal.Width NA 4.492017e-17 ANOVA
## Petal.Length NA 4.803974e-29 kruskal.test
## Petal.Width 0.5 3.261796e-29 kruskal.test</code></pre>
<pre><code>## Species: setosa (n=50) / N Species: setosa (n=50) / Mean
## 1 Sepal.Length 50 5.006
## 2 Sepal.Width 50 3.428
## 3 Petal.Length 50 NA
## 4 Petal.Width 50 NA
## Species: setosa (n=50) / sd Species: setosa (n=50) / Med
## 1 0.3524897 NA
## 2 0.3790644 NA
## 3 NA 1.5
## 4 NA 0.2
## Species: setosa (n=50) / IQR Species: versicolor (n=50) / N
## 1 NA 50
## 2 NA 50
## 3 0.175 50
## 4 0.100 50
## Species: versicolor (n=50) / Mean Species: versicolor (n=50) / sd
## 1 5.936 0.5161711
## 2 2.770 0.3137983
## 3 4.260 0.4699110
## 4 NA NA
## Species: versicolor (n=50) / Med Species: versicolor (n=50) / IQR
## 1 NA NA
## 2 NA NA
## 3 NA NA
## 4 1.3 0.3
## Species: virginica (n=50) / N Species: virginica (n=50) / Mean
## 1 50 6.588
## 2 50 2.974
## 3 50 5.552
## 4 50 NA
## Species: virginica (n=50) / sd Species: virginica (n=50) / Med
## 1 0.6358796 NA
## 2 0.3224966 NA
## 3 0.5518947 NA
## 4 NA 2
## Species: virginica (n=50) / IQR tests / p tests / test
## 1 NA 8.918734e-22 kruskal.test
## 2 NA 4.492017e-17 ANOVA
## 3 NA 4.803974e-29 kruskal.test
## 4 0.5 3.261796e-29 kruskal.test</code></pre>
<p>The result is a table containing a descriptive subtable for each level of the grouping factor (the statistical functions rules are applied to each subtable independently), with the statistical tests performed, and their p values.</p>
<p>When displayed as a flat dataframe, the grouping header appears in each variable.</p>
<p>You can also see the grouping headers by inspecting the resulting object, which is a deep list of dataframes, each dataframe named after the grouping factor and its levels (with sample size for each).</p>
@@ -468,13 +448,13 @@ iris_by_Species</code></pre></div>
## - attr(*, &quot;class&quot;)= chr &quot;desctable&quot;</code></pre>
<p>You can specify groups based on any variable, not only factors:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># With pander output</span>
mtcars <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">group_by</span>(cyl) <span class="op">%&gt;%</span>
<span class="st"> </span>desctable <span class="op">%&gt;%</span>
mtcars %&gt;%
<span class="st"> </span><span class="kw">group_by</span>(cyl) %&gt;%
<span class="st"> </span>desctable %&gt;%
<span class="st"> </span>pander</code></pre></div>
<table>
<colgroup>
<col width="4%"></col>
<col width="5%"></col>
<col width="13%"></col>
<col width="6%"></col>
<col width="6%"></col>
@@ -489,7 +469,7 @@ mtcars <span class="op">%&gt;%</span>
</colgroup>
<thead>
<tr class="header">
<th> </th>
<th align="left"> </th>
<th align="left">cyl: 4 (n=11)<br />N</th>
<th align="left"><br />Med</th>
<th align="left"><br />IQR</th>
@@ -505,7 +485,7 @@ mtcars <span class="op">%&gt;%</span>
</thead>
<tbody>
<tr class="odd">
<td>mpg</td>
<td align="left">mpg</td>
<td align="left">11</td>
<td align="left">26</td>
<td align="left">7.6</td>
@@ -519,7 +499,7 @@ mtcars <span class="op">%&gt;%</span>
<td align="left">kruskal.test</td>
</tr>
<tr class="even">
<td>disp</td>
<td align="left">disp</td>
<td align="left">11</td>
<td align="left">108</td>
<td align="left">42</td>
@@ -533,7 +513,7 @@ mtcars <span class="op">%&gt;%</span>
<td align="left">kruskal.test</td>
</tr>
<tr class="odd">
<td>hp</td>
<td align="left">hp</td>
<td align="left">11</td>
<td align="left">91</td>
<td align="left">30</td>
@@ -547,7 +527,7 @@ mtcars <span class="op">%&gt;%</span>
<td align="left">kruskal.test</td>
</tr>
<tr class="even">
<td>drat</td>
<td align="left">drat</td>
<td align="left">11</td>
<td align="left">4.1</td>
<td align="left">0.35</td>
@@ -561,7 +541,7 @@ mtcars <span class="op">%&gt;%</span>
<td align="left">kruskal.test</td>
</tr>
<tr class="odd">
<td>wt</td>
<td align="left">wt</td>
<td align="left">11</td>
<td align="left">2.2</td>
<td align="left">0.74</td>
@@ -575,7 +555,7 @@ mtcars <span class="op">%&gt;%</span>
<td align="left">kruskal.test</td>
</tr>
<tr class="even">
<td>qsec</td>
<td align="left">qsec</td>
<td align="left">11</td>
<td align="left">19</td>
<td align="left">1.4</td>
@@ -589,7 +569,7 @@ mtcars <span class="op">%&gt;%</span>
<td align="left">kruskal.test</td>
</tr>
<tr class="odd">
<td>vs</td>
<td align="left">vs</td>
<td align="left">11</td>
<td align="left">1</td>
<td align="left">0</td>
@@ -603,7 +583,7 @@ mtcars <span class="op">%&gt;%</span>
<td align="left">kruskal.test</td>
</tr>
<tr class="even">
<td>am</td>
<td align="left">am</td>
<td align="left">11</td>
<td align="left">1</td>
<td align="left">0.5</td>
@@ -617,7 +597,7 @@ mtcars <span class="op">%&gt;%</span>
<td align="left">kruskal.test</td>
</tr>
<tr class="odd">
<td>gear</td>
<td align="left">gear</td>
<td align="left">11</td>
<td align="left">4</td>
<td align="left">0</td>
@@ -631,7 +611,7 @@ mtcars <span class="op">%&gt;%</span>
<td align="left">kruskal.test</td>
</tr>
<tr class="even">
<td>carb</td>
<td align="left">carb</td>
<td align="left">11</td>
<td align="left">2</td>
<td align="left">1</td>
@@ -648,20 +628,20 @@ mtcars <span class="op">%&gt;%</span>
</table>
<p>Also with conditions:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># With datatable output</span>
iris <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">group_by</span>(Petal.Length <span class="op">&gt;</span><span class="st"> </span><span class="dv">5</span>) <span class="op">%&gt;%</span>
<span class="st"> </span>desctable <span class="op">%&gt;%</span>
iris %&gt;%
<span class="st"> </span><span class="kw">group_by</span>(Petal.Length &gt;<span class="st"> </span><span class="dv">5</span>) %&gt;%
<span class="st"> </span>desctable %&gt;%
<span class="st"> </span>datatable</code></pre></div>
<p><div id="htmlwidget-f9d71a8850e026b57ba5" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-f9d71a8850e026b57ba5">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","<b>Species<\/b>","    setosa","    versicolor","    virginica"],["108","108","108","108","108","50","49","9"],["","3.1","","","","46","45","8.3"],["","0.48","","","","","",""],["5.5","","3.5","1","","","",""],["1","","3","1.2","","","",""],["42","42","42","42","42","0","1","41"],["","","","2.1","","0","2.4","98"],["","","","0.28","","","",""],["6.7","3","5.6","","","","",""],["0.85","0.4","0.67","","","","",""],["1.6e-15","0.69","2.1e-21","1.6e-19","2.5e-26","","",""],["wilcox.test","wilcox.test","wilcox.test","wilcox.test","fisher.test",null,null,null]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th rowspan=\"2\"><\/th>\n <th colspan=\"5\">Petal.Length &gt; 5: FALSE (n=108)<\/th>\n <th colspan=\"5\">Petal.Length &gt; 5: TRUE (n=42)<\/th>\n <th colspan=\"2\">tests<\/th>\n <\/tr>\n <tr>\n <th>N<\/th>\n <th>Mean/%<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Mean/%<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false,"columnDefs":[{"orderable":false,"targets":0}]},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p><div id="htmlwidget-48f9020a3f438d35520a" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-48f9020a3f438d35520a">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","<b>Species<\/b>","    setosa","    versicolor","    virginica"],["108","108","108","108","108","50","49","9"],["","3.1","","","","46","45","8.3"],["","0.48","","","","","",""],["5.5","","3.5","1","","","",""],["1","","3","1.2","","","",""],["42","42","42","42","42","0","1","41"],["","","","2.1","","0","2.4","98"],["","","","0.28","","","",""],["6.7","3","5.6","","","","",""],["0.85","0.4","0.67","","","","",""],["1.6e-15","0.69","2.1e-21","1.6e-19","2.5e-26","","",""],["wilcox.test","wilcox.test","wilcox.test","wilcox.test","fisher.test",null,null,null]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th rowspan=\"2\"><\/th>\n <th colspan=\"5\">Petal.Length &gt; 5: FALSE (n=108)<\/th>\n <th colspan=\"5\">Petal.Length &gt; 5: TRUE (n=42)<\/th>\n <th colspan=\"2\">tests<\/th>\n <\/tr>\n <tr>\n <th>N<\/th>\n <th>Mean/%<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Mean/%<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p>And even on multiple nested groups:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mtcars <span class="op">%&gt;%</span>
<span class="st"> </span>dplyr<span class="op">::</span><span class="kw">mutate</span>(<span class="dt">am =</span> <span class="kw">factor</span>(am, <span class="dt">labels =</span> <span class="kw">c</span>(<span class="st">&quot;Automatic&quot;</span>, <span class="st">&quot;Manual&quot;</span>))) <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">group_by</span>(vs, am, cyl) <span class="op">%&gt;%</span>
<span class="st"> </span>desctable <span class="op">%&gt;%</span>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mtcars %&gt;%
<span class="st"> </span>dplyr::<span class="kw">mutate</span>(<span class="dt">am =</span> <span class="kw">factor</span>(am, <span class="dt">labels =</span> <span class="kw">c</span>(<span class="st">&quot;Automatic&quot;</span>, <span class="st">&quot;Manual&quot;</span>))) %&gt;%
<span class="st"> </span><span class="kw">group_by</span>(vs, am, cyl) %&gt;%
<span class="st"> </span>desctable %&gt;%
<span class="st"> </span>datatable</code></pre></div>
<p><div id="htmlwidget-bb00b5b1ab5e71af5352" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-bb00b5b1ab5e71af5352">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["mpg","disp","hp","drat","wt","qsec","gear","carb"],["12","12","12","12","12","12","12","12"],["15","355","180","3.1","3.8","17","3","3"],["2.6","113","44","0.11","0.81","0.67","0","2"],["","","","","","","",""],["no.test","no.test","no.test","no.test","no.test","no.test","no.test","no.test"],["1","1","1","1","1","1","1","1"],["26","120","91","4.4","2.1","17","5","2"],["0","0","0","0","0","0","0","0"],["3","3","3","3","3","3","3","3"],["21","160","110","3.9","2.8","16","4","4"],["0.65","7.5","32","0.14","0.13","0.76","0.5","1"],["2","2","2","2","2","2","2","2"],["15","326","300","3.9","3.4","15","5","6"],["0.4","25","36","0.34","0.2","0.05","0","2"],["0.11","0.11","0.11","0.33","0.12","0.17","0.29","0.26"],["kruskal.test","kruskal.test","kruskal.test","kruskal.test","kruskal.test","kruskal.test","kruskal.test","kruskal.test"],["3","3","3","3","3","3","3","3"],["23","141","95","3.7","3.1","20","4","2"],["1.5","13","18","0.11","0.36","1.4","0.5","0.5"],["4","4","4","4","4","4","4","4"],["19","196","116","3.5","3.4","19","3.5","2.5"],["1.7","66","14","0.92","0.061","0.89","1","3"],["0.057","0.05","0.05","0.85","0.05","0.23","0.84","0.85"],["wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test"],["7","7","7","7","7","7","7","7"],["30","79","66","4.1","1.9","19","4","1"],["6.3","24","36","0.2","0.53","0.62","0","1"],["","","","","","","",""],["no.test","no.test","no.test","no.test","no.test","no.test","no.test","no.test"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th rowspan=\"4\"><\/th>\n <th colspan=\"16\">vs: 0 (n=18)<\/th>\n <th colspan=\"13\">vs: 1 (n=14)<\/th>\n <\/tr>\n <tr>\n <th colspan=\"5\">am: Automatic (n=12)<\/th>\n <th colspan=\"11\">am: Manual (n=6)<\/th>\n <th colspan=\"8\">am: Automatic (n=7)<\/th>\n <th colspan=\"5\">am: Manual (n=7)<\/th>\n <\/tr>\n <tr>\n <th colspan=\"3\">cyl: 8 (n=12)<\/th>\n <th colspan=\"2\">tests<\/th>\n <th colspan=\"3\">cyl: 4 (n=1)<\/th>\n <th colspan=\"3\">cyl: 6 (n=3)<\/th>\n <th colspan=\"3\">cyl: 8 (n=2)<\/th>\n <th colspan=\"2\">tests<\/th>\n <th colspan=\"3\">cyl: 4 (n=3)<\/th>\n <th colspan=\"3\">cyl: 6 (n=4)<\/th>\n <th colspan=\"2\">tests<\/th>\n <th colspan=\"3\">cyl: 4 (n=7)<\/th>\n <th colspan=\"2\">tests<\/th>\n <\/tr>\n <tr>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false,"columnDefs":[{"orderable":false,"targets":0}]},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p><div id="htmlwidget-73a68c404fec5e2cba0b" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-73a68c404fec5e2cba0b">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["mpg","disp","hp","drat","wt","qsec","gear","carb"],["12","12","12","12","12","12","12","12"],["15","355","180","3.1","3.8","17","3","3"],["2.6","113","44","0.11","0.81","0.67","0","2"],["","","","","","","",""],["no.test","no.test","no.test","no.test","no.test","no.test","no.test","no.test"],["1","1","1","1","1","1","1","1"],["26","120","91","4.4","2.1","17","5","2"],["0","0","0","0","0","0","0","0"],["3","3","3","3","3","3","3","3"],["21","160","110","3.9","2.8","16","4","4"],["0.65","7.5","32","0.14","0.13","0.76","0.5","1"],["2","2","2","2","2","2","2","2"],["15","326","300","3.9","3.4","15","5","6"],["0.4","25","36","0.34","0.2","0.05","0","2"],["0.11","0.11","0.11","0.33","0.12","0.17","0.29","0.26"],["kruskal.test","kruskal.test","kruskal.test","kruskal.test","kruskal.test","kruskal.test","kruskal.test","kruskal.test"],["3","3","3","3","3","3","3","3"],["23","141","95","3.7","3.1","20","4","2"],["1.5","13","18","0.11","0.36","1.4","0.5","0.5"],["4","4","4","4","4","4","4","4"],["19","196","116","3.5","3.4","19","3.5","2.5"],["1.7","66","14","0.92","0.061","0.89","1","3"],["0.057","0.05","0.05","0.85","0.05","0.23","0.84","0.85"],["wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test"],["7","7","7","7","7","7","7","7"],["30","79","66","4.1","1.9","19","4","1"],["6.3","24","36","0.2","0.53","0.62","0","1"],["","","","","","","",""],["no.test","no.test","no.test","no.test","no.test","no.test","no.test","no.test"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th rowspan=\"4\"><\/th>\n <th colspan=\"16\">vs: 0 (n=18)<\/th>\n <th colspan=\"13\">vs: 1 (n=14)<\/th>\n <\/tr>\n <tr>\n <th colspan=\"5\">am: Automatic (n=12)<\/th>\n <th colspan=\"11\">am: Manual (n=6)<\/th>\n <th colspan=\"8\">am: Automatic (n=7)<\/th>\n <th colspan=\"5\">am: Manual (n=7)<\/th>\n <\/tr>\n <tr>\n <th colspan=\"3\">cyl: 8 (n=12)<\/th>\n <th colspan=\"2\">tests<\/th>\n <th colspan=\"3\">cyl: 4 (n=1)<\/th>\n <th colspan=\"3\">cyl: 6 (n=3)<\/th>\n <th colspan=\"3\">cyl: 8 (n=2)<\/th>\n <th colspan=\"2\">tests<\/th>\n <th colspan=\"3\">cyl: 4 (n=3)<\/th>\n <th colspan=\"3\">cyl: 6 (n=4)<\/th>\n <th colspan=\"2\">tests<\/th>\n <th colspan=\"3\">cyl: 4 (n=7)<\/th>\n <th colspan=\"2\">tests<\/th>\n <\/tr>\n <tr>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p>In the case of nested groups (a.k.a. sub-group analysis), statistical tests are performed only between the groups of the deepest grouping level.</p>
<p>Statistical tests are automatically selected depending on the data and the grouping factor.</p>
</div>
@@ -698,12 +678,12 @@ iris <span class="op">%&gt;%</span>
</ul>
<p>This function will be used on every variable and every grouping factor to determine the appropriate test.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Strictly equivalent to iris %&gt;% group_by(Species) %&gt;% desctable %&gt;% datatable</span>
iris <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">group_by</span>(Species) <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">tests =</span> tests_auto) <span class="op">%&gt;%</span>
iris %&gt;%
<span class="st"> </span><span class="kw">group_by</span>(Species) %&gt;%
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">tests =</span> tests_auto) %&gt;%
<span class="st"> </span>datatable</code></pre></div>
<p><div id="htmlwidget-e5a5abf2b46d1348ffd3" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-e5a5abf2b46d1348ffd3">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["Sepal.Length","Sepal.Width","Petal.Length","Petal.Width"],["50","50","50","50"],["5","3.4","",""],["0.35","0.38","",""],["","","1.5","0.2"],["","","0.18","0.1"],["50","50","50","50"],["5.9","2.8","4.3",""],["0.52","0.31","0.47",""],["","","","1.3"],["","","","0.3"],["50","50","50","50"],["6.6","3","5.6",""],["0.64","0.32","0.55",""],["","","","2"],["","","","0.5"],["8.9e-22","4.5e-17","4.8e-29","3.3e-29"],["kruskal.test","ANOVA","kruskal.test","kruskal.test"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th rowspan=\"2\"><\/th>\n <th colspan=\"5\">Species: setosa (n=50)<\/th>\n <th colspan=\"5\">Species: versicolor (n=50)<\/th>\n <th colspan=\"5\">Species: virginica (n=50)<\/th>\n <th colspan=\"2\">tests<\/th>\n <\/tr>\n <tr>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false,"columnDefs":[{"orderable":false,"targets":0}]},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p><div id="htmlwidget-514bd413d644ea2ee198" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-514bd413d644ea2ee198">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["Sepal.Length","Sepal.Width","Petal.Length","Petal.Width"],["50","50","50","50"],["5","3.4","",""],["0.35","0.38","",""],["","","1.5","0.2"],["","","0.18","0.1"],["50","50","50","50"],["5.9","2.8","4.3",""],["0.52","0.31","0.47",""],["","","","1.3"],["","","","0.3"],["50","50","50","50"],["6.6","3","5.6",""],["0.64","0.32","0.55",""],["","","","2"],["","","","0.5"],["8.9e-22","4.5e-17","4.8e-29","3.3e-29"],["kruskal.test","ANOVA","kruskal.test","kruskal.test"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th rowspan=\"2\"><\/th>\n <th colspan=\"5\">Species: setosa (n=50)<\/th>\n <th colspan=\"5\">Species: versicolor (n=50)<\/th>\n <th colspan=\"5\">Species: virginica (n=50)<\/th>\n <th colspan=\"2\">tests<\/th>\n <\/tr>\n <tr>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
</div>
<div id="list-of-statistical-test-functions" class="section level3">
<h3>List of statistical test functions</h3>
@@ -715,21 +695,21 @@ iris <span class="op">%&gt;%</span>
</ul>
<p>You can also provide overrides to use specific tests for specific variables.<br />
This is done using list items named as the variable and containing a single-term formula function.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">group_by</span>(Petal.Length <span class="op">&gt;</span><span class="st"> </span><span class="dv">5</span>) <span class="op">%&gt;%</span>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris %&gt;%
<span class="st"> </span><span class="kw">group_by</span>(Petal.Length &gt;<span class="st"> </span><span class="dv">5</span>) %&gt;%
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">tests =</span> <span class="kw">list</span>(<span class="dt">.auto =</span> tests_auto,
<span class="dt">Species =</span> <span class="op">~</span>chisq.test)) <span class="op">%&gt;%</span>
<span class="dt">Species =</span> ~chisq.test)) %&gt;%
<span class="st"> </span>datatable</code></pre></div>
<p><div id="htmlwidget-1e1d3dad311d69687101" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-1e1d3dad311d69687101">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","<b>Species<\/b>","    setosa","    versicolor","    virginica"],["108","108","108","108","108","50","49","9"],["","3.1","","","","46","45","8.3"],["","0.48","","","","","",""],["5.5","","3.5","1","","","",""],["1","","3","1.2","","","",""],["42","42","42","42","42","0","1","41"],["","","","2.1","","0","2.4","98"],["","","","0.28","","","",""],["6.7","3","5.6","","","","",""],["0.85","0.4","0.67","","","","",""],["1.6e-15","0.69","2.1e-21","1.6e-19","2.7e-24","","",""],["wilcox.test","wilcox.test","wilcox.test","wilcox.test","chisq.test",null,null,null]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th rowspan=\"2\"><\/th>\n <th colspan=\"5\">Petal.Length &gt; 5: FALSE (n=108)<\/th>\n <th colspan=\"5\">Petal.Length &gt; 5: TRUE (n=42)<\/th>\n <th colspan=\"2\">tests<\/th>\n <\/tr>\n <tr>\n <th>N<\/th>\n <th>Mean/%<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Mean/%<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false,"columnDefs":[{"orderable":false,"targets":0}]},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mtcars <span class="op">%&gt;%</span>
<span class="st"> </span>dplyr<span class="op">::</span><span class="kw">mutate</span>(<span class="dt">am =</span> <span class="kw">factor</span>(am, <span class="dt">labels =</span> <span class="kw">c</span>(<span class="st">&quot;Automatic&quot;</span>, <span class="st">&quot;Manual&quot;</span>))) <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">group_by</span>(am) <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">tests =</span> <span class="kw">list</span>(<span class="dt">.default =</span> <span class="op">~</span>wilcox.test,
<span class="dt">mpg =</span> <span class="op">~</span>t.test)) <span class="op">%&gt;%</span>
<p><div id="htmlwidget-a12f61ce87699ba7a70b" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-a12f61ce87699ba7a70b">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","<b>Species<\/b>","    setosa","    versicolor","    virginica"],["108","108","108","108","108","50","49","9"],["","3.1","","","","46","45","8.3"],["","0.48","","","","","",""],["5.5","","3.5","1","","","",""],["1","","3","1.2","","","",""],["42","42","42","42","42","0","1","41"],["","","","2.1","","0","2.4","98"],["","","","0.28","","","",""],["6.7","3","5.6","","","","",""],["0.85","0.4","0.67","","","","",""],["1.6e-15","0.69","2.1e-21","1.6e-19","2.7e-24","","",""],["wilcox.test","wilcox.test","wilcox.test","wilcox.test","chisq.test",null,null,null]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th rowspan=\"2\"><\/th>\n <th colspan=\"5\">Petal.Length &gt; 5: FALSE (n=108)<\/th>\n <th colspan=\"5\">Petal.Length &gt; 5: TRUE (n=42)<\/th>\n <th colspan=\"2\">tests<\/th>\n <\/tr>\n <tr>\n <th>N<\/th>\n <th>Mean/%<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Mean/%<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mtcars %&gt;%
<span class="st"> </span>dplyr::<span class="kw">mutate</span>(<span class="dt">am =</span> <span class="kw">factor</span>(am, <span class="dt">labels =</span> <span class="kw">c</span>(<span class="st">&quot;Automatic&quot;</span>, <span class="st">&quot;Manual&quot;</span>))) %&gt;%
<span class="st"> </span><span class="kw">group_by</span>(am) %&gt;%
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">tests =</span> <span class="kw">list</span>(<span class="dt">.default =</span> ~wilcox.test,
<span class="dt">mpg =</span> ~t.test)) %&gt;%
<span class="st"> </span>datatable</code></pre></div>
<p><div id="htmlwidget-a5d94aa6021c0cfca4e9" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-a5d94aa6021c0cfca4e9">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["mpg","cyl","disp","hp","drat","wt","qsec","vs","gear","carb"],["19","19","19","19","19","19","19","19","19","19"],["17","8","276","175","3.1","3.5","18","0","3","3"],["4.2","2","164","76","0.63","0.41","2","1","0","2"],["13","13","13","13","13","13","13","13","13","13"],["23","4","120","109","4.1","2.3","17","1","4","2"],["9.4","2","81","47","0.37","0.84","2.1","1","1","3"],["0.0014","0.0039","0.00055","0.046","0.00014","4.3e-05","0.27","0.36","7.6e-06","0.74"],["t.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th rowspan=\"2\"><\/th>\n <th colspan=\"3\">am: Automatic (n=19)<\/th>\n <th colspan=\"3\">am: Manual (n=13)<\/th>\n <th colspan=\"2\">tests<\/th>\n <\/tr>\n <tr>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false,"columnDefs":[{"orderable":false,"targets":0}]},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p><div id="htmlwidget-455afe88c751413b0494" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-455afe88c751413b0494">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["mpg","cyl","disp","hp","drat","wt","qsec","vs","gear","carb"],["19","19","19","19","19","19","19","19","19","19"],["17","8","276","175","3.1","3.5","18","0","3","3"],["4.2","2","164","76","0.63","0.41","2","1","0","2"],["13","13","13","13","13","13","13","13","13","13"],["23","4","120","109","4.1","2.3","17","1","4","2"],["9.4","2","81","47","0.37","0.84","2.1","1","1","3"],["0.0014","0.0039","0.00055","0.046","0.00014","4.3e-05","0.27","0.36","7.6e-06","0.74"],["t.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th rowspan=\"2\"><\/th>\n <th colspan=\"3\">am: Automatic (n=19)<\/th>\n <th colspan=\"3\">am: Manual (n=13)<\/th>\n <th colspan=\"2\">tests<\/th>\n <\/tr>\n <tr>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p>You might wonder why the formula expression. That is needed to capture the test name, and to provide it in the resulting table.</p>
<p>As with statistical functions, any statistical test function defined in R can be used.</p>
<p>The conditions are that the function</p>
@@ -744,37 +724,37 @@ This is done using list items named as the variable and containing a single-term
<div id="tips-and-tricks" class="section level1">
<h1>Tips and tricks</h1>
<p>In the <em>stats</em> argument, you can not only feed function names, but even arbitrary function definitions, functional sequences (a feature provided with the pipe (<code>%&gt;%</code>)), or partial applications (with the <strong>purrr</strong> package):</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mtcars <span class="op">%&gt;%</span>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">mtcars %&gt;%
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">stats =</span> <span class="kw">list</span>(<span class="st">&quot;N&quot;</span> =<span class="st"> </span>length,
<span class="st">&quot;Sum of squares&quot;</span> =<span class="st"> </span><span class="cf">function</span>(x) <span class="kw">sum</span>(x<span class="op">^</span><span class="dv">2</span>),
<span class="st">&quot;Q1&quot;</span> =<span class="st"> </span>. <span class="op">%&gt;%</span><span class="st"> </span><span class="kw">quantile</span>(<span class="dt">prob =</span> .<span class="dv">25</span>),
<span class="st">&quot;Q3&quot;</span> =<span class="st"> </span>purrr<span class="op">::</span><span class="kw">partial</span>(quantile, <span class="dt">probs =</span> .<span class="dv">75</span>))) <span class="op">%&gt;%</span>
<span class="st">&quot;Sum of squares&quot;</span> =<span class="st"> </span>function(x) <span class="kw">sum</span>(x^<span class="dv">2</span>),
<span class="st">&quot;Q1&quot;</span> =<span class="st"> </span>. %&gt;%<span class="st"> </span><span class="kw">quantile</span>(<span class="dt">prob =</span> .<span class="dv">25</span>),
<span class="st">&quot;Q3&quot;</span> =<span class="st"> </span>purrr::<span class="kw">partial</span>(quantile, <span class="dt">probs =</span> .<span class="dv">75</span>))) %&gt;%
<span class="st"> </span>datatable</code></pre></div>
<p><div id="htmlwidget-1c195140acc77e5a180b" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-1c195140acc77e5a180b">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["mpg","cyl","disp","hp","drat","wt","qsec","vs","am","gear","carb"],["32","32","32","32","32","32","32","32","32","32","32"],["14042","1324","2179627","834278","423","361","10293","14","13","452","334"],["15","4","121","96","3.1","2.6","17","0","0","3","2"],["23","8","326","180","3.9","3.6","19","1","1","4","4"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th><\/th>\n <th>N<\/th>\n <th>Sum of squares<\/th>\n <th>Q1<\/th>\n <th>Q3<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false,"columnDefs":[{"orderable":false,"targets":0}]},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p><div id="htmlwidget-6819d85dbb7b9d227cbb" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-6819d85dbb7b9d227cbb">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["mpg","cyl","disp","hp","drat","wt","qsec","vs","am","gear","carb"],["32","32","32","32","32","32","32","32","32","32","32"],["14042","1324","2179627","834278","423","361","10293","14","13","452","334"],["15","4","121","96","3.1","2.6","17","0","0","3","2"],["23","8","326","180","3.9","3.6","19","1","1","4","4"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th><\/th>\n <th>N<\/th>\n <th>Sum of squares<\/th>\n <th>Q1<\/th>\n <th>Q3<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p>In the <em>tests</em> arguments, you can also provide function definitions, functional sequences, and partial applications in the formulas:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">group_by</span>(Species) <span class="op">%&gt;%</span>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris %&gt;%
<span class="st"> </span><span class="kw">group_by</span>(Species) %&gt;%
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">tests =</span> <span class="kw">list</span>(<span class="dt">.auto =</span> tests_auto,
<span class="dt">Sepal.Width =</span> <span class="op">~</span><span class="cf">function</span>(f) <span class="kw">oneway.test</span>(f, <span class="dt">var.equal =</span> F),
<span class="dt">Petal.Length =</span> <span class="op">~</span>. <span class="op">%&gt;%</span><span class="st"> </span><span class="kw">oneway.test</span>(<span class="dt">var.equal =</span> T),
<span class="dt">Sepal.Length =</span> <span class="op">~</span>purrr<span class="op">::</span><span class="kw">partial</span>(oneway.test, <span class="dt">var.equal =</span> T))) <span class="op">%&gt;%</span>
<span class="dt">Sepal.Width =</span> ~function(f) <span class="kw">oneway.test</span>(f, <span class="dt">var.equal =</span> F),
<span class="dt">Petal.Length =</span> ~. %&gt;%<span class="st"> </span><span class="kw">oneway.test</span>(<span class="dt">var.equal =</span> T),
<span class="dt">Sepal.Length =</span> ~purrr::<span class="kw">partial</span>(oneway.test, <span class="dt">var.equal =</span> T))) %&gt;%
<span class="st"> </span>datatable</code></pre></div>
<p><div id="htmlwidget-28d194f20a0390abe749" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-28d194f20a0390abe749">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["Sepal.Length","Sepal.Width","Petal.Length","Petal.Width"],["50","50","50","50"],["5","3.4","",""],["0.35","0.38","",""],["","","1.5","0.2"],["","","0.18","0.1"],["50","50","50","50"],["5.9","2.8","4.3",""],["0.52","0.31","0.47",""],["","","","1.3"],["","","","0.3"],["50","50","50","50"],["6.6","3","5.6",""],["0.64","0.32","0.55",""],["","","","2"],["","","","0.5"],["1.7e-31","1.4e-14","2.9e-91","3.3e-29"],["purrr::partial(oneway.test, var.equal = T)","function(f) oneway.test(f, var.equal = F)",". %>% oneway.test(var.equal = T)","kruskal.test"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th rowspan=\"2\"><\/th>\n <th colspan=\"5\">Species: setosa (n=50)<\/th>\n <th colspan=\"5\">Species: versicolor (n=50)<\/th>\n <th colspan=\"5\">Species: virginica (n=50)<\/th>\n <th colspan=\"2\">tests<\/th>\n <\/tr>\n <tr>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false,"columnDefs":[{"orderable":false,"targets":0}]},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p><div id="htmlwidget-e3defc5823a71460f0ee" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-e3defc5823a71460f0ee">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["Sepal.Length","Sepal.Width","Petal.Length","Petal.Width"],["50","50","50","50"],["5","3.4","",""],["0.35","0.38","",""],["","","1.5","0.2"],["","","0.18","0.1"],["50","50","50","50"],["5.9","2.8","4.3",""],["0.52","0.31","0.47",""],["","","","1.3"],["","","","0.3"],["50","50","50","50"],["6.6","3","5.6",""],["0.64","0.32","0.55",""],["","","","2"],["","","","0.5"],["1.7e-31","1.4e-14","2.9e-91","3.3e-29"],["purrr::partial(oneway.test, var.equal = T)","function(f) oneway.test(f, var.equal = F)",". %>% oneway.test(var.equal = T)","kruskal.test"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th rowspan=\"2\"><\/th>\n <th colspan=\"5\">Species: setosa (n=50)<\/th>\n <th colspan=\"5\">Species: versicolor (n=50)<\/th>\n <th colspan=\"5\">Species: virginica (n=50)<\/th>\n <th colspan=\"2\">tests<\/th>\n <\/tr>\n <tr>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Mean<\/th>\n <th>sd<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script> <br></p>
<p>This allows you to modulate the behavior of <code>desctable</code> in every detail, such as using paired tests, or non <em>htest</em> tests.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># This is a contrived example, which would be better solved with a dedicated function</span>
<span class="kw">library</span>(survival)

bladder<span class="op">$</span>surv &lt;-<span class="st"> </span><span class="kw">Surv</span>(bladder<span class="op">$</span>stop, bladder<span class="op">$</span>event)
bladder$surv &lt;-<span class="st"> </span><span class="kw">Surv</span>(bladder$stop, bladder$event)

bladder <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">group_by</span>(rx) <span class="op">%&gt;%</span>
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">tests =</span> <span class="kw">list</span>(<span class="dt">.default =</span> <span class="op">~</span>wilcox.test,
<span class="dt">surv =</span> <span class="op">~</span>. <span class="op">%&gt;%</span><span class="st"> </span>survdiff <span class="op">%&gt;%</span><span class="st"> </span>.<span class="op">$</span>chisq <span class="op">%&gt;%</span><span class="st"> </span><span class="kw">pchisq</span>(<span class="dv">1</span>, <span class="dt">lower.tail =</span> F) <span class="op">%&gt;%</span><span class="st"> </span><span class="kw">list</span>(<span class="dt">p.value =</span> .))) <span class="op">%&gt;%</span>
bladder %&gt;%
<span class="st"> </span><span class="kw">group_by</span>(rx) %&gt;%
<span class="st"> </span><span class="kw">desctable</span>(<span class="dt">tests =</span> <span class="kw">list</span>(<span class="dt">.default =</span> ~wilcox.test,
<span class="dt">surv =</span> ~. %&gt;%<span class="st"> </span>survdiff %&gt;%<span class="st"> </span>.$chisq %&gt;%<span class="st"> </span><span class="kw">pchisq</span>(<span class="dv">1</span>, <span class="dt">lower.tail =</span> F) %&gt;%<span class="st"> </span><span class="kw">list</span>(<span class="dt">p.value =</span> .))) %&gt;%
<span class="st"> </span>datatable</code></pre></div>
<div id="htmlwidget-8cb538454a2c895f0227" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-8cb538454a2c895f0227">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["id","number","size","stop","event","enum","surv"],["188","188","188","188","188","188","376"],["24","1","1","23","0","2.5",""],["24","2","2","20","1","1.5",""],["152","152","152","152","152","152","304"],["66","1","1","25","0","2.5",""],["19","2","2","28","1","1.5",""],["1.3e-56","0.62","0.32","0.17","0.02","1","0.023"],["wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test",". %>% survdiff %>% .$chisq %>% pchisq(1, lower.tail = F) %>% list(p.value = .)"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th rowspan=\"2\"><\/th>\n <th colspan=\"3\">rx: 1 (n=188)<\/th>\n <th colspan=\"3\">rx: 2 (n=152)<\/th>\n <th colspan=\"2\">tests<\/th>\n <\/tr>\n <tr>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false,"columnDefs":[{"orderable":false,"targets":0}]},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script>
<div id="htmlwidget-0ae44a8b9270003302e1" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-0ae44a8b9270003302e1">{"x":{"filter":"none","class":"display","extensions":["FixedHeader","FixedColumns","Buttons"],"data":[["id","number","size","stop","event","enum","surv"],["188","188","188","188","188","188","376"],["24","1","1","23","0","2.5",""],["24","2","2","20","1","1.5",""],["152","152","152","152","152","152","304"],["66","1","1","25","0","2.5",""],["19","2","2","28","1","1.5",""],["1.3e-56","0.62","0.32","0.17","0.02","1","0.023"],["wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test","wilcox.test",". %>% survdiff %>% .$chisq %>% pchisq(1, lower.tail = F) %>% list(p.value = .)"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th rowspan=\"2\"><\/th>\n <th colspan=\"3\">rx: 1 (n=188)<\/th>\n <th colspan=\"3\">rx: 2 (n=152)<\/th>\n <th colspan=\"2\">tests<\/th>\n <\/tr>\n <tr>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>N<\/th>\n <th>Med<\/th>\n <th>IQR<\/th>\n <th>p<\/th>\n <th>test<\/th>\n <\/tr>\n <\/thead>\n<\/table>","options":{"info":false,"search":false,"dom":"Brtip","fixedColumns":true,"paging":false,"fixedHeader":true,"buttons":["copy","excel"],"order":[],"autoWidth":false,"orderClasses":false},"callback":"function(table) {\nreturn table;\n}"},"evals":["callback"],"jsHooks":[]}</script>
</div>


@@ -784,7 +764,7 @@ bladder <span class="op">%&gt;%</span>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
script.src = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>


Loading…
Cancel
Save