| Title: | 'SciViews::R' - Statistical Models |
|---|---|
| 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] (ORCID: <https://orcid.org/0000-0002-2694-9471>), Guyliann Engels [aut] (ORCID: <https://orcid.org/0000-0001-9514-1014>) |
| Maintainer: | Philippe Grosjean <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.4.10 |
| Built: | 2026-06-09 06:34:53 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().
Maintainer: Philippe Grosjean [email protected] (ORCID)
Authors:
Guyliann Engels [email protected] (ORCID)
Useful links:
Report bugs at https://github.com/SciViews/modelit/issues
This function attempts to compute anova or deviance tables using the
standard stats::anova() function. The original object is attached as an
attribute to the result for reference.
anova_(object, ...)anova_(object, ...)
object |
An object for which anova or deviance tables should be computed. |
... |
Additional arguments passed to the |
An anova object with an additional "object" attribute containing
the original input.
is_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) anova(is_lm) anova_(is_lm) attr(anova_(is_lm), "object")is_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) anova(is_lm) anova_(is_lm) attr(anova_(is_lm), "object")
lm_)anova.lm_() is a method for objects of class lm_, extending the standard
stats::anova() functionality.
It returns an ANOVA table similar to the base version but includes additional
metadata such as variable labels (if available), making the output more
informative for interpretation and reporting.
This method is part of the experimental lm_() modeling framework.
## S3 method for class 'lm_' anova(object, ...)## S3 method for class 'lm_' anova(object, ...)
object |
An object of class |
... |
Additional arguments passed to |
An object of class anova_, which inherits from anova and may include
a labels component if available in the original model.
data(iris) # Add labels to variables attr(iris$Sepal.Length, "label") <- "Sepal Length (cm)" attr(iris$Petal.Length, "label") <- "Petal Length (cm)" # Fit model using lm_() model <- lm_(iris, Petal.Length ~ Sepal.Length + Species) # Get ANOVA table with labels anova_model <- anova(model) anova_model # Access labels anova_model$labelsdata(iris) # Add labels to variables attr(iris$Sepal.Length, "label") <- "Sepal Length (cm)" attr(iris$Petal.Length, "label") <- "Petal Length (cm)" # Fit model using lm_() model <- lm_(iris, Petal.Length ~ Sepal.Length + Species) # Get ANOVA table with labels anova_model <- anova(model) anova_model # Access labels anova_model$labels
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:20data("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("SciViews_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("SciViews_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("SciViews_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("SciViews_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("SciViews_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("SciViews_lang", "en"), env = parent.frame() )## S3 method for class 'nls' chart( data, type = "model", ..., title, labels = "AUTO", name = deparse(substitute(data)), lang = getOption("SciViews_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("SciViews_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, swap_var_names = NULL, var_names = swap_var_names, 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, swap_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, swap_var_names = NULL, var_names = swap_var_names, 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, swap_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 |
swap_var_names |
A named character vector as |
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 <- equatiomatic::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), swap_var_names = c( weight = "Body weight [gm]", Time = "Number of days"))equation <- equatiomatic::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), swap_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.
glm_() is an experimental wrapper around the base stats::glm()
function. It behaves similarly to glm(), but enriches the returned object
with additional metadata. The order of the arguments differs from glm(),
and the function uses evaluation through svBase::prepare_data_dot and
svBase::recall_with_data_dot to support the data-dot mechanism.
glm_(data = (.), formula, ..., .data = data)glm_(data = (.), formula, ..., .data = data)
data |
A |
formula |
An object of class |
... |
Additional arguments passed to |
.data |
an alias for the |
An object of class glm_, which inherits from glm, and includes
additional components such as labels. If no additional attributes are
added, a standard glm object is returned.
data(iris) # Add labels to variables attr(iris$Sepal.Length, "label") <- "Sepal Length (cm)" attr(iris$Petal.Length, "label") <- "Petal Length (cm)" # Fit the model using lm_() res <- glm_(iris, formula = Petal.Length ~ Sepal.Length + Species) res class(res) summary(res) # Access labels res$labelsdata(iris) # Add labels to variables attr(iris$Sepal.Length, "label") <- "Sepal Length (cm)" attr(iris$Petal.Length, "label") <- "Petal Length (cm)" # Fit the model using lm_() res <- glm_(iris, formula = Petal.Length ~ Sepal.Length + Species) res class(res) summary(res) # Access labels res$labels
lm_() is an experimental wrapper around the base stats::lm() function.
It behaves similarly to lm(), but enriches the returned object with additional metadata.
The order of the arguments differs from lm(), and the function uses evaluation
through svBase::prepare_data_dot and svBase::recall_with_data_dot to support the data-dot mechanism.
lm_(data = (.), formula, ..., .data = data)lm_(data = (.), formula, ..., .data = data)
data |
A |
formula |
An object of class |
... |
Additional arguments passed to |
.data |
an alias for the |
An object of class lm_, which inherits from lm, and includes additional
components such as labels. If no additional attributes are added, a standard lm object is returned.
data(iris) # Add labels to variables attr(iris$Sepal.Length, "label") <- "Sepal Length (cm)" attr(iris$Petal.Length, "label") <- "Petal Length (cm)" # Fit the model using lm_() res <- lm_(iris, formula = Petal.Length ~ Sepal.Length + Species) . <- iris res1 <- lm_(Petal.Length ~ Sepal.Length + Species) res class(res) summary(res) # Access labels res$labelsdata(iris) # Add labels to variables attr(iris$Sepal.Length, "label") <- "Sepal Length (cm)" attr(iris$Petal.Length, "label") <- "Petal Length (cm)" # Fit the model using lm_() res <- lm_(iris, formula = Petal.Length ~ Sepal.Length + Species) . <- iris res1 <- lm_(Petal.Length ~ Sepal.Length + Species) res class(res) summary(res) # Access labels res$labels
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 exampledata(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
nls_() is an experimental wrapper around the base stats::nls()
function. It behaves similarly to glm(), but enriches the returned object
with additional metadata. The order of the arguments differs from glm(),
and the function uses evaluation through svBase::recall_with_data_dot() to support
the data-dot mechanism.
nls_(data = (.), formula, model = TRUE, ..., .data = data)nls_(data = (.), formula, model = TRUE, ..., .data = data)
data |
A |
formula |
An object of class |
model |
logical. If true, the model frame is returned as part of the object. Default is FALSE. |
... |
Additional arguments passed to |
.data |
an alias for the |
An object of class nls_, which inherits from nls, and includes
additional components such as labels. If no additional attributes are
added, a standard nls object is returned.
chick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Add labels to variables attr(chick1$weight, "label") <- "Body weight [gm]" attr(chick1$Time, "label") <- "Number of days" chick1_nls <- nls_(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) chick1_nls class(chick1_nls) summary(chick1_nls) # Access labels chick1_nlschick1 <- ChickWeight[ChickWeight$Chick == 1, ] # Add labels to variables attr(chick1$weight, "label") <- "Body weight [gm]" attr(chick1$Time, "label") <- "Number of days" chick1_nls <- nls_(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal)) chick1_nls class(chick1_nls) summary(chick1_nls) # Access labels chick1_nls
This function attempts to summarize an object using the standard base::summary()
function. The original object is attached as an attribute to the result for
reference.
summary_(object, ...)summary_(object, ...)
object |
An object to be summarized. |
... |
Additional arguments passed to the |
A summary object with an additional "object" attribute containing
the original input.
is_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) summary(is_lm) summary_(is_lm) attr(summary_(is_lm), "object")is_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) summary(is_lm) summary_(is_lm) attr(summary_(is_lm), "object")
summary.lm_() is a method for objects of class lm_, extending the standard
summary.lm() functionality.
It returns a summary object similar to summary.lm, but includes additional
metadata such as variable labels (if available), making the output more
informative for reporting and interpretation.
This method is part of the experimental lm_() modeling framework.
## S3 method for class 'lm_' summary(object, ...)## S3 method for class 'lm_' summary(object, ...)
object |
An object of class |
... |
Additional arguments passed to |
An object of class summary.lm_, which inherits from summary.lm and
includes an optional labels component if available in the original model.
data(iris) # Add labels to variables attr(iris$Sepal.Length, "label") <- "Sepal Length (cm)" attr(iris$Petal.Length, "label") <- "Petal Length (cm)" attr(iris$Species, "label") <- "Iris Species" # Fit model using lm_() model <- lm_(iris, formula = Petal.Length ~ Sepal.Length + Species) # Get summary with labels summary_model <- summary(model) summary_model # Access labels summary_model$labelsdata(iris) # Add labels to variables attr(iris$Sepal.Length, "label") <- "Sepal Length (cm)" attr(iris$Petal.Length, "label") <- "Petal Length (cm)" attr(iris$Species, "label") <- "Iris Species" # Fit model using lm_() model <- lm_(iris, formula = Petal.Length ~ Sepal.Length + Species) # Get summary with labels summary_model <- summary(model) summary_model # Access labels summary_model$labels
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 = FALSE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, footer = FALSE, lang = getOption("SciViews_lang", default = Sys.getenv("LANGUAGE", unset = "en")), ..., kind = "ft", env = parent.frame() )## S3 method for class 'glm' tabularise_coef( data, header = FALSE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, footer = FALSE, lang = getOption("SciViews_lang", default = Sys.getenv("LANGUAGE", unset = "en")), ..., kind = "ft", env = parent.frame() )
data |
A glm object |
header |
Logical. If |
title |
If |
equation |
Logical or character. Controls whether an equation is added to the table header and how parameters are used. Accepted values are:
|
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 |
footer |
If |
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 formulas (you probably do not need to change the default). |
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) # If the 'iris' dataset has labels and units, they can be used to enhance # the output table iris <- svBase::labelise(iris, self = FALSE, label = list( Sepal.Length = "Length of the sepals", Petal.Length = "Length of the petals", Species = "Species"), units = c(rep("cm", 4), NA)) iris_glm1 <- glm(data = iris, Petal.Length ~ Sepal.Length + Species) tabularise::tabularise$coef(iris_glm1)iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$coef(iris_glm) # If the 'iris' dataset has labels and units, they can be used to enhance # the output table iris <- svBase::labelise(iris, self = FALSE, label = list( Sepal.Length = "Length of the sepals", Petal.Length = "Length of the petals", Species = "Species"), units = c(rep("cm", 4), NA)) iris_glm1 <- glm(data = iris, Petal.Length ~ Sepal.Length + Species) tabularise::tabularise$coef(iris_glm1)
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 = FALSE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", default = Sys.getenv("LANGUAGE", unset = "en")), ..., kind = "ft" )## S3 method for class 'lm' tabularise_coef( data, header = FALSE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", default = Sys.getenv("LANGUAGE", unset = "en")), ..., kind = "ft" )
data |
An lm object |
header |
Logical. If |
title |
If |
equation |
Logical or character. Controls whether an equation is added to the table header and how parameters are used. Accepted values are:
|
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). |
A flextable object that you can print in different formats (HTML, LaTeX, Word, PowerPoint) or rearrange with the {flextable} functions.
data(iris) # Fit a simple linear model: Petal.Length as a function of Sepal.Length iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$coef(iris_lm) # If the 'iris' dataset has labels and units, they can be used to enhance # the output table iris <- svBase::labelise(iris, self = FALSE, label = list( Sepal.Length = "Length of the sepals", Petal.Length = "Length of the petals", Species = "Species"), units = c(rep("cm", 4), NA)) iris_lm1 <- lm(data = iris, Petal.Length ~ Sepal.Length + Species) tabularise::tabularise$coef(iris_lm1) # The same table but without showing the model equation tabularise::tabularise$coef(iris_lm, equation = FALSE) iris_lm2 <- lm(data = iris, Petal.Length ~ Sepal.Length * Species) tabularise::tabularise$coef(iris_lm2)data(iris) # Fit a simple linear model: Petal.Length as a function of Sepal.Length iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$coef(iris_lm) # If the 'iris' dataset has labels and units, they can be used to enhance # the output table iris <- svBase::labelise(iris, self = FALSE, label = list( Sepal.Length = "Length of the sepals", Petal.Length = "Length of the petals", Species = "Species"), units = c(rep("cm", 4), NA)) iris_lm1 <- lm(data = iris, Petal.Length ~ Sepal.Length + Species) tabularise::tabularise$coef(iris_lm1) # The same table but without showing the model equation tabularise::tabularise$coef(iris_lm, equation = FALSE) iris_lm2 <- lm(data = iris, Petal.Length ~ Sepal.Length * Species) tabularise::tabularise$coef(iris_lm2)
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 = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), footer = TRUE, ..., kind = "ft" )## S3 method for class 'nls' tabularise_coef( data, header = TRUE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), footer = TRUE, ..., kind = "ft" )
data |
An nls object. |
header |
If |
title |
If |
equation |
Add equation of the model to the table. 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 language to use. The default value can be set with, e.g.,
|
footer |
If |
... |
Not used |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
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, header = TRUE, title = NULL, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", default = Sys.getenv("LANGUAGE", unset = "en")), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )## S3 method for class 'summary.glm' tabularise_coef( data, header = TRUE, title = NULL, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", default = Sys.getenv("LANGUAGE", unset = "en")), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )
data |
A summary.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., |
show.signif.stars |
If |
... |
Additional arguments |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate formulas (you probably do not need to change the default). |
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, header = TRUE, title = header, equation = header, footer = FALSE, auto.labs = TRUE, origdata = NULL, labs = NULL, conf.int = FALSE, conf.level = 0.95, lang = getOption("SciViews_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft" )## S3 method for class 'summary.lm' tabularise_coef( data, header = TRUE, title = header, equation = header, footer = FALSE, auto.labs = TRUE, origdata = NULL, labs = NULL, conf.int = FALSE, conf.level = 0.95, lang = getOption("SciViews_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft" )
data |
An summary.lm object |
header |
Logical. If |
title |
If |
equation |
Logical or character. Controls whether an equation is added to the table header and how parameters are used. Accepted values are:
|
footer |
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 |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for
flextable (default).
#' @param footer If |
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 = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), footer = FALSE, show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft" )## S3 method for class 'summary.nls' tabularise_coef( data, header = TRUE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), footer = FALSE, show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft" )
data |
An nls object. |
header |
If |
title |
If |
equation |
Add equation of the model to the table. 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 language to use. The default value can be set with, e.g.,
|
footer |
If |
show.signif.stars |
If |
... |
Not used |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
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("SciViews_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft" )## S3 method for class 'anova' tabularise_default( data, header = TRUE, title = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft" )
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). |
A flextable object you can print in different form or rearrange with the {flextable} functions.
is <- data.io::read("iris", package = "datasets") is_lm1 <- lm(data = is, petal_length ~ species) library(tabularise) anova(is_lm1) |> tabularise_default() # identical anova(is_lm1) |> tabularise() # Use labels anova(is_lm1) |> tabularise(origdata = is) # alternative with anova_() in {modelit} package anova_(is_lm1) |> tabularise() is_lm2 <- lm(data = is, petal_length ~ sepal_length + species) anova(is_lm1, is_lm2) |> tabularise(origdata = is) anova_(is_lm1, is_lm2) |> tabularise()is <- data.io::read("iris", package = "datasets") is_lm1 <- lm(data = is, petal_length ~ species) library(tabularise) anova(is_lm1) |> tabularise_default() # identical anova(is_lm1) |> tabularise() # Use labels anova(is_lm1) |> tabularise(origdata = is) # alternative with anova_() in {modelit} package anova_(is_lm1) |> tabularise() is_lm2 <- lm(data = is, petal_length ~ sepal_length + species) anova(is_lm1, is_lm2) |> tabularise(origdata = is) anova_(is_lm1, is_lm2) |> tabularise()
Create a rich-formatted table from an aov object
## S3 method for class 'aov' tabularise_default(data, ...)## S3 method for class 'aov' tabularise_default(data, ...)
data |
An aov object |
... |
Additional arguments passed to |
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)
Create a rich-formatted table from a glm object
## S3 method for class 'glm' tabularise_default( data, header = FALSE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, footer = FALSE, lang = getOption("SciViews_lang", default = Sys.getenv("LANGUAGE", unset = "en")), ..., kind = "ft", env = parent.frame() )## S3 method for class 'glm' tabularise_default( data, header = FALSE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, footer = FALSE, lang = getOption("SciViews_lang", default = Sys.getenv("LANGUAGE", unset = "en")), ..., kind = "ft", env = parent.frame() )
data |
A glm object |
header |
Logical. If |
title |
If |
equation |
Logical or character. Controls whether an equation is added to the table header and how parameters are used. Accepted values are:
|
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 |
footer |
If |
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 formulas (you probably do not need to change the default). |
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) tabularise::tabularise(iris_glm, header = TRUE, footer = TRUE) tabularise::tabularise(iris_glm, header = TRUE, footer = FALSE) tabularise::tabularise(iris_glm, header = TRUE, equation = NA,footer = TRUE)iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise(iris_glm) tabularise::tabularise(iris_glm, header = TRUE, footer = TRUE) tabularise::tabularise(iris_glm, header = TRUE, footer = FALSE) tabularise::tabularise(iris_glm, header = TRUE, equation = NA,footer = TRUE)
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")## S3 method for class 'lm' tabularise_default(data, ..., kind = "ft")
data |
An lm object |
... |
Additional arguments passed to |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
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 = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), footer = TRUE, ..., kind = "ft" )## S3 method for class 'nls' tabularise_default( data, header = TRUE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), footer = TRUE, ..., kind = "ft" )
data |
An nls object. |
header |
If |
title |
If |
equation |
Add equation of the model to the table. 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 language to use. The default value can be set with, e.g.,
|
footer |
If |
... |
Not used |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
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, header = TRUE, title = NULL, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", default = Sys.getenv("LANGUAGE", unset = "en")), show.signif.stars = getOption("show.signif.stars", TRUE), footer = TRUE, ..., kind = "ft", env = parent.frame() )## S3 method for class 'summary.glm' tabularise_default( data, header = TRUE, title = NULL, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", default = Sys.getenv("LANGUAGE", unset = "en")), show.signif.stars = getOption("show.signif.stars", TRUE), footer = TRUE, ..., kind = "ft", env = parent.frame() )
data |
A summary.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., |
show.signif.stars |
If |
footer |
If |
... |
Additional arguments |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate formulas (you probably do not need to change the default). |
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)## S3 method for class 'summary.lm' tabularise_default(data, ..., footer = TRUE)
data |
A summary.lm object |
... |
Additional arguments passed to |
footer |
If |
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 = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), footer = TRUE, show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft" )## S3 method for class 'summary.nls' tabularise_default( data, header = TRUE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), footer = TRUE, show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft" )
data |
An nls object. |
header |
If |
title |
If |
equation |
Add equation of the model to the table. 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 language to use. The default value can be set with, e.g.,
|
footer |
If |
show.signif.stars |
If |
... |
Not used |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
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) growth <- data.io::read("urchin_growth", package = "data.io") growth_logis <- nls(data = growth, diameter ~ SSlogis(age, Asym, xmid, scal)) chart::chart(growth_logis) tabularise::tabularise(summary(growth_logis)) # No labels tabularise::tabularise(summary(growth_logis), origdata = growth) # with labels tabularise::tabularise(summary(growth_logis), origdata = growth, equation = FALSE, show.signif.stars = 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) growth <- data.io::read("urchin_growth", package = "data.io") growth_logis <- nls(data = growth, diameter ~ SSlogis(age, Asym, xmid, scal)) chart::chart(growth_logis) tabularise::tabularise(summary(growth_logis)) # No labels tabularise::tabularise(summary(growth_logis), origdata = growth) # with labels tabularise::tabularise(summary(growth_logis), origdata = growth, equation = FALSE, show.signif.stars = 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 = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), ..., kind = "ft", env = parent.frame() )## S3 method for class 'glm' tabularise_glance( data, header = TRUE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), ..., kind = "ft", env = parent.frame() )
data |
A glm object |
header |
Logical. If |
title |
If |
equation |
Logical or character. Controls whether an equation is added to the table header and how parameters are used. Accepted values are:
|
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 formulas (you probably do not need to change the default). |
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) tabularise::tabularise$glance(iris_glm, equation = FALSE) tabularise::tabularise$glance(iris_glm, equation = "my personal equation")iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$glance(iris_glm) tabularise::tabularise$glance(iris_glm, equation = FALSE) tabularise::tabularise$glance(iris_glm, equation = "my personal equation")
Create a rich-formatted table with the 'glance' information from an lm object.
## S3 method for class 'lm' tabularise_glance( data, header = TRUE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), ..., kind = "ft" )## S3 method for class 'lm' tabularise_glance( data, header = TRUE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), ..., kind = "ft" )
data |
An lm object |
header |
Logical. If |
title |
If |
equation |
Logical or character. Controls whether an equation is added to the table header and how parameters are used. Accepted values are:
|
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). |
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 = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), ..., kind = "ft" )## S3 method for class 'nls' tabularise_glance( data, header = TRUE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), ..., kind = "ft" )
data |
An nls object. |
header |
If |
title |
If |
equation |
Add equation of the model to the table. 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 language to use. The default value can be set with, e.g.,
|
... |
Not used |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
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, ...)## S3 method for class 'anova' tabularise_tidy(data, ...)
data |
An anova object |
... |
Additional arguments used |
A flextable object you can print in different form or rearrange with the {flextable} functions.
is <- data.io::read("iris", package = "datasets") is_lm1 <- lm(data = is, petal_length ~ species) library(tabularise) anova(is_lm1) |> tabularise_tidy() # identical anova(is_lm1) |> tabularise$tidy() # Use labels anova(is_lm1) |> tabularise$tidy(origdata = is) # alternative with anova_() in {modelit} package anova_(is_lm1) |> tabularise$tidy()is <- data.io::read("iris", package = "datasets") is_lm1 <- lm(data = is, petal_length ~ species) library(tabularise) anova(is_lm1) |> tabularise_tidy() # identical anova(is_lm1) |> tabularise$tidy() # Use labels anova(is_lm1) |> tabularise$tidy(origdata = is) # alternative with anova_() in {modelit} package anova_(is_lm1) |> tabularise$tidy()
Tidy version of the aov object into a flextable object
## S3 method for class 'aov' tabularise_tidy(data, ...)## S3 method for class 'aov' tabularise_tidy(data, ...)
data |
An aov object |
... |
Additional arguments passed to |
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("SciViews_lang", default = Sys.getenv("LANGUAGE", unset = "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("SciViews_lang", default = Sys.getenv("LANGUAGE", unset = "en")), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft", env = parent.frame() )
data |
A glm object |
header |
Logical. If |
title |
If |
equation |
Logical or character. Controls whether an equation is added to the table header and how parameters are used. Accepted values are:
|
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 |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
env |
The environment where to evaluate formulas (you probably do not need to change the default). |
A flextable object is returned. You can print it in different formats (HTML, LaTeX, Word, PowerPoint), or rearrange it with the {flextable} functions.
#' # If the 'iris' dataset has labels and units, they can be used to enhance # the output table iris <- svBase::labelise(iris, self = FALSE, label = list( Sepal.Length = "Length of the sepals", Petal.Length = "Length of the petals", Species = "Species"), units = c(rep("cm", 4), NA)) iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$tidy(iris_glm) tabularise::tabularise$tidy(iris_glm, conf.int = TRUE) tabularise::tabularise$tidy(iris_glm, conf.int = TRUE, equation = NA)#' # If the 'iris' dataset has labels and units, they can be used to enhance # the output table iris <- svBase::labelise(iris, self = FALSE, label = list( Sepal.Length = "Length of the sepals", Petal.Length = "Length of the petals", Species = "Species"), units = c(rep("cm", 4), NA)) iris_glm <- glm(data = iris, Petal.Length ~ Sepal.Length) tabularise::tabularise$tidy(iris_glm) tabularise::tabularise$tidy(iris_glm, conf.int = TRUE) tabularise::tabularise$tidy(iris_glm, conf.int = TRUE, equation = NA)
Create a rich-formatted table with the 'tidy' information from an lm object.
## S3 method for class 'lm' tabularise_tidy( data, header = TRUE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, conf.int = FALSE, conf.level = 0.95, lang = getOption("SciViews_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft" )## S3 method for class 'lm' tabularise_tidy( data, header = TRUE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, conf.int = FALSE, conf.level = 0.95, lang = getOption("SciViews_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft" )
data |
An lm object |
header |
Logical. If |
title |
If |
equation |
Logical or character. Controls whether an equation is added to the table header and how parameters are used. Accepted values are:
|
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). |
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, header = TRUE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft" )## S3 method for class 'nls' tabularise_tidy( data, header = TRUE, title = header, equation = header, auto.labs = TRUE, origdata = NULL, labs = NULL, lang = getOption("SciViews_lang", "en"), show.signif.stars = getOption("show.signif.stars", TRUE), ..., kind = "ft" )
data |
An nls object. |
header |
If |
title |
If |
equation |
Add equation of the model to the table. 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 language to use. The default value can be set with, e.g.,
|
show.signif.stars |
If |
... |
Not used |
kind |
The kind of table to produce: "tt" for tinytable, or "ft" for flextable (default). |
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")