-
Notifications
You must be signed in to change notification settings - Fork 7
/
tidy_add_reference_rows.Rd
90 lines (83 loc) · 2.79 KB
/
tidy_add_reference_rows.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tidy_add_reference_rows.R
\name{tidy_add_reference_rows}
\alias{tidy_add_reference_rows}
\title{Add references rows for categorical variables}
\usage{
tidy_add_reference_rows(
x,
no_reference_row = NULL,
model = tidy_get_model(x),
quiet = FALSE
)
}
\arguments{
\item{x}{a tidy tibble}
\item{no_reference_row}{a vector indicating the name of variables
for those no reference row should be added. Accepts tidyselect notation.
Default is \code{NULL}}
\item{model}{the corresponding model, if not attached to \code{x}}
\item{quiet}{logical argument whether broom.helpers should not return a message
when requested output cannot be generated. Default is FALSE}
}
\description{
For categorical variables with a treatment contrast
(\code{\link[stats:contrast]{stats::contr.treatment()}}), a SAS contrast (\code{\link[stats:contrast]{stats::contr.SAS()}})
or a sum contrast (\code{\link[stats:contrast]{stats::contr.sum()}}), add a reference row.
}
\details{
The added \code{reference_row} column will be equal to:
\itemize{
\item \code{TRUE} for a reference row;
\item \code{FALSE} for a normal row of a variable with a reference row;
\item \code{NA} for variables without a reference row.
}
If the \code{contrasts} column is not yet available in \code{x},
\code{\link[=tidy_add_contrasts]{tidy_add_contrasts()}} will be automatically applied.
\code{tidy_add_reference_rows()} will not populate the label
of the reference term. It is therefore better to apply
\code{\link[=tidy_add_term_labels]{tidy_add_term_labels()}} after \code{tidy_add_reference_rows()}
rather than before.
}
\examples{
df <- Titanic \%>\%
dplyr::as_tibble() \%>\%
dplyr::mutate(Survived = factor(Survived, c("No", "Yes")))
df \%>\%
glm(
Survived ~ Class + Age + Sex,
data = ., weights = .$n, family = binomial,
contrasts = list(Age = contr.sum, Class = "contr.SAS")
) \%>\%
tidy_and_attach() \%>\%
tidy_add_reference_rows()
if (requireNamespace("gtsummary")) {
glm(
response ~ stage + grade * trt,
gtsummary::trial,
family = binomial,
contrasts = list(
stage = contr.treatment(4, base = 3),
grade = contr.treatment(3, base = 2),
trt = contr.treatment(2, base = 2)
)
) \%>\%
tidy_and_attach() \%>\%
tidy_add_reference_rows()
}
}
\seealso{
Other tidy_helpers:
\code{\link{tidy_add_coefficients_type}()},
\code{\link{tidy_add_contrasts}()},
\code{\link{tidy_add_estimate_to_reference_rows}()},
\code{\link{tidy_add_header_rows}()},
\code{\link{tidy_add_term_labels}()},
\code{\link{tidy_add_variable_labels}()},
\code{\link{tidy_attach_model}()},
\code{\link{tidy_identify_variables}()},
\code{\link{tidy_plus_plus}()},
\code{\link{tidy_remove_intercept}()},
\code{\link{tidy_select_variables}()}
}
\concept{tidy_helpers}