<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/elegant-regression-results-tables-and-plots-in-r-the-finalfit-package/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.datasurg.net/2018/05/16/elegant-regression-results-tables-and-plots-the-finalfit-package/"> R – DataSurg</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The <code>finafit</code> package brings together the day-to-day functions we use to generate final results tables and plots when modelling. I spent many years repeatedly manually copying results from R analyses and built these functions to automate our standard healthcare data workflow. It is particularly useful when undertaking a large study involving multiple different regression analyses. When combined with <a rel="nofollow" href="https://rmarkdown.rstudio.com/" target="_blank">RMarkdown</a>, the reporting becomes entirely automated. Its design follows Hadley Wickham’s <a rel="nofollow" href="http://tidyverse.tidyverse.org/articles/manifesto.html" target="_blank">tidy tool manifesto</a>.</p>
<h3>Installation and Documentation</h3>
<p>It lives on <a rel="nofollow" href="https://github.com/ewenharrison/finalfit" target="_blank">GitHub</a>.</p>
<p>You can install <code>finalfit</code> from github with:</p>
<pre># install.packages(&quot;devtools&quot;)
devtools::install_github(&quot;ewenharrison/finalfit&quot;)</pre>
<p>It is recommended that this package is used together with <code>dplyr</code>, which is a dependent.</p>
<p>Some of the functions require <code>rstan</code> and <code>boot</code>. These have been left as <code>Suggests</code> rather than <code>Depends</code> to avoid unnecessary installation. If needed, they can be installed in the normal way:</p>
<pre>install.packages(&quot;rstan&quot;)
install.packages(&quot;boot&quot;)</pre>

<p>To <a rel="nofollow" href="http://www.datasurg.net/2018/05/05/install-github-package-on-safe-haven-server/" target="_blank">install off-line (or in a Safe Haven)</a>, download the zip file and use <code>devtools::install_local()</code>.</p>
<h3>Main Features</h3>
<h4>1. Summarise variables/factors by a categorical variable</h4>
<p><code>summary_factorlist()</code> is a wrapper used to aggregate any number of explanatory variables by a single <strong>variable of interest</strong>. This is often “Table 1” of a published study. When categorical, the variable of interest can have a maximum of five levels. It uses <code>Hmisc::summary.formula()</code>.</p>
<pre>library(finalfit)
library(dplyr)

# Load example dataset, modified version of survival::colon
data(colon_s)

# Table 1 - Patient demographics by variable of interest ----
explanatory = c(&quot;age&quot;, &quot;age.factor&quot;, &quot;sex.factor&quot;, &quot;obstruct.factor&quot;)
dependent = &quot;perfor.factor&quot; # Bowel perforation
colon_s %>%
	summary_factorlist(dependent, explanatory, p=TRUE, add_dependent_label=TRUE)</pre>

<p><a rel="nofollow" href="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table1.jpg" target="_blank"><img data-orig-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table1.jpg?fit=1079%2C424" data-orig-size="1079,424" data-medium-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table1.jpg?fit=300%2C118" data-attachment-id="879" data-image-meta="{" data-image-description="" src="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table1.jpg?resize=525%2C206" data-permalink="http://www.datasurg.net/2018/05/16/elegant-regression-results-tables-and-plots-the-finalfit-package/table1/" data-large-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table1.jpg?fit=525%2C206" alt="" data-image-title="table1" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" width="450" data-comments-opened="1" class="wp-image-879" data-recalc-dims="1"></a></p>
<p>See other options relating to inclusion of missing data, mean vs. median for continuous variables, column vs. row proportions, include a total column etc. </p>
<p><code>summary_factorlist()</code> is also commonly used to summarise any number of variables by an <strong>outcome variable</strong> (say dead yes/no).</p>
<pre># Table 2 - 5 yr mortality ----
explanatory = c(&quot;age&quot;, &quot;age.factor&quot;, &quot;sex.factor&quot;,
                &quot;obstruct.factor&quot;)
dependent = 'mort_5yr'
colon_s %>%
	summary_factorlist(dependent, explanatory, p=TRUE, add_dependent_label=TRUE)</pre>

<p><a rel="nofollow" href="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table2.jpg" target="_blank"><img data-orig-file="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table2.jpg?fit=1146%2C457" data-orig-size="1146,457" data-medium-file="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table2.jpg?fit=300%2C120" data-attachment-id="880" data-image-meta="{" data-image-description="" src="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table2.jpg?resize=525%2C209" data-permalink="http://www.datasurg.net/2018/05/16/elegant-regression-results-tables-and-plots-the-finalfit-package/table2/" data-large-file="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table2.jpg?fit=525%2C209" alt="" data-image-title="table2" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" width="450" data-comments-opened="1" class="wp-image-880" data-recalc-dims="1"></a></p>
<p>Tables can be knitted to PDF, Word or html documents. We do this in RStudio from a .Rmd document. Example chunk:</p>
<pre>```{r, echo = FALSE, results='asis'}
knitr::kable(example_table, row.names=FALSE, 
    align=c(&quot;l&quot;, &quot;l&quot;, &quot;r&quot;, &quot;r&quot;, &quot;r&quot;, &quot;r&quot;))
```</pre>

<h4>2. Summarise regression model results in final table format</h4>
<p>The second main feature is the ability to create final tables for linear (<code>lm()</code>), logistic (<code>glm()</code>), hierarchical logistic (<code>lme4::glmer()</code>) and<br>
Cox proportional hazards (<code>survival::coxph()</code>) regression models.</p>
<p>The <code>finalfit()</code> “all-in-one” function takes a single dependent variable with a vector of explanatory variable names (continuous or categorical variables) to produce a final table for publication including summary statistics, univariable and multivariable regression analyses. The first columns are those produced by <code>summary_factorist()</code>. The appropriate regression model is chosen on the basis of the dependent variable type and other arguments passed.</p>
<h5>Logistic regression: glm()</h5>
<p>Of the form: <code>glm(depdendent ~ explanatory, family=&quot;binomial&quot;)</code></p>
<pre>explanatory = c(&quot;age.factor&quot;, &quot;sex.factor&quot;, 
                &quot;obstruct.factor&quot;, &quot;perfor.factor&quot;)
dependent = 'mort_5yr'
colon_s %>%
    finalfit(dependent, explanatory)</pre>

<p><a rel="nofollow" href="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table3.jpg" target="_blank"><img data-orig-file="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table3.jpg?fit=1815%2C451" data-orig-size="1815,451" data-medium-file="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table3.jpg?fit=300%2C75" data-attachment-id="881" data-image-meta="{" data-image-description="" src="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table3.jpg?resize=525%2C130" data-permalink="http://www.datasurg.net/2018/05/16/elegant-regression-results-tables-and-plots-the-finalfit-package/table3/" data-large-file="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table3.jpg?fit=525%2C130" alt="" data-image-title="table3" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" width="450" data-comments-opened="1" class="wp-image-881" data-recalc-dims="1"></a></p>
<h5>Logistic regression with reduced model: glm()</h5>
<p>Where a multivariable model contains a subset of the variables included specified in the full univariable set, this can be specified.</p>
<pre>explanatory = c(&quot;age.factor&quot;, &quot;sex.factor&quot;, &quot;obstruct.factor&quot;, &quot;perfor.factor&quot;)
explanatory_multi = c(&quot;age.factor&quot;, &quot;obstruct.factor&quot;)
dependent = 'mort_5yr'
colon_s %>%
    finalfit(dependent, explanatory, explanatory_multi)</pre>

<p><a rel="nofollow" href="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table4.jpg" target="_blank"><img data-orig-file="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table4.jpg?fit=1824%2C457" data-orig-size="1824,457" data-medium-file="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table4.jpg?fit=300%2C75" data-attachment-id="882" data-image-meta="{" data-image-description="" src="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table4.jpg?resize=525%2C132" data-permalink="http://www.datasurg.net/2018/05/16/elegant-regression-results-tables-and-plots-the-finalfit-package/table4/" data-large-file="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table4.jpg?fit=525%2C132" alt="" data-image-title="table4" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" width="450" data-comments-opened="1" class="wp-image-882" data-recalc-dims="1"></a></p>
<h5>Mixed effects logistic regression: lme4::glmer()</h5>
<p>Of the form: <code>lme4::glmer(dependent ~ explanatory + (1 | random_effect), family=&quot;binomial&quot;)</code></p>
<p>Hierarchical/mixed effects/multilevel logistic regression models can be specified using the argument <code>random_effect</code>. At the moment it is just set up for random intercepts (i.e. <code>(1 | random_effect)</code>, but in the future I’ll adjust this to accommodate random gradients if needed (i.e. <code>(variable1 | variable2)</code>.</p>
<pre>explanatory = c(&quot;age.factor&quot;, &quot;sex.factor&quot;, &quot;obstruct.factor&quot;, &quot;perfor.factor&quot;)
explanatory_multi = c(&quot;age.factor&quot;, &quot;obstruct.factor&quot;)
random_effect = &quot;hospital&quot;
dependent = 'mort_5yr'
colon_s %>%
    finalfit(dependent, explanatory, explanatory_multi, random_effect)</pre>

<p><a rel="nofollow" href="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table5.jpg" target="_blank"><img data-orig-file="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table5.jpg?fit=1820%2C456" data-orig-size="1820,456" data-medium-file="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table5.jpg?fit=300%2C75" data-attachment-id="883" data-image-meta="{" data-image-description="" src="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table5.jpg?resize=525%2C132" data-permalink="http://www.datasurg.net/2018/05/16/elegant-regression-results-tables-and-plots-the-finalfit-package/table5/" data-large-file="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table5.jpg?fit=525%2C132" alt="" data-image-title="table5" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" width="450" data-comments-opened="1" class="wp-image-883" data-recalc-dims="1"></a></p>
<h5>Cox proportional hazards: survival::coxph()</h5>
<p>Of the form: <code>survival::coxph(dependent ~ explanatory)</code></p>
<pre>explanatory = c(&quot;age.factor&quot;, &quot;sex.factor&quot;, &quot;obstruct.factor&quot;, &quot;perfor.factor&quot;)
dependent = &quot;Surv(time, status)&quot;
colon_s %>%
    finalfit(dependent, explanatory)</pre>

<p><a rel="nofollow" href="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table6.jpg" target="_blank"><img data-orig-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table6.jpg?fit=1473%2C449" data-orig-size="1473,449" data-medium-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table6.jpg?fit=300%2C91" data-attachment-id="884" data-image-meta="{" data-image-description="" src="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table6.jpg?resize=525%2C160" data-permalink="http://www.datasurg.net/2018/05/16/elegant-regression-results-tables-and-plots-the-finalfit-package/table6/" data-large-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table6.jpg?fit=525%2C160" alt="" data-image-title="table6" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" width="450" data-comments-opened="1" class="wp-image-884" data-recalc-dims="1"></a></p>
<h5>Add common model metrics to output</h5>
<p><code>metrics=TRUE</code> provides common model metrics. The output is a list of two dataframes. Note chunk specification for output below.</p>
<pre>explanatory = c(&quot;age.factor&quot;, &quot;sex.factor&quot;, &quot;obstruct.factor&quot;, &quot;perfor.factor&quot;)
dependent = 'mort_5yr'
colon_s %>%
  finalfit(dependent, explanatory, metrics=TRUE)</pre>

<pre>```{r, echo=FALSE, results=&quot;asis&quot;}
knitr::kable(table7[[1]], row.names=FALSE, align=c(&quot;l&quot;, &quot;l&quot;, &quot;r&quot;, &quot;r&quot;, &quot;r&quot;))
knitr::kable(table7[[2]], row.names=FALSE)
```</pre>

<p><a rel="nofollow" href="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table7a.jpg" target="_blank"><img data-orig-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table7a.jpg?fit=1818%2C454" data-orig-size="1818,454" data-medium-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table7a.jpg?fit=300%2C75" data-attachment-id="886" data-image-meta="{" data-image-description="" src="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table7a.jpg?resize=525%2C131" data-permalink="http://www.datasurg.net/2018/05/16/elegant-regression-results-tables-and-plots-the-finalfit-package/table7a/" data-large-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table7a.jpg?fit=525%2C131" alt="" data-image-title="table7a" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" width="450" data-comments-opened="1" class="wp-image-886" data-recalc-dims="1"></a></p>
<p><a rel="nofollow" href="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table7b.jpg" target="_blank"><img data-orig-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table7b.jpg?fit=1836%2C71" data-orig-size="1836,71" data-medium-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table7b.jpg?fit=300%2C12" data-attachment-id="885" data-image-meta="{" data-image-description="" src="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table7b.jpg?resize=525%2C20" data-permalink="http://www.datasurg.net/2018/05/16/elegant-regression-results-tables-and-plots-the-finalfit-package/table7b/" data-large-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table7b.jpg?fit=525%2C21" alt="" data-image-title="table7b" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" width="450" data-comments-opened="1" class="wp-image-885" data-recalc-dims="1"></a></p>
<p>Rather than going all-in-one, any number of subset models can be manually added on to a <code>summary_factorlist()</code> table using <code>finalfit_merge()</code>. This is particularly useful when models take a long-time to run or are complicated.</p>
<p>Note the requirement for <code>fit_id=TRUE</code> in <code>summary_factorlist()</code>. <code>fit2df</code> extracts, condenses, and add metrics to supported models.</p>

<pre>explanatory = c(&quot;age.factor&quot;, &quot;sex.factor&quot;, &quot;obstruct.factor&quot;, &quot;perfor.factor&quot;)
explanatory_multi = c(&quot;age.factor&quot;, &quot;obstruct.factor&quot;)
random_effect = &quot;hospital&quot;
dependent = 'mort_5yr'

# Separate tables
colon_s %>%
	summary_factorlist(dependent, explanatory, fit_id=TRUE) -> example.summary

colon_s %>%
	glmuni(dependent, explanatory) %>%
	fit2df(estimate_suffix=&quot; (univariable)&quot;) -> example.univariable

colon_s %>%
	glmmulti(dependent, explanatory) %>%
	fit2df(estimate_suffix=&quot; (multivariable)&quot;) -> example.multivariable

colon_s %>%
	glmmixed(dependent, explanatory, random_effect) %>%
	fit2df(estimate_suffix=&quot; (multilevel)&quot;) -> example.multilevel

# Pipe together
example.summary %>%
	finalfit_merge(example.univariable) %>%
	finalfit_merge(example.multivariable) %>%
	finalfit_merge(example.multilevel) %>%
	select(-c(fit_id, index)) %>% # remove unnecessary columns
	dependent_label(colon_s, dependent, prefix=&quot;&quot;) # place dependent variable label</pre>

<p><a rel="nofollow" href="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table8.jpg" target="_blank"><img data-orig-file="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table8.jpg?fit=1632%2C358" data-orig-size="1632,358" data-medium-file="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table8.jpg?fit=300%2C66" data-attachment-id="890" data-image-meta="{" data-image-description="" src="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table8.jpg?resize=525%2C115" data-permalink="http://www.datasurg.net/2018/05/16/elegant-regression-results-tables-and-plots-the-finalfit-package/table8/" data-large-file="https://i0.wp.com/www.datasurg.net/wp-content/uploads/2018/05/table8.jpg?fit=525%2C115" alt="" data-image-title="table8" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" width="450" data-comments-opened="1" class="wp-image-890" data-recalc-dims="1"></a></p>
<h5>Bayesian logistic regression: with <code>stan</code></h5>
<p>Our own particular <code>rstan</code> models are supported and will be documented in the future. Broadly, if you are running (hierarchical) logistic regression models in [Stan](http://mc-stan.org/users/interfaces/rstan) with coefficients specified as a vector labelled <code>beta</code>, then <code>fit2df()</code> will work directly on the <code>stanfit</code> object in a similar manner to if it was a <code>glm</code> or <code>glmerMod</code> object.</p>
<h3>3. Summarise regression model results in plot</h3>
<p>Models can be summarized with odds ratio/hazard ratio plots using <code>or_plot</code>, <code>hr_plot</code> and <code>surv_plot</code>.</p>
<h4>OR plot</h4>

<pre># OR plot
explanatory = c(&quot;age.factor&quot;, &quot;sex.factor&quot;, &quot;obstruct.factor&quot;, &quot;perfor.factor&quot;)
dependent = 'mort_5yr'
colon_s %>%
  or_plot(dependent, explanatory)
# Previously fitted models (`glmmulti()` or `glmmixed()`) can be provided directly to `glmfit`</pre>

<p><a rel="nofollow" href="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/plot1.jpg" target="_blank"><img data-orig-file="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/plot1.jpg?fit=1042%2C481" data-orig-size="1042,481" data-medium-file="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/plot1.jpg?fit=300%2C138" data-attachment-id="895" data-image-meta="{" data-image-description="" src="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/plot1.jpg?resize=525%2C242" data-permalink="http://www.datasurg.net/2018/05/16/elegant-regression-results-tables-and-plots-the-finalfit-package/plot1/" data-large-file="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/plot1.jpg?fit=525%2C243" alt="" data-image-title="plot1" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" width="450" data-comments-opened="1" class="wp-image-895" data-recalc-dims="1"></a></p>
<h4>HR plot</h4>

<pre># HR plot
explanatory = c(&quot;age.factor&quot;, &quot;sex.factor&quot;, &quot;obstruct.factor&quot;, &quot;perfor.factor&quot;)
dependent = &quot;Surv(time, status)&quot;
colon_s %>%
  hr_plot(dependent, explanatory, dependent_label = &quot;Survival&quot;)
# Previously fitted models (`coxphmulti`) can be provided directly using `coxfit`</pre>

<p><a rel="nofollow" href="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/plot2.jpg" target="_blank"><img data-orig-file="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/plot2.jpg?fit=1039%2C478" data-orig-size="1039,478" data-medium-file="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/plot2.jpg?fit=300%2C138" data-attachment-id="896" data-image-meta="{" data-image-description="" src="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/plot2.jpg?resize=525%2C242" data-permalink="http://www.datasurg.net/2018/05/16/elegant-regression-results-tables-and-plots-the-finalfit-package/plot2/" data-large-file="https://i2.wp.com/www.datasurg.net/wp-content/uploads/2018/05/plot2.jpg?fit=525%2C241" alt="" data-image-title="plot2" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" width="450" data-comments-opened="1" class="wp-image-896" data-recalc-dims="1"></a></p>
<h4> Kaplan-Meier survival plots</h4>
<p>KM plots can be produced using the <code>library(survminer)</code></p>

<pre># KM plot
explanatory = c(&quot;perfor.factor&quot;)
dependent = &quot;Surv(time, status)&quot;
colon_s %>%
	surv_plot(dependent, explanatory, xlab=&quot;Time (days)&quot;, pval=TRUE, legend=&quot;none&quot;)</pre>

<p><a rel="nofollow" href="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/Rplot.png" target="_blank"><img data-orig-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/Rplot.png?fit=500%2C500" data-orig-size="500,500" data-medium-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/Rplot.png?fit=300%2C300" data-attachment-id="964" data-image-meta="{" data-image-description="" src="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/Rplot.png?resize=500%2C500" data-permalink="http://www.datasurg.net/2018/05/16/elegant-regression-results-tables-and-plots-the-finalfit-package/rplot/" data-large-file="https://i1.wp.com/www.datasurg.net/wp-content/uploads/2018/05/Rplot.png?fit=500%2C500" alt="" data-image-title="Rplot" sizes="(max-width: 500px) 100vw, 500px" width="450" data-comments-opened="1" class="wp-image-964" data-recalc-dims="1"></a></p>
<h3>Notes</h3>
<p>Use <code>Hmisc::label()</code> to assign labels to variables for tables and plots.</p>

<pre>label(colon_s$age.factor) = &quot;Age (years)&quot;</pre>

<p>Export dataframe tables directly or to <a rel="nofollow" href="http://rmarkdown.rstudio.com/" target="_blank">R Markdown</a> <a rel="nofollow" href="https://yihui.name/knitr/" target="_blank"><code>knitr::kable()</code></a>.</p>
<p>Note wrapper <code>summary_missing()</code> is also useful. Wraps <code>mice::md.pattern</code>.</p>

<pre>colon_s %>%
  summary_missing(dependent, explanatory)</pre>

<p>Development will be on-going, but any input appreciated. </p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.datasurg.net/2018/05/16/elegant-regression-results-tables-and-plots-the-finalfit-package/"> R – DataSurg</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/kLNAbPTUaO0" height="1"></a></div>