tbl_likert()
creates a summary of Likert scales following the gtsummary structure.
add_n()
adds a column to the table with the total number of observations.
add_continuous_stat()
converts Likert scales into a numeric score and computes
continuous statistics based on this score.
tbl_likert(
data,
label = NULL,
statistic = NULL,
digits = NULL,
include = everything(),
sort = c("default", "ascending", "descending")
)
# S3 method for tbl_likert
add_n(
x,
statistic = "{n}",
col_label = "**N**",
footnote = FALSE,
last = FALSE,
...
)
add_continuous_stat(x, ...)
# S3 method for tbl_likert
add_continuous_stat(
x,
statistic = "{mean}",
digits = NULL,
col_label = NULL,
footnote = FALSE,
last = TRUE,
score_values = NULL,
stat_col_name = NULL,
...
)
A data frame
List of formulas specifying variables labels,
e.g. list(age ~ "Age", stage ~ "Path T Stage")
. If a
variable's label is not specified here, the label attribute
(attr(data$age, "label")
) is used. If
attribute label is NULL
, the variable name will be used.
String or formula indicating the statistic to be reported.
Default is the mean score. Other possible continuous statistics are described
in gtsummary::tbl_summary()
help page, section statistic argument.
Formula or list of formulas indicating how to display the
computed statistics, see gtsummary::tbl_summary()
help page
variables to include in the summary table. Default is everything()
Sort table based on mean scores? Must be one of
c("default", "ascending", "descending")
Object with class tbl_likert
from the tbl_likert()
function
String indicating the column label. Default is generated
from statistic
.
Logical argument indicating whether to print a footnote
clarifying the statistics presented. Default is FALSE
Logical indicator to include the new column last in table.
Default is TRUE
not used
Vector indicating the numeric value of each factor level.
Default is 1:n
where n
indicates the number of levels.
Optional string indicating the name of the new column
added to x$table_body
Example 1
Other gtsummary-related functions:
add_inline_forest_plot()
,
add_sparkline()
,
as_ggplot()
,
bold_italicize_group_labels()
,
logistic_reg_adj_diff()
,
style_tbl_compact()
,
theme_gtsummary_msk()
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
set.seed(1123)
likert_lvls <- c("Never", "Sometimes", "Often", "Always")
df <-
tibble::tibble(
Q1 = sample(likert_lvls, size = 100, replace = TRUE),
Q2 = sample(likert_lvls, size = 100, replace = TRUE)
) %>%
mutate(across(c(Q1, Q2), ~factor(., levels = likert_lvls)))
tbl_likert_ex1 <-
tbl_likert(df) %>%
add_n() %>%
add_continuous_stat(statistic = "{mean}") %>%
add_continuous_stat(statistic = "{sd}")