Package 'repmod'

Title: Create Report Table from Different Objects
Description: Tools for generating descriptives and report tables for different models, data.frames and tables and exporting them to different formats.
Authors: David Hervas Marin
Maintainer: David Hervas Marin <[email protected]>
License: GPL (>=2)
Version: 0.4.02
Built: 2024-11-16 16:47:14 UTC
Source: https://github.com/david-hervas/repmod

Help Index


ROC area under curve

Description

Estimates AUC from predicted and observed values

Usage

AUC(pred, obs)

Arguments

pred

Numeric vector of predicted values

obs

Numeric vector of observed values or factor with two levels

Value

Returns the AUC

Examples

glm1 <- glm(case ~ spontaneous + age, data=infert, family="binomial")
pred1 <- fitted(glm1)
AUC(pred1, infert$case)

Bootstrap optimism correction for models

Description

Returns optimism correction for absolute fit values

Usage

boot_model(
  formula,
  data,
  B = 200,
  fit_function = "lm",
  metric = if (length(unique(data[, as.character(formula)[2]])) == 2) "AUC" else "RMSE",
  predict.control = list(NULL),
  ...
)

Arguments

formula

An object of class "formula" describing the model to be validated

data

A data frame containing the variables specified in formula argument

B

Number of bootstrap samples

fit_function

Name of the model fitting function

metric

Performance metric to estimate: RMSE, MSE, MAE or AUC

predict.control

Named list of arguments to pass to the predict function of the model

...

Further arguments passed to the model fitting function

Value

Optimism correction values for the selected performance metric

Examples

boot_model(Petal.Length ~ Sepal.Width + Species, data=iris)

Auxiliary functions for report.data.frame

Description

Internal function for categorical summary

Usage

cat_summary(x, digits)

Arguments

x

A vector of class character

digits

Number of digits for rounding

Value

Returns a summary of a categorical variable


Plot of the coefficients of a model

Description

Creates a plot of the coefficients of a model.

Usage

coefplot(
  coefs,
  lwr.int = coefs,
  upper.int = coefs,
  offset = 0,
  coefnames = names(coefs),
  abline.pos = 0,
  sorted = FALSE,
  reverse = FALSE,
  pch = 16,
  xlim = c(min(lwr.int, na.rm = TRUE), max(upper.int, na.rm = TRUE)),
  ylim = c(1, length(coefs)),
  color = "black",
  ...
)

Arguments

coefs

A vector with each coefficient

lwr.int

A vector with the lower end of the CI

upper.int

A vector with the upper end of the CI

offset

Y-axis offset for the coefficients

coefnames

Name for each variable

abline.pos

Position for the vertical reference line

sorted

Should the coefficients be sorted from highest to lowest?

reverse

Should the order be reversed?

pch

Type of point

xlim

Limits of the X-axis

ylim

Limits of the Y-axis

color

Color for the points

...

Further arguments passed to axis()

Value

A plot of the coefficients with their CI

Examples

lm1 <- lm(Petal.Length ~ Sepal.Width + Species, data=iris)
a<-report(lm1)
oldpar <- par()
par(mar=c(4, 10, 3, 2))
#Coefplot calling plot.reportmodel
plot(a)
par(mar=oldpar$mar)  #Restore old margin values
#Manual coefplot
coefplot(coefs=c(1, 2, 3), lwr.int=c(0, 1, 2), upper.int=c(5, 6, 7), coefnames=c("A", "B", "C"))

K-fold cross-validation for models

Description

Returns cross-validated absolute fit values

Usage

cv_model(
  formula,
  data,
  k = 5,
  fit_function = "lm",
  metric = if (length(unique(data[, as.character(formula)[2]])) == 2) "AUC" else "RMSE",
  predict.control = list(NULL),
  ...
)

Arguments

formula

An object of class "formula" describing the model to be validated

data

A data frame containing the variables specified in formula argument

k

Number of folds

fit_function

Name of the model fitting function

metric

Performance metric to estimate: RMSE, MSE, MAE or AUC

predict.control

Named list of arguments to pass to the predict function of the model

...

Further arguments passed to the model fitting function

Value

Cross-validated values for the selected performance metric

Examples

cv_model(Petal.Length ~ Sepal.Width + Species, data=iris)

Mean absolute error

Description

Estimates mean absolute error from predicted and observed values

Usage

MAE(pred, obs)

Arguments

pred

Numeric vector of predicted values

obs

Numeric vector of observed values

Value

Returns the MAE

Examples

lm1 <- lm(Petal.Length ~ Sepal.Width + Species, data=iris)
pred1 <- fitted(lm1)
MAE(pred1, iris$Petal.Length)

Export a table to excel

Description

Exports a table to Excel.

Usage

make_csv_table(x, file, info)

Arguments

x

A data.frame object

file

Name of the file

info

Footer for the table

Value

Creates a .csv file with the table


Export a table to latex

Description

Exports a table to latex.

Usage

make_latex_table(x, file)

Arguments

x

A data.frame object

file

Name of the file

Value

Creates a .txt file with latex code for the table


Make a table from report

Description

Auxiliary function to create tables.

Usage

make_table(x, file, type, info = NULL, ...)

Arguments

x

A data.frame object

file

Name of the file

type

Type of file

info

Footer for the table

...

Additional parameters passed to make_word_table

Value

Creates a file with the table


Export a table to word

Description

Exports a table to Word.

Usage

make_word_table(x, file, info = NULL, use.rownames = TRUE)

Arguments

x

A data.frame object

file

Name of the file

info

Footer for the table

use.rownames

Should row names be added to the output?

Value

Creates a word file with the table


Auxiliary matrix paste function

Description

Internal function for report.table

Usage

matrixPaste(..., sep = rep(" ", length(list(...)) - 1))

Arguments

...

Matrices to paste

sep

Separator for the paste function

Value

Returns a matrix with the different matrices used as input pasted together


Mean squared error

Description

Estimates mean squared error from predicted and observed values

Usage

MSE(pred, obs)

Arguments

pred

Numeric vector of predicted values

obs

Numeric vector of observed values

Value

Returns the MSE

Examples

lm1 <- lm(Petal.Length ~ Sepal.Width + Species, data=iris)
pred1 <- fitted(lm1)
MSE(pred1, iris$Petal.Length)

Auxiliary functions for report.data.frame

Description

Internal function for numerical summary

Usage

numeric_summary(x, digits)

Arguments

x

A vector of class numeric

digits

Number of digits for rounding

Value

Returns a summary of a numerical variable


Coefplot for reportmodel objects

Description

Creates a coefplot from the reportmodel object.

Usage

## S3 method for class 'reportmodel'
plot(x, ...)

Arguments

x

A reportmodel object

...

Further arguments passed to coefplot

Value

Returns a plot of each coefficient in the model with its 95

Examples

lm1 <- lm(Petal.Length ~ Sepal.Width + Species, data=iris)
a<-report(lm1)
oldpar <- par()
par(mar=c(4, 10, 3, 2))
plot(a)   #Coefplot calling plot.reportmodel
par(mar=oldpar$mar)

Generic function for creating reporting tables

Description

Generic function for creating reporting tables.

Usage

report(x, ...)

Arguments

x

An compatibleobject that can be summarized

...

further arguments passed to make_table

Value

A data frame with the report table

Examples

report(iris)  #Report of descriptive statistics
lm1 <- lm(Petal.Length ~ Sepal.Width + Species, data=iris)
report(lm1)   #Report of model

Report from beta regression model

Description

Creates a report table from a beta regression model.

Usage

## S3 method for class 'betareg'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  digitspvals = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

A betareg model object

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

digitspvals

Number of decimals for p-values

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report models from brms package

Description

Creates a report table from model fitted by brms.

Usage

## S3 method for class 'brmsfit'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

A brms model object

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report from ordinal model

Description

Creates a report table from an ordinal model.

Usage

## S3 method for class 'clm'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  digitspvals = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

An ordinal model object

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

digitspvals

Number of decimals for p-values

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report from ordinal mixed model

Description

Creates a report table from an ordinal mixed model.

Usage

## S3 method for class 'clmm'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  digitspvals = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

An ordinal model object

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

digitspvals

Number of decimals for p-values

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report from cox regression model

Description

Creates a report table from a cox model.

Usage

## S3 method for class 'coxph'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  digitspvals = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

A cox model object

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

digitspvals

Number of decimals for p-values

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report tables of summary data

Description

Creates a report table ready for publication.

Usage

## S3 method for class 'data.frame'
report(
  x,
  by = NULL,
  remove.by = FALSE,
  file = NULL,
  type = "word",
  digits = 2,
  digitscat = digits,
  print = TRUE,
  ...
)

Arguments

x

A data.frame object

by

Grouping variable for the report

remove.by

Remove grouping variable from the report table?

file

Name of the file to export the table

type

Format of the file

digits

Number of decimal places

digitscat

Number of decimal places for categorical variables (if different to digits)

print

Should the report table be printed on screen?

...

further arguments passed to make_table()

Value

Returns a summary table of the data in publication-friendly format

Examples

report(iris)
(reporTable<-report(iris, by="Species"))
class(reporTable)

Default function for report

Description

This is a default function for calling summary(x) on non-implemented classes.

Usage

## Default S3 method:
report(x, ...)

Arguments

x

Any object without specific report function

...

further arguments passed to summary

Value

A summary of the object


Report from categorical variable

Description

Creates a report table.

Usage

## S3 method for class 'factor'
report(x, ...)

Arguments

x

A categorical variable

...

Further arguments passed to make_table

Value

A data frame with the report table


Report from generalized linear model

Description

Creates a report table from a generalized linear model.

Usage

## S3 method for class 'glm'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  digitspvals = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

A generalized linear model object

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

digitspvals

Number of decimals for p-values

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report from generalized linear mixed model

Description

Creates a report table from a generalized linear mixed model.

Usage

## S3 method for class 'glmerMod'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  digitspvals = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

A generalized linear mixed model object

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

digitspvals

Number of decimals for p-values

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report from generalized linear mixed model from ADMB

Description

Creates a report table from a glmmadmb model.

Usage

## S3 method for class 'glmmadmb'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  digitspvals = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

A generalized linear mixed model object (glmmabmb)

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

digitspvals

Number of decimals for p-values

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report models from glmnet package

Description

Creates a report table from models fitted by glmnet.

Usage

## S3 method for class 'glmnet'
report(
  x,
  s,
  gamma = 1,
  drop.zero = TRUE,
  file = NULL,
  type = "word",
  digits = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

A glmnet model object

s

Value of lambda for estimating the coefficients

gamma

Value of gamma for estimating the coefficients (only used in relaxed fits)

drop.zero

Should zero coefficients be dropped?

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report from generalized least squares model

Description

Creates a report table from a generalized least squares model.

Usage

## S3 method for class 'gls'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  digitspvals = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

A gls object

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

digitspvals

Number of decimals for p-values

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report from linear model

Description

Creates a report table from a linear model.

Usage

## S3 method for class 'lm'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  digitspvals = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

A linear model object

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

digitspvals

Number of decimals for p-values

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report from linear mixed model

Description

Creates a report table from a linear mixed model.

Usage

## S3 method for class 'lmerMod'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  digitspvals = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

A linear mixed model object

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

digitspvals

Number of decimals for p-values

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report from quantile mixed model

Description

Creates a report table from a quantile mixed model.

Usage

## S3 method for class 'lqmm'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  digitspvals = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

A quantile model object

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

digitspvals

Number of decimals for p-values

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report from linear mixed model with pvalues

Description

Creates a report table from a linear mixed model.

Usage

## S3 method for class 'merModLmerTest'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  digitspvals = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

A linear mixed model object

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

digitspvals

Number of decimals for p-values

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report from numeric variable

Description

Creates a report table.

Usage

## S3 method for class 'numeric'
report(x, ...)

Arguments

x

A numeric variable

...

Further arguments passed to make_table

Value

A data frame with the report table


Report from robust linear model (rlm)

Description

Creates a report table from a robust linear model.

Usage

## S3 method for class 'rlm'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  digitspvals = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

A rlm object

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

digitspvals

Number of decimals for p-values

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Report from quantile regression model

Description

Creates a report table from a quantile regression model.

Usage

## S3 method for class 'rq'
report(
  x,
  file = NULL,
  type = "word",
  digits = 3,
  digitspvals = 3,
  info = TRUE,
  print = TRUE,
  exclude = NULL,
  ...
)

Arguments

x

A quantreg model object

file

Name of the file to export the table

type

Format of the file

digits

Number of decimals

digitspvals

Number of decimals for p-values

info

If TRUE, include call in the exported table

print

Should the report table be printed on screen?

exclude

Vector with rownames to remove from output

...

Further arguments passed to make_table

Value

A data frame with the report table


Root mean squared error

Description

Estimates root mean squared error from predicted and observed values

Usage

RMSE(pred, obs)

Arguments

pred

Numeric vector of predicted values

obs

Numeric vector of observed values

Value

Returns the RMSE

Examples

lm1 <- lm(Petal.Length ~ Sepal.Width + Species, data=iris)
pred1 <- fitted(lm1)
RMSE(pred1, iris$Petal.Length)

Function to compute bootstrap confidence intervals for robust linear regression models

Description

Estimates confidence intervals for rlm models.

Usage

rob.ci(x, level = 0.95, maxit = 200, R = 2000)

Arguments

x

A rlm object

level

Confidence level for the interval

maxit

Maximum number of iterations per fit

R

Number of boostrap samples

Value

A matrix with bootstrap confidence intervals for each variable in the model


Function to compute p-values for robust linear regression models

Description

Estimates p-values for rlm models.

Usage

rob.pvals(x)

Arguments

x

A rlm object

Value

A vector of p-values


Set header names for word tables

Description

Internal function for make_word_table.

Usage

set_noms(x, args)

Arguments

x

A flextable object

args

A names list with the header names

Value

A flextable object with assigned header names


Generic VarCorr function

Description

Extract Variance-Covariance Matrix.

Usage

VarCorr(x, sigma = 1, ...)

Arguments

x

A model object

sigma

Optional value used as a multiplier for the standard deviations

...

Further arguments passed to VarrCorr methods

Value

A Variance-Covariance Matrix