This function controls the text which is printed to the console when one of the core marginalefffects
functions is called and the object is returned: predictions()
, comparisons()
, slopes()
, marginal_means()
, hypotheses()
, avg_predictions()
, avg_comparisons()
, avg_slopes()
.
All of those functions return standard data frames. Columns can be extracted by name, predictions(model)$estimate
, and all the usual data manipulation functions work out-of-the-box: colnames()
, head()
, subset()
, dplyr::filter()
, dplyr::arrange()
, etc.
Some of the data columns are not printed by default. You can disable pretty printing and print the full results as a standard data frame using the style
argument or by applying as.data.frame()
on the object. See examples below.
Usage
# S3 method for marginaleffects
print(
x,
digits = getOption("marginaleffects_print_digits", default = 3),
p_eps = getOption("marginaleffects_print_p_eps", default = 0.001),
topn = getOption("marginaleffects_print_topn", default = 5),
nrows = getOption("marginaleffects_print_nrows", default = 30),
ncols = getOption("marginaleffects_print_ncols", default = 30),
style = getOption("marginaleffects_print_style", default = "summary"),
...
)
Arguments
- x
An object produced by one of the
marginaleffects
package functions.- digits
The number of digits to display.
- p_eps
p values smaller than this number are printed in "<0.001" style.
- topn
The number of rows to be printed from the beginning and end of tables with more than
nrows
rows.- nrows
The number of rows which will be printed before truncation.
- ncols
The maximum number of column names to display at the bottom of the printed output.
- style
"summary" or "data.frame"
- ...
Other arguments are currently ignored.
Examples
library(marginaleffects)
mod <- lm(mpg ~ hp + am + factor(gear), data = mtcars)
p <- predictions(mod, by = c("am", "gear"))
p
#>
#> am gear Estimate Std. Error z Pr(>|z|) 2.5 % 97.5 %
#> 1 4 26.3 1.039 25.3 <0.001 24.2 28.3
#> 0 3 16.1 0.759 21.2 <0.001 14.6 17.6
#> 0 4 21.0 1.470 14.3 <0.001 18.2 23.9
#> 1 5 21.4 1.315 16.3 <0.001 18.8 24.0
#>
#> Columns: am, gear, estimate, std.error, statistic, p.value, conf.low, conf.high
#>
subset(p, am == 1)
#>
#> Estimate Std. Error z Pr(>|z|) CI low CI high
#> 26.3 1.04 25.3 <0.001 24.2 28.3
#> 21.4 1.31 16.3 <0.001 18.8 24.0
#>
#> Columns: am, gear, estimate, std.error, statistic, p.value, conf.low, conf.high
#>
print(p, style = "data.frame")
#> am gear estimate std.error statistic p.value conf.low conf.high
#> 1 1 4 26.27500 1.0392746 25.28206 5.032214e-141 24.23806 28.31194
#> 2 0 3 16.10667 0.7589789 21.22150 6.047008e-100 14.61910 17.59424
#> 3 0 4 21.05000 1.4697563 14.32210 1.592320e-46 18.16933 23.93067
#> 4 1 5 21.38000 1.3145900 16.26363 1.788333e-59 18.80345 23.95655
data.frame(p)
#> am gear estimate std.error statistic p.value conf.low conf.high
#> 1 1 4 26.27500 1.0392746 25.28206 5.032214e-141 24.23806 28.31194
#> 2 0 3 16.10667 0.7589789 21.22150 6.047008e-100 14.61910 17.59424
#> 3 0 4 21.05000 1.4697563 14.32210 1.592320e-46 18.16933 23.93067
#> 4 1 5 21.38000 1.3145900 16.26363 1.788333e-59 18.80345 23.95655