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 |
Estimates AUC from predicted and observed values
AUC(pred, obs)
AUC(pred, obs)
pred |
Numeric vector of predicted values |
obs |
Numeric vector of observed values or factor with two levels |
Returns the AUC
glm1 <- glm(case ~ spontaneous + age, data=infert, family="binomial") pred1 <- fitted(glm1) AUC(pred1, infert$case)
glm1 <- glm(case ~ spontaneous + age, data=infert, family="binomial") pred1 <- fitted(glm1) AUC(pred1, infert$case)
Returns optimism correction for absolute fit values
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), ... )
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), ... )
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 |
Optimism correction values for the selected performance metric
boot_model(Petal.Length ~ Sepal.Width + Species, data=iris)
boot_model(Petal.Length ~ Sepal.Width + Species, data=iris)
Internal function for categorical summary
cat_summary(x, digits)
cat_summary(x, digits)
x |
A vector of class character |
digits |
Number of digits for rounding |
Returns a summary of a categorical variable
Creates a plot of the coefficients of a model.
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", ... )
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", ... )
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() |
A plot of the coefficients with their CI
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"))
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"))
Returns cross-validated absolute fit values
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), ... )
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), ... )
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 |
Cross-validated values for the selected performance metric
cv_model(Petal.Length ~ Sepal.Width + Species, data=iris)
cv_model(Petal.Length ~ Sepal.Width + Species, data=iris)
Estimates mean absolute error from predicted and observed values
MAE(pred, obs)
MAE(pred, obs)
pred |
Numeric vector of predicted values |
obs |
Numeric vector of observed values |
Returns the MAE
lm1 <- lm(Petal.Length ~ Sepal.Width + Species, data=iris) pred1 <- fitted(lm1) MAE(pred1, iris$Petal.Length)
lm1 <- lm(Petal.Length ~ Sepal.Width + Species, data=iris) pred1 <- fitted(lm1) MAE(pred1, iris$Petal.Length)
Exports a table to Excel.
make_csv_table(x, file, info)
make_csv_table(x, file, info)
x |
A data.frame object |
file |
Name of the file |
info |
Footer for the table |
Creates a .csv file with the table
Exports a table to latex.
make_latex_table(x, file)
make_latex_table(x, file)
x |
A data.frame object |
file |
Name of the file |
Creates a .txt file with latex code for the table
Auxiliary function to create tables.
make_table(x, file, type, info = NULL, ...)
make_table(x, file, type, info = NULL, ...)
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 |
Creates a file with the table
Exports a table to Word.
make_word_table(x, file, info = NULL, use.rownames = TRUE)
make_word_table(x, file, info = NULL, use.rownames = TRUE)
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? |
Creates a word file with the table
Internal function for report.table
matrixPaste(..., sep = rep(" ", length(list(...)) - 1))
matrixPaste(..., sep = rep(" ", length(list(...)) - 1))
... |
Matrices to paste |
sep |
Separator for the paste function |
Returns a matrix with the different matrices used as input pasted together
Estimates mean squared error from predicted and observed values
MSE(pred, obs)
MSE(pred, obs)
pred |
Numeric vector of predicted values |
obs |
Numeric vector of observed values |
Returns the MSE
lm1 <- lm(Petal.Length ~ Sepal.Width + Species, data=iris) pred1 <- fitted(lm1) MSE(pred1, iris$Petal.Length)
lm1 <- lm(Petal.Length ~ Sepal.Width + Species, data=iris) pred1 <- fitted(lm1) MSE(pred1, iris$Petal.Length)
Internal function for numerical summary
numeric_summary(x, digits)
numeric_summary(x, digits)
x |
A vector of class numeric |
digits |
Number of digits for rounding |
Returns a summary of a numerical variable
Creates a coefplot from the reportmodel object.
## S3 method for class 'reportmodel' plot(x, ...)
## S3 method for class 'reportmodel' plot(x, ...)
x |
A reportmodel object |
... |
Further arguments passed to coefplot |
Returns a plot of each coefficient in the model with its 95
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)
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.
report(x, ...)
report(x, ...)
x |
An compatibleobject that can be summarized |
... |
further arguments passed to make_table |
A data frame with the report table
report(iris) #Report of descriptive statistics lm1 <- lm(Petal.Length ~ Sepal.Width + Species, data=iris) report(lm1) #Report of model
report(iris) #Report of descriptive statistics lm1 <- lm(Petal.Length ~ Sepal.Width + Species, data=iris) report(lm1) #Report of model
Creates a report table from a beta regression model.
## S3 method for class 'betareg' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'betareg' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Creates a report table from model fitted by brms.
## S3 method for class 'brmsfit' report( x, file = NULL, type = "word", digits = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'brmsfit' report( x, file = NULL, type = "word", digits = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Creates a report table from an ordinal model.
## S3 method for class 'clm' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'clm' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Creates a report table from an ordinal mixed model.
## S3 method for class 'clmm' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'clmm' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Creates a report table from a cox model.
## S3 method for class 'coxph' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'coxph' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Creates a report table ready for publication.
## S3 method for class 'data.frame' report( x, by = NULL, remove.by = FALSE, file = NULL, type = "word", digits = 2, digitscat = digits, print = TRUE, ... )
## S3 method for class 'data.frame' report( x, by = NULL, remove.by = FALSE, file = NULL, type = "word", digits = 2, digitscat = digits, print = TRUE, ... )
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() |
Returns a summary table of the data in publication-friendly format
report(iris) (reporTable<-report(iris, by="Species")) class(reporTable)
report(iris) (reporTable<-report(iris, by="Species")) class(reporTable)
This is a default function for calling summary(x) on non-implemented classes.
## Default S3 method: report(x, ...)
## Default S3 method: report(x, ...)
x |
Any object without specific report function |
... |
further arguments passed to summary |
A summary of the object
Creates a report table.
## S3 method for class 'factor' report(x, ...)
## S3 method for class 'factor' report(x, ...)
x |
A categorical variable |
... |
Further arguments passed to make_table |
A data frame with the report table
Creates a report table from a generalized linear model.
## S3 method for class 'glm' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'glm' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Creates a report table from a generalized linear mixed model.
## S3 method for class 'glmerMod' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'glmerMod' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Creates a report table from a glmmadmb model.
## S3 method for class 'glmmadmb' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'glmmadmb' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Creates a report table from models fitted by glmnet.
## 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, ... )
## 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, ... )
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 |
A data frame with the report table
Creates a report table from a generalized least squares model.
## S3 method for class 'gls' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'gls' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Creates a report table from a linear model.
## S3 method for class 'lm' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'lm' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Creates a report table from a linear mixed model.
## S3 method for class 'lmerMod' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'lmerMod' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Creates a report table from a quantile mixed model.
## S3 method for class 'lqmm' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'lqmm' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Creates a report table from a linear mixed model.
## S3 method for class 'merModLmerTest' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'merModLmerTest' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Creates a report table.
## S3 method for class 'numeric' report(x, ...)
## S3 method for class 'numeric' report(x, ...)
x |
A numeric variable |
... |
Further arguments passed to make_table |
A data frame with the report table
Creates a report table from a robust linear model.
## S3 method for class 'rlm' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'rlm' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Creates a report table from a quantile regression model.
## S3 method for class 'rq' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
## S3 method for class 'rq' report( x, file = NULL, type = "word", digits = 3, digitspvals = 3, info = TRUE, print = TRUE, exclude = NULL, ... )
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 |
A data frame with the report table
Estimates root mean squared error from predicted and observed values
RMSE(pred, obs)
RMSE(pred, obs)
pred |
Numeric vector of predicted values |
obs |
Numeric vector of observed values |
Returns the RMSE
lm1 <- lm(Petal.Length ~ Sepal.Width + Species, data=iris) pred1 <- fitted(lm1) RMSE(pred1, iris$Petal.Length)
lm1 <- lm(Petal.Length ~ Sepal.Width + Species, data=iris) pred1 <- fitted(lm1) RMSE(pred1, iris$Petal.Length)
Estimates confidence intervals for rlm models.
rob.ci(x, level = 0.95, maxit = 200, R = 2000)
rob.ci(x, level = 0.95, maxit = 200, R = 2000)
x |
A rlm object |
level |
Confidence level for the interval |
maxit |
Maximum number of iterations per fit |
R |
Number of boostrap samples |
A matrix with bootstrap confidence intervals for each variable in the model
Estimates p-values for rlm models.
rob.pvals(x)
rob.pvals(x)
x |
A rlm object |
A vector of p-values
Internal function for make_word_table.
set_noms(x, args)
set_noms(x, args)
x |
A flextable object |
args |
A names list with the header names |
A flextable object with assigned header names
Extract Variance-Covariance Matrix.
VarCorr(x, sigma = 1, ...)
VarCorr(x, sigma = 1, ...)
x |
A model object |
sigma |
Optional value used as a multiplier for the standard deviations |
... |
Further arguments passed to VarrCorr methods |
A Variance-Covariance Matrix