This vignette will show a few examples of how to use this package and alter what is output. It will also highlight some restrictions on formats that the user can request.
The main function used from this package is tablify
. This function accepts a
series of model output objects as its main arguments, converts the outputs to
dataset columns (using the tidy
function from the broom
package), and then
outputs two objects:
library(tabler) lm1 <- lm(mpg ~ wt, data = mtcars) lm2 <- lm(mpg ~ wt + cyl, data = mtcars) tablify(lm1, lm2)
If the user wants to manually manipulate the dataset of regression output:
start_table <- tablify(lm1, lm2)[[1]]
In general, the internal R object output is meant to be intermediary, or used as a preview before exporting the table to share. Exporting is achieved by:
library(WriteXLS) tablify(lm1, lm2, file = "myresults.csv") tablify(lm1, lm2, file = "myresults.xls") tablify(lm1, lm2, file = "myresults.xlsx")
Outputs to xls
or xlsx
formats requires the WriteXLS
package.
The default output can be altered in several ways:
teststat
: by default is "p.value"
, but can also be "std.error"
or "statistic"
"statistic"
will be a t-value or z-value and is model-dependentdigits
: by default is 3, and specifies the number of decimal rounding placesdigits_coef
and digits_teststat
take on the digits
value, unless they are explicitly specified. These allow more control over rounding coefficient vs. significance test outputscutoffs
: by default c(0.1, 0.05, 0.01)
, these specify the cutpoints at which significance markers are displayed. They must be presented in decreasing order, and any number are allowed.stars
: by default c("*", "**", "***")
, this list must be the same length as cutoffs
and again in order of weakest significance to strongest significanceintercept_last
: by default TRUE
, moves the intercept output to the bottom of the table (but before observation count and model fit statistics). If FALSE
, reports it first.N
: by default TRUE
, adds a row to the table displaying observation countfit
: by default NULL
, can also be a string or list of fit statistics available in a regression output ("r.squared", "adj.r.squared")file
: by deafult NULL
, specifies the output file name and path if desiredlm3 <- lm(mpg ~ cyl + disp + hp + drat + wt + qsec + vs, data = mtcars) tablify(lm3) tablify(lm3, cutoffs = c(0.2, 0.1, 0.05)) # error: # tablify(lm3, cutoffs = c(0.9, 0.7, 0.5, 0.3, 0.1)) # correct - must supply enugh significance denoters tablify(lm3, cutoffs = c(0.9, 0.7, 0.5, 0.3, 0.1), stars = c('?', '+', '*', '**', '***')) tablify(lm1, lm2, lm3, fit = c("r.squared", "adj.r.squared"))
Since this package relies on
broom
to tidy
model outputs into the columns for tables, it is currently limited to model
types handled by broom. For the latest list, see the developer's
site. Most frequently-used
models should be ready to go, though.
Models of different types (i.e. OLS and ordinal / binary logit) can be combined into one table, so long as the requested outputs are common between all of them. For example, requesting coefficients and their p-values will work, but requesting $R^2$ will fail, as ordinal models do not include this in their outputs.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.