Title: | Statistical Models for 'SciViews::R' |
---|---|
Description: | Create and use statistical models (linear, general, nonlinear...) with extensions to support rich-formatted tables, equations and plots for the 'SciViews::R' dialect. |
Authors: | Philippe Grosjean [aut, cre] , Guyliann Engels [aut] |
Maintainer: | Philippe Grosjean <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.4.6 |
Built: | 2024-11-10 03:47:22 UTC |
Source: | https://github.com/SciViews/modelit |
The {modelit} package provides an extension to base R functions for model
fitting like lm()
, glm()
or nls()
with enhanced plots and utilitarian
functions.
fit_model()
creates a model_fit object that has many methods.
tabularise()
methods for lm, glm, nls, model_fit,
anova and aov objects.
chart()
methods for lm, glm, nls and model_fit objects.
as.function()
transforms an lm or nls model into a function that
can be plotted using stat_function()
.
Transform an lm or glm model that has only two variables into a function (useful for plotting, see examples).
## S3 method for class 'lm' as.function(x, ...)
## S3 method for class 'lm' as.function(x, ...)
x |
An lm or glm model |
... |
Further arguments to the method (not used for now) |
A function with argument x
that returns the values predicted by the
model for these values of x
.
data("trees", package = "datasets") trees_lm1 <- lm(Volume ~ Girth, data = trees) trees_lm2 <- lm(Volume ~ Girth + I(Girth^2), data = trees) # Compare these two models on a chart library(chart) chart(trees, Volume ~ Girth) + geom_point() + stat_function(fun = as.function(trees_lm1), col = "red") + stat_function(fun = as.function(trees_lm2), col = "blue") # The created function can also be used for easy predictions trees_fn1 <- as.function(trees_lm1) trees_fn1(10:20) # Volume for Girth 10:20
data("trees", package = "datasets") trees_lm1 <- lm(Volume ~ Girth, data = trees) trees_lm2 <- lm(Volume ~ Girth + I(Girth^2), data = trees) # Compare these two models on a chart library(chart) chart(trees, Volume ~ Girth) + geom_point() + stat_function(fun = as.function(trees_lm1), col = "red") + stat_function(fun = as.function(trees_lm2), col = "blue") # The created function can also be used for easy predictions trees_fn1 <- as.function(trees_lm1) trees_fn1(10:20) # Volume for Girth 10:20
Transforming an nls model into a function could be useful to plot or otherwise manipulate it, see examples.
## S3 method for class 'nls' as.function(x, ...)
## S3 method for class 'nls' as.function(x, ...)
x |
An nls model |
... |
Further arguments to the method (not used for now) |
A function with argument x
that returns the values predicted by the
model for these values of x
.
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(weight ~ SSlogis(Time, Asym, xmid, scal), data = chick1) # Show this on a ggplot library(ggplot2) p <- ggplot(chick1, aes(x = Time, y = weight)) + geom_point() + stat_function(fun = as.function(chick1_logis), col = "red") p # Visually compare with another model (four-parameter logistic): chick1_fpl <- nls(weight ~ SSfpl(Time, A, B, xmid, scal), data = chick1) p + stat_function(fun = as.function(chick1_fpl), col = "blue")
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(weight ~ SSlogis(Time, Asym, xmid, scal), data = chick1) # Show this on a ggplot library(ggplot2) p <- ggplot(chick1, aes(x = Time, y = weight)) + geom_point() + stat_function(fun = as.function(chick1_logis), col = "red") p # Visually compare with another model (four-parameter logistic): chick1_fpl <- nls(weight ~ SSfpl(Time, A, B, xmid, scal), data = chick1) p + stat_function(fun = as.function(chick1_fpl), col = "blue")
The methods autoplot()
or chart()
for lm or glm
objects. If type = model
(by default for chart()
), a scatterplot with the
model superimposed is produced, providing the model has only two numeric
variables (or a combination of these). The other types allow to analyze the
residuals of the model.
## S3 method for class 'lm' chart( data, type = "model", ..., origdata = NULL, title, labels = "AUTO", name = deparse(substitute(data)), lang = getOption("data.io_lang", "en"), env = parent.frame() ) autoplot.lm( object, origdata = NULL, type = c("model", "resfitted", "qqplot", "scalelocation", "cooksd", "resleverage", "cookleverage", "reshist", "resautocor"), title, xlab, ylab, ..., name = deparse(substitute(object)), lang = getOption("data.io_lang", "en"), env = parent.frame() )
## S3 method for class 'lm' chart( data, type = "model", ..., origdata = NULL, title, labels = "AUTO", name = deparse(substitute(data)), lang = getOption("data.io_lang", "en"), env = parent.frame() ) autoplot.lm( object, origdata = NULL, type = c("model", "resfitted", "qqplot", "scalelocation", "cooksd", "resleverage", "cookleverage", "reshist", "resautocor"), title, xlab, ylab, ..., name = deparse(substitute(object)), lang = getOption("data.io_lang", "en"), env = parent.frame() )
data |
A lm or glm model. |
type |
The type of plot: |
... |
Additional arguments passed to the chart.“ |
origdata |
The original dataset this model was fitted to. Only required
for |
title |
A title for the plot. If not provided, a default title is computed. |
labels |
A vector of four character strings, one for each plot done with
|
name |
The name of the model. If not provided, it is the name of the model object by default. |
lang |
The language to use for titles and labels, currently only |
env |
The environment to evaluate code. It is |
object |
Idem |
xlab |
A label for the X axis. A default label is proposed if it is not provided. |
ylab |
A label for the Y axis (with default if not provided). |
The ggplot object produced.
library(chart) data(trees, package = "datasets") trees_lm <- lm(Volume ~ Girth, data = trees) chart(trees_lm) # origdata not needed because untransformed variables # Residuals analysis chart$resfitted(trees_lm) chart$qqplot(trees_lm) chart$scalelocation(trees_lm) chart$cooksd(trees_lm) chart$resleverage(trees_lm) chart$cookleverage(trees_lm) chart$reshist(trees_lm, bins = 15) chart$resautocor(trees_lm) # The four most important residual analysis plots in one figure chart$residuals(trees_lm) trees_lm2 <- lm(Volume ~ log(Girth), data = trees) chart(trees_lm2, origdata = trees) # origdata needed, cf. transformed Girth trees_lm3 <- lm(Volume ~ Girth + Height, data = trees) # chart(trees_lm3) # Error because more than 2 variables! # Polynomial regressions work too trees_lm4 <- lm(Volume ~ I(Girth^2) + Girth, data = trees) chart(trees_lm4) # or using poly() trees_lm5 <- lm(Volume ~ poly(Girth, 3), data = trees) chart(trees_lm5, origdata = trees) # origdata required here!
library(chart) data(trees, package = "datasets") trees_lm <- lm(Volume ~ Girth, data = trees) chart(trees_lm) # origdata not needed because untransformed variables # Residuals analysis chart$resfitted(trees_lm) chart$qqplot(trees_lm) chart$scalelocation(trees_lm) chart$cooksd(trees_lm) chart$resleverage(trees_lm) chart$cookleverage(trees_lm) chart$reshist(trees_lm, bins = 15) chart$resautocor(trees_lm) # The four most important residual analysis plots in one figure chart$residuals(trees_lm) trees_lm2 <- lm(Volume ~ log(Girth), data = trees) chart(trees_lm2, origdata = trees) # origdata needed, cf. transformed Girth trees_lm3 <- lm(Volume ~ Girth + Height, data = trees) # chart(trees_lm3) # Error because more than 2 variables! # Polynomial regressions work too trees_lm4 <- lm(Volume ~ I(Girth^2) + Girth, data = trees) chart(trees_lm4) # or using poly() trees_lm5 <- lm(Volume ~ poly(Girth, 3), data = trees) chart(trees_lm5, origdata = trees) # origdata required here!
The methods autoplot()
or chart()
for nls objects. If
type = model
(by default for chart()
), a scatterplot with the model
superimposed is produced,. The other types allow to analyze the residuals of
the model.
## S3 method for class 'nls' chart( data, type = "model", ..., title, labels = "AUTO", name = deparse(substitute(data)), lang = getOption("data.io_lang", "en"), env = parent.frame() ) autoplot.nls( object, type = c("model", "resfitted", "qqplot", "scalelocation", "reshist", "resautocor"), title, xlab, ylab, ..., name = deparse(substitute(object)), lang = getOption("data.io_lang", "en"), env = parent.frame() )
## S3 method for class 'nls' chart( data, type = "model", ..., title, labels = "AUTO", name = deparse(substitute(data)), lang = getOption("data.io_lang", "en"), env = parent.frame() ) autoplot.nls( object, type = c("model", "resfitted", "qqplot", "scalelocation", "reshist", "resautocor"), title, xlab, ylab, ..., name = deparse(substitute(object)), lang = getOption("data.io_lang", "en"), env = parent.frame() )
data |
A nls model. |
type |
The type of plot: |
... |
Additional arguments passed to the chart. |
title |
A title for the plot. If not provided, a default title is computed. |
labels |
A vector of four character strings, one for each plot done with
|
name |
The name of the model. If not provided, it is the name of the model object by default. |
lang |
The language to use for titles and labels, currently only |
env |
The environment to evaluate code. It is |
object |
Idem |
xlab |
A label for the X axis. A default label is proposed if it is not provided. |
ylab |
A label for the Y axis (with default if not provided). |
The ggplot object produced.
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(weight ~ SSlogis(Time, Asym, xmid, scal), data = chick1) library(chart) chart(chick1_logis) # Residuals analysis chart$resfitted(chick1_logis) chart$qqplot(chick1_logis) chart$scalelocation(chick1_logis) chart$reshist(chick1_logis, bins = 15) chart$resautocor(chick1_logis) # The four most important residual analysis plots in one figure chart$residuals(chick1_logis)
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(weight ~ SSlogis(Time, Asym, xmid, scal), data = chick1) library(chart) chart(chick1_logis) # Residuals analysis chart$resfitted(chick1_logis) chart$qqplot(chick1_logis) chart$scalelocation(chick1_logis) chart$reshist(chick1_logis, bins = 15) chart$resautocor(chick1_logis) # The four most important residual analysis plots in one figure chart$residuals(chick1_logis)
Create the model equation of several self-starting nonlinear models available in the stats package.
## S3 method for class 'nls' equation( object, ital_vars = FALSE, use_coefs = FALSE, coef_digits = 2L, fix_signs = TRUE, var_names = NULL, op_latex = c("\\cdot", "\\times"), ... ) ## S3 method for class 'summary.nls' equation( object, ital_vars = FALSE, use_coefs = FALSE, coef_digits = 2L, fix_signs = TRUE, var_names = NULL, op_latex = c("\\cdot", "\\times"), ... )
## S3 method for class 'nls' equation( object, ital_vars = FALSE, use_coefs = FALSE, coef_digits = 2L, fix_signs = TRUE, var_names = NULL, op_latex = c("\\cdot", "\\times"), ... ) ## S3 method for class 'summary.nls' equation( object, ital_vars = FALSE, use_coefs = FALSE, coef_digits = 2L, fix_signs = TRUE, var_names = NULL, op_latex = c("\\cdot", "\\times"), ... )
object |
An nls or summary.nls object. |
ital_vars |
Logical, defaults to |
use_coefs |
Logical, defaults to |
coef_digits |
Integer, defaults to 2. The number of decimal places to
round to when displaying model estimates with |
fix_signs |
Logical, defaults to |
var_names |
A named character vector as |
op_latex |
The LaTeX product operator character to use in fancy
scientific notation, either |
... |
Additional arguments (not used yet). |
A character string with a LaTeX equation.
equation <- tabularise::equation chick1 <- ChickWeight[ChickWeight$Chick == 1, ] chick1_nls <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) summary(chick1_nls) equation(chick1_nls) equation(summary(chick1_nls)) chick1_nls2 <- nls(data = chick1, weight ~ SSlogis(Time, Asym = A, xmid = x, scal = scale)) summary(chick1_nls2) equation(chick1_nls2) equation(summary(chick1_nls2)) equation(summary(chick1_nls2), var_names = c( weight = "Body weight [gm]", Time = "Number of days"))
equation <- tabularise::equation chick1 <- ChickWeight[ChickWeight$Chick == 1, ] chick1_nls <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) summary(chick1_nls) equation(chick1_nls) equation(summary(chick1_nls)) chick1_nls2 <- nls(data = chick1, weight ~ SSlogis(Time, Asym = A, xmid = x, scal = scale)) summary(chick1_nls2) equation(chick1_nls2) equation(summary(chick1_nls2)) equation(summary(chick1_nls2), var_names = c( weight = "Body weight [gm]", Time = "Number of days"))
fit_model()
takes a model_spec object from {parsnip} and
it fits is. Then, usual methods like summary()
, or coef()
can be applied
directly on it, while it can still be used as the {tidymodels} recommends it.
fit_model(data, formula, ..., type = NULL, env = parent.frame()) ## S3 method for class 'model_fit' summary(object, ...) ## S3 method for class 'model_fit' anova(object, ...) ## S3 method for class 'model_fit' plot(x, y, ...) ## S3 method for class 'model_fit' chart(data, ..., type = "model", env = parent.frame()) ## S3 method for class 'model_fit' as.function(x, ...) ## S3 method for class 'model_fit' coef(object, ...) ## S3 method for class 'model_fit' vcov(object, ...) ## S3 method for class 'model_fit' confint(object, parm, level = 0.95, ...) ## S3 method for class 'model_fit' fitted(object, ...) ## S3 method for class 'model_fit' residuals(object, ...) ## S3 method for class 'model_fit' rstandard(model, ...) ## S3 method for class 'model_fit' cooks.distance(model, ...) ## S3 method for class 'model_fit' hatvalues(model, ...) ## S3 method for class 'model_fit' deviance(object, ...) ## S3 method for class 'model_fit' AIC(object, ..., k = 2) ## S3 method for class 'model_fit' BIC(object, ...) ## S3 method for class 'model_fit' family(object, ...) ## S3 method for class 'model_fit' nobs(object, ...) ## S3 method for class 'model_fit' formula(x, ...) ## S3 method for class 'model_fit' variable.names(object, ...) ## S3 method for class 'model_fit' labels(object, ...)
fit_model(data, formula, ..., type = NULL, env = parent.frame()) ## S3 method for class 'model_fit' summary(object, ...) ## S3 method for class 'model_fit' anova(object, ...) ## S3 method for class 'model_fit' plot(x, y, ...) ## S3 method for class 'model_fit' chart(data, ..., type = "model", env = parent.frame()) ## S3 method for class 'model_fit' as.function(x, ...) ## S3 method for class 'model_fit' coef(object, ...) ## S3 method for class 'model_fit' vcov(object, ...) ## S3 method for class 'model_fit' confint(object, parm, level = 0.95, ...) ## S3 method for class 'model_fit' fitted(object, ...) ## S3 method for class 'model_fit' residuals(object, ...) ## S3 method for class 'model_fit' rstandard(model, ...) ## S3 method for class 'model_fit' cooks.distance(model, ...) ## S3 method for class 'model_fit' hatvalues(model, ...) ## S3 method for class 'model_fit' deviance(object, ...) ## S3 method for class 'model_fit' AIC(object, ..., k = 2) ## S3 method for class 'model_fit' BIC(object, ...) ## S3 method for class 'model_fit' family(object, ...) ## S3 method for class 'model_fit' nobs(object, ...) ## S3 method for class 'model_fit' formula(x, ...) ## S3 method for class 'model_fit' variable.names(object, ...) ## S3 method for class 'model_fit' labels(object, ...)
data |
A data frame (or a model_fit object for |
formula |
A formula specifying a model |
... |
Further arguments passed to the method |
type |
The type of model fitting, specified by a model_spec object or the name of such an object in a string |
env |
The environment where to evaluate |
object |
A model_fit object |
x |
Idem |
y |
Not used here |
parm |
Specification of parameters for the confidence intervals (vector of numbers or of names). If missing, all parameters are considered. |
level |
Confidence level required. |
model |
Idem |
k |
The penalty per parameter to be used in the AIC (by default, |
A model_fit object.
library(parsnip) data(trees, package = "datasets") # Take the habit to prefix your regression model specs by `reg_` reg_lm <- linear_reg(mod = "regression", engine = "lm") trees_fit <- fit_model$reg_lm(data = trees, Volume ~ Girth) # You can use summary(), AIC(), anova(), tidy(), glance(), etc. directly summary(trees_fit) anova(trees_fit) AIC(trees_fit) coef(trees_fit) library(chart) chart(trees_fit) # etc.
library(parsnip) data(trees, package = "datasets") # Take the habit to prefix your regression model specs by `reg_` reg_lm <- linear_reg(mod = "regression", engine = "lm") trees_fit <- fit_model$reg_lm(data = trees, Volume ~ Girth) # You can use summary(), AIC(), anova(), tidy(), glance(), etc. directly summary(trees_fit) anova(trees_fit) AIC(trees_fit) coef(trees_fit) library(chart) chart(trees_fit) # etc.
add_predictions()
and add_residuals()
are pipe-friendly
functions to add predictions or residuals to a data frame.
geom_ref_line()
adds a vertical of horizontal reference line. rmse()
(the root-mean-squared-error), [mae[]] (the mean absolute error), qae()
(the quantiles of absolute error) and rsquare()
(the variance of the
predictions divided by the variance of the response) are useful model
metrics.
add_predictions(data, model, var = "pred", type = NULL) add_residuals(data, model, var = "resid") geom_ref_line(h, v, color = "red", colour = color, size = 1) rmse(model, data) mae(model, data) qae(model, data, probs = c(0.05, 0.25, 0.5, 0.75, 0.95)) rsquare(model, data)
add_predictions(data, model, var = "pred", type = NULL) add_residuals(data, model, var = "resid") geom_ref_line(h, v, color = "red", colour = color, size = 1) rmse(model, data) mae(model, data) qae(model, data, probs = c(0.05, 0.25, 0.5, 0.75, 0.95)) rsquare(model, data)
data |
A data frame |
model |
A model that has a |
var |
A string with the name of the predictions or residuals variable
(by default, it is |
type |
If the model's |
h |
Position of the horizontal reference line |
v |
Position of the vertical reference line |
color |
The color of the reference line |
colour |
Same as above (use the one you prefer) |
size |
The width of the reference line |
probs |
A numeric vector of probabilities |
A function with argument x
that returns the values predicted by the
model for these values of x
.
data(trees, package = "datasets") trees_lm <- lm(Volume ~ Girth + I(Girth^2), data = trees) rmse(trees_lm, trees) rsquare(trees_lm, trees) mae(trees_lm, trees) qae(trees_lm, trees, probs = c(0, 0.25, 0.5, 0.75, 1)) # Resids five numbers add_predictions(trees, trees_lm) add_residuals(trees, trees_lm) library(chart) chart(trees_lm) + geom_ref_line(h = 0) # Not particularly useful here, just an example
data(trees, package = "datasets") trees_lm <- lm(Volume ~ Girth + I(Girth^2), data = trees) rmse(trees_lm, trees) rsquare(trees_lm, trees) mae(trees_lm, trees) qae(trees_lm, trees, probs = c(0, 0.25, 0.5, 0.75, 1)) # Resids five numbers add_predictions(trees, trees_lm) add_residuals(trees, trees_lm) library(chart) chart(trees_lm) + geom_ref_line(h = 0) # Not particularly useful here, just an example
Extract and format the table of coefficients from a glm object, similar
to stats::coef()
, but in a rich-formatted flextable object.
## S3 method for class 'glm' tabularise_coef( data, header = TRUE, title = NULL, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'glm' tabularise_coef( data, header = TRUE, title = NULL, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
data |
A glm object |
header |
If |
title |
If |
equation |
If |
auto.labs |
If |
origdata |
The original data set this model was fitted to. By default it
is |
labs |
Labels to change the names of elements in the |
lang |
The natural language to use. The default value can be set with,
e.g., |
... |
Additional arguments (not used yet). |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate lazyeval expressions (unused for now). |
A flextable object is returned. You can print it in different formats (HTML, LaTeX, Word, PowerPoint) or rearrange it with the {flextable} functions.
iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$coef(iris_glm)
iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$coef(iris_glm)
This function extracts and formats the table of coefficients from an lm
object, similar to stats::coef()
, but in a rich-formatted table using
{flextable}.
## S3 method for class 'lm' tabularise_coef( data, header = TRUE, title = NULL, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'lm' tabularise_coef( data, header = TRUE, title = NULL, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
data |
An lm object |
header |
If |
title |
If |
equation |
If |
auto.labs |
If |
origdata |
The original data set this model was fitted to. By default it
is |
labs |
Labels to change the names of elements in the |
lang |
The natural language to use. The default value can be set with,
e.g., |
... |
Additional arguments |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate lazyeval expressions (unused for now). |
A flextable object that you can print in different formats (HTML, LaTeX, Word, PowerPoint) or rearrange with the {flextable} functions.
iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$coef(iris_lm)
iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$coef(iris_lm)
This method extracts and formats the coefficients from an nls object,
similar to stats::coef()
, but in flextable object.
## S3 method for class 'nls' tabularise_coef( data, header = TRUE, title = NULL, equation = header, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'nls' tabularise_coef( data, header = TRUE, title = NULL, equation = header, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
data |
An nls object. |
header |
If |
title |
If |
equation |
If |
lang |
The language to use. The default value can be set with, e.g.,
|
... |
Additional arguments. |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate lazyeval expressions (unused for now). |
A flextable object that you can print in different forms or rearrange with the {flextable} functions.
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) tabularise::tabularise$coef(chick1_logis)
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) tabularise::tabularise$coef(chick1_logis)
Create a rich-formatted {flextable} object with the table of coefficients
from the summary()
of a glm object.
## S3 method for class 'summary.glm' tabularise_coef(data, ..., kind = "ft", env = parent.frame())
## S3 method for class 'summary.glm' tabularise_coef(data, ..., kind = "ft", env = parent.frame())
data |
A summary.glm object |
... |
Additional arguments passed to |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate the model. |
A flextable object that you can print in different formats (HTML, LaTeX, Word, PowerPoint) or rearrange with the {flextable} functions.
iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) iris_glm_sum <- summary(iris_glm) tabularise::tabularise$coef(iris_glm_sum)
iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) iris_glm_sum <- summary(iris_glm) tabularise::tabularise$coef(iris_glm_sum)
Create a rich-formatted table using the table of coefficients of the summary.lm object
## S3 method for class 'summary.lm' tabularise_coef(data, ..., kind = "ft", env = parent.frame())
## S3 method for class 'summary.lm' tabularise_coef(data, ..., kind = "ft", env = parent.frame())
data |
A summary.lm object |
... |
Additional arguments passed to |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate the model. |
A flextable object you can print in different formats (HTML, LaTeX, Word, PowerPoint) or rearrange with the {flextable} functions.
iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) iris_lm_sum <- summary(iris_lm) tabularise::tabularise$coef(iris_lm_sum)
iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) iris_lm_sum <- summary(iris_lm) tabularise::tabularise$coef(iris_lm_sum)
This function extracts and formats the table of coefficients from a
summary.nls object, similar to stats::coef()
, but in flextable object.
## S3 method for class 'summary.nls' tabularise_coef( data, header = TRUE, title = NULL, equation = header, lang = getOption("data.io_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'summary.nls' tabularise_coef( data, header = TRUE, title = NULL, equation = header, lang = getOption("data.io_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )
data |
A summary.nls object. |
header |
If |
title |
If |
equation |
Add equation of the model to the table. If |
lang |
The language to use. The default value can be set with, e.g.,
|
show.signif.stars |
If |
... |
Additional arguments passed to |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate lazyeval expressions (unused for now). |
A flextable object that you can print in different forms or rearrange with the {flextable} functions.
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) chick1_logis_sum <- summary(chick1_logis) tabularise::tabularise$coef(chick1_logis_sum) tabularise::tabularise$coef(chick1_logis_sum, header = FALSE, equation = TRUE)
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) chick1_logis_sum <- summary(chick1_logis) tabularise::tabularise$coef(chick1_logis_sum) tabularise::tabularise$coef(chick1_logis_sum, header = FALSE, equation = TRUE)
Create a rich-formatted table from an anova object
## S3 method for class 'anova' tabularise_default( data, header = TRUE, title = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("data.io_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'anova' tabularise_default( data, header = TRUE, title = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("data.io_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )
data |
An anova object |
header |
If |
title |
If |
auto.labs |
If |
origdata |
The original data set used for the ANOVA. By default it is
|
labs |
Labels to change the default names in the |
lang |
The natural language to use. The default value is set with,
e.g., |
show.signif.stars |
If |
... |
Additional arguments (not used for now) |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate lazyeval expressions (not used for now) |
A flextable object you can print in different form or rearrange with the {flextable} functions.
iris_anova <- anova(lm(data = iris, Petal.Length ~ Species)) tabularise::tabularise(iris_anova)
iris_anova <- anova(lm(data = iris, Petal.Length ~ Species)) tabularise::tabularise(iris_anova)
Create a rich-formatted table from a glm object
## S3 method for class 'glm' tabularise_default( data, footer = TRUE, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'glm' tabularise_default( data, footer = TRUE, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
data |
A glm object |
footer |
If |
lang |
The natural language to use. The default value can be set with,
e.g., |
... |
Additional arguments passed to |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate the model. |
A flextable object is returned. You can print it in different formats (HTML, LaTeX, Word, PowerPoint) or rearrange it with the {flextable} functions.
iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise(iris_glm)
iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise(iris_glm)
The default tabularise()
method for lm objects create a minimalist
table with result of the analysis in a rich-formatted tabular presentation.
## S3 method for class 'lm' tabularise_default(data, ..., kind = "ft", env = parent.frame())
## S3 method for class 'lm' tabularise_default(data, ..., kind = "ft", env = parent.frame())
data |
An lm object |
... |
Additional arguments passed to |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate the model. |
A flextable object that you can print in different formats (HTML, LaTeX, Word, PowerPoint) or rearrange with the {flextable} functions.
iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise(iris_lm)
iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise(iris_lm)
This method extracts and formats an nls object, similar to print()
, but
in flextable object.
## S3 method for class 'nls' tabularise_default( data, header = TRUE, title = NULL, equation = header, footer = TRUE, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'nls' tabularise_default( data, header = TRUE, title = NULL, equation = header, footer = TRUE, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
data |
An nls object. |
header |
If |
title |
If |
equation |
Add equation of the model to the table. If |
footer |
If |
lang |
The language to use. The default value can be set with, e.g.,
|
... |
Additional arguments. Not used. |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate lazyeval expressions (unused for now). |
A flextable object that you can print in different forms or rearrange with the {flextable} functions.
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) tabularise::tabularise(chick1_logis)
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) tabularise::tabularise(chick1_logis)
Create a rich-formatted table version of the summary()
of a glm object.
## S3 method for class 'summary.glm' tabularise_default( data, footer = TRUE, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'summary.glm' tabularise_default( data, footer = TRUE, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
data |
A summary.glm object |
footer |
If |
lang |
The natural language to use. The default value can be set with,
e.g., |
... |
Additional arguments passed to |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate the model. |
A flextable object that you can print in different form or rearrange with the {flextable} functions.
iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) iris_glm_sum <- summary(iris_glm) tabularise::tabularise(iris_glm_sum)
iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) iris_glm_sum <- summary(iris_glm) tabularise::tabularise(iris_glm_sum)
Create a rich-formatted table from an summary.lm object
## S3 method for class 'summary.lm' tabularise_default( data, footer = TRUE, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'summary.lm' tabularise_default( data, footer = TRUE, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
data |
A summary.lm object |
footer |
If |
lang |
The natural language to use. The default value can be set with,
e.g., |
... |
Additional arguments passed to |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate the model. |
A flextable object you can print in different formats (HTML, LaTeX, Word, PowerPoint) or rearrange with the {flextable} functions.
iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) iris_lm_sum <- summary(iris_lm) tabularise::tabularise(iris_lm_sum)
iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) iris_lm_sum <- summary(iris_lm) tabularise::tabularise(iris_lm_sum)
Create a table of a summary.nls object. This table looks like the output
of print.summary.nls()
but richly formatted. The tabularise_coef()
function offers more customization options for this object.
## S3 method for class 'summary.nls' tabularise_default( data, header = TRUE, title = NULL, equation = header, footer = TRUE, lang = getOption("data.io_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'summary.nls' tabularise_default( data, header = TRUE, title = NULL, equation = header, footer = TRUE, lang = getOption("data.io_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )
data |
A summary.nls object. |
header |
If |
title |
If |
equation |
Add equation of the model to the table. If |
footer |
If |
lang |
The language to use. The default value can be set with, e.g.
|
show.signif.stars |
If |
... |
Additional arguments (Not used). |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate lazyeval expressions (unused for now). |
A flextable object that you can print in different forms or rearrange with the {flextable} functions.
tabularise::tabularise()
, tabularise::tabularise_tidy()
,
tabularise_coef.summary.nls()
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) chick1_logis_sum <- summary(chick1_logis) tabularise::tabularise(chick1_logis_sum) tabularise::tabularise(chick1_logis_sum, footer = FALSE)
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) chick1_logis_sum <- summary(chick1_logis) tabularise::tabularise(chick1_logis_sum) tabularise::tabularise(chick1_logis_sum, footer = FALSE)
Turn the glance of glm object into a rich-formatted table with {flextable}. The table can be printed in different formats (HTML, LaTeX, Word, PowerPoint), or rearranged later on.
## S3 method for class 'glm' tabularise_glance( data, header = TRUE, title = NULL, equation = TRUE, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'glm' tabularise_glance( data, header = TRUE, title = NULL, equation = TRUE, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
data |
A glm object |
header |
If |
title |
If |
equation |
If |
auto.labs |
If |
origdata |
The original data set this model was fitted to. By default it
is |
labs |
Labels to change the names of elements in the |
lang |
The natural language to use. The default value can be set with,
e.g., |
... |
Additional arguments passed to |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate lazyeval expressions (unused for now). |
A flextable object is produced that you can print in different formats (HTML, LaTeX, Word, PowerPoint) or rearrange with the {flextable} functions.
iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$glance(iris_glm)
iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$glance(iris_glm)
Create a rich-formatted table with the 'glance' information from an lm object.
## S3 method for class 'lm' tabularise_glance( data, header = TRUE, title = NULL, equation = TRUE, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'lm' tabularise_glance( data, header = TRUE, title = NULL, equation = TRUE, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
data |
An lm object |
header |
If |
title |
If |
equation |
If |
auto.labs |
If |
origdata |
The original data set this model was fitted to. By default it
is |
labs |
Labels to change the names of elements in the |
lang |
The natural language to use. The default value can be set with,
e.g., |
... |
Additional arguments passed to |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate lazyeval expressions (unused for now). |
A flextable object that you can print in different form or rearrange with the {flextable} functions.
iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$glance(iris_lm)
iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$glance(iris_lm)
Extract the information contained in an nls object in a table as it could
be obtained by broom::glance()
. Here, the table is nicely formatted as an
(almost) publication-ready form (good for informal reports, notebooks, etc).
## S3 method for class 'nls' tabularise_glance( data, header = TRUE, title = NULL, equation = header, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'nls' tabularise_glance( data, header = TRUE, title = NULL, equation = header, lang = getOption("data.io_lang", "en"), ..., kind = "ft", env = parent.frame() )
data |
An nls object. |
header |
If |
title |
If |
equation |
Add equation of the model to the table. If |
lang |
The language to use. The default value can be set with, e.g.,
|
... |
Additional arguments passed to |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate lazyeval expressions (unused for now). |
A flextable object that you can print in different forms or rearrange with the {flextable} functions.
tabularise::tabularise_glance()
, tabularise_coef.summary.nls()
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) tabularise::tabularise$glance(chick1_logis) tabularise::tabularise$glance(chick1_logis, lang = "fr")
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) tabularise::tabularise$glance(chick1_logis) tabularise::tabularise$glance(chick1_logis, lang = "fr")
Tidy version of the anova object into a flextable object
## S3 method for class 'anova' tabularise_tidy( data, header = TRUE, title = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("data.io_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'anova' tabularise_tidy( data, header = TRUE, title = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("data.io_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )
data |
An anova object |
header |
If |
title |
If |
auto.labs |
If |
origdata |
The original data set used for the ANOVA (used for changing
the labels). By default, it is |
labs |
Labels to use to change the names of elements in the |
lang |
The natural language to use. The default value can be set with,
e.g., |
show.signif.stars |
If |
... |
Additional arguments (not used for now) |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate lazyeval expressions (not used for now) |
A flextable object you can print in different form or rearrange with the {flextable} functions.
iris_anova <- anova(lm(data = iris, Petal.Length ~ Species)) tabularise::tabularise$tidy(iris_anova)
iris_anova <- anova(lm(data = iris, Petal.Length ~ Species)) tabularise::tabularise$tidy(iris_anova)
Tidy version of the aov object into a flextable object
## S3 method for class 'aov' tabularise_tidy(data, ..., kind = "ft", env = parent.frame())
## S3 method for class 'aov' tabularise_tidy(data, ..., kind = "ft", env = parent.frame())
data |
An anova object |
... |
Additional arguments passed to |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate the object. |
flextable object you can print in different form or rearrange with the {flextable} functions.
iris_aov <- aov(data = iris, Petal.Length ~ Species) tabularise::tabularise$tidy(iris_aov)
iris_aov <- aov(data = iris, Petal.Length ~ Species) tabularise::tabularise$tidy(iris_aov)
Turn the tidy of glm object into a rich-formatted table with {flextable}. The table can be printed in different formats (HTML, LaTeX, Word, PowerPoint), or rearranged later on.
## S3 method for class 'glm' tabularise_tidy( data, header = TRUE, title = NULL, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, conf.int = FALSE, conf.level = 0.95, lang = getOption("data.io_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'glm' tabularise_tidy( data, header = TRUE, title = NULL, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, conf.int = FALSE, conf.level = 0.95, lang = getOption("data.io_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )
data |
A glm object |
header |
If |
title |
If |
equation |
If |
auto.labs |
If |
origdata |
The original data set this model was fitted to. By default it
is |
labs |
Labels to change the names of elements in the |
conf.int |
If |
conf.level |
The confidence level to use for the confidence interval if
|
lang |
The natural language to use. The default value can be set with,
e.g., |
show.signif.stars |
If |
... |
Additional arguments passed to |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate lazyeval expressions (unused for now). |
A flextable object is returned. You can print it in different formats (HTML, LaTeX, Word, PowerPoint), or rearrange it with the {flextable} functions.
iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$tidy(iris_glm)
iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$tidy(iris_glm)
Create a rich-formatted table with the 'tidy' information from an lm object.
## S3 method for class 'lm' tabularise_tidy( data, header = TRUE, title = NULL, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, conf.int = FALSE, conf.level = 0.95, lang = getOption("data.io_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )
## S3 method for class 'lm' tabularise_tidy( data, header = TRUE, title = NULL, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, conf.int = FALSE, conf.level = 0.95, lang = getOption("data.io_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )
data |
An lm object |
header |
If |
title |
If |
equation |
If |
auto.labs |
If |
origdata |
The original data set this model was fitted to. By default it
is |
labs |
Labels to change the names of elements in the |
conf.int |
If |
conf.level |
The confidence level to use for the confidence interval if
|
lang |
The natural language to use. The default value can be set with,
e.g., |
show.signif.stars |
If |
... |
Additional arguments passed to |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate lazyeval expressions (unused for now). |
A flextable object that you can print in different formats (HTML, LaTeX, Word, PowerPoint) or rearrange with the {flextable} functions.
iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$tidy(iris_lm)
iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$tidy(iris_lm)
Extract the information contained in a nls object into a rectangular table as
it could be obtained by broom::tidy()
. Here, the table is nicely
formatted as an (almost) publication-ready form (good for informal reports,
notebooks, etc).
## S3 method for class 'nls' tabularise_tidy(data, ..., kind = "ft", env = parent.frame())
## S3 method for class 'nls' tabularise_tidy(data, ..., kind = "ft", env = parent.frame())
data |
A nls object |
... |
arguments of |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate lazyeval expressions (unused for now). |
A flextable object that you can print in different forms or rearrange with the {flextable} functions.
tabularise::tabularise()
, tabularise::tabularise_tidy()
,
tabularise_coef.summary.nls()
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) tabularise::tabularise$tidy(chick1_logis) tabularise::tabularise$tidy(chick1_logis, lang = "fr")
data("ChickWeight", package = "datasets") chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Adjust a logistic curve chick1_logis <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) tabularise::tabularise$tidy(chick1_logis) tabularise::tabularise$tidy(chick1_logis, lang = "fr")