tidy_coef: Tidy a table of coefficients

View source: R/tidy_coef.R

tidy_coefR Documentation

Tidy a table of coefficients

Description

This function tidies a table of coefficients. Values can be processed (e.g., by rounding) and row and column names adjusted. A text file can be saved that can be imported into other programmes (e.g., Microsoft Word).

Usage

tidy_coef(
  coef,
  coef_names = rownames(coef),
  col_names = c("Coefficient", "Estimate", "SE", "z-value", "p-value")[1:(ncol(coef) +
    1)],
  f = function(x) prettyGraphics::add_lagging_point_zero(round(x, digits = 3), n = 3),
  f_index = 1:ncol(coef),
  file = NULL,
  quote = FALSE,
  sep = ",",
  row.names = FALSE,
  ...
)

Arguments

coef

A matrix of model coefficients, usually from coef. The matrix is expected to have row names (coefficient names) and numeric coefficients.

coef_names

(optional) A character vector of 'tidy' coefficient names.

col_names

(optional) A character vector of 'tidy' column names. The first column name should be the name of the column containing the coefficient names.

f

(optional) A function to be applied to specified columns to tidy numeric outputs.

f_index

An integer vector of the indices of the columns in coef to which the function f is applied. By default, if f is supplied, it is applied to all columns.

file

(optional) A character which defines the name of the file to be saved. This is passed to write.table.

quote

A logical value which defines whether or not to surround character or factor columns with quotes. This is passed to write.table.

sep

The field separator string. This is passed to write.table.

row.names

A logical value which defines whether or not row names are to be saved (or a character vector or the row names to be written). This is passed to write.table.

...

Other arguments passed to write.table.

Value

The function returns/saves a tidier table of coefficients.

Author(s)

Edward Lavender

Examples

n <- 100
x <- runif(n, 0, 1)
y <- rnorm(n, 5*x, 10)
mod <- lm(y ~ x)
tidy_coef(coef(summary(mod)))

edwardlavender/utils.add documentation built on Dec. 14, 2024, 8:11 a.m.