Debian Codegraph @

R/betareg.R

raw
1 #' @templateVar class betareg
2 #' @template title_desc_tidy
3 #'
4 #' @param x A `betareg` object produced by a call to [betareg::betareg()].
5 #' @template param_confint
6 #' @template param_unused_dots
7 #'
8 #' @evalRd return_tidy(regression = TRUE,
9 #' component = "Whether a particular term was used to model the mean or the
10 #' precision in the regression. See details."
11 #' )
12 #'
13 #' @details The tibble has one row for each term in the regression. The
14 #' `component` column indicates whether a particular
15 #' term was used to model either the `"mean"` or `"precision"`. Here the
16 #' precision is the inverse of the variance, often referred to as `phi`.
17 #' At least one term will have been used to model the precision `phi`.
18 #'
19 #' @examplesIf rlang::is_installed("betareg")
20 #'
21 #' # load libraries for models and data
22 #' library(betareg)
23 #'
24 #' # load dats
25 #' data("GasolineYield", package = "betareg")
26 #'
27 #' # fit model
28 #' mod <- betareg(yield ~ batch + temp, data = GasolineYield)
29 #'
30 #' mod
31 #'
32 #' # summarize model fit with tidiers
33 #' tidy(mod)
34 #' tidy(mod, conf.int = TRUE)
35 #' tidy(mod, conf.int = TRUE, conf.level = .99)
36 #'
37 #' augment(mod)
38 #'
39 #' glance(mod)
40 #'
41 #' @export
42 #' @seealso [tidy()], [betareg::betareg()]
43 #' @family betareg tidiers
44 #' @aliases betareg_tidiers
45 tidy.betareg <- function(x, conf.int = FALSE, conf.level = .95, ...) {
46 check_ellipses("exponentiate", "tidy", "betareg", ...)
47
48 ret <- map_as_tidy_tibble(
49 purrr::map(coef(summary(x)), as.matrix),
50 new_names = c("estimate", "std.error", "statistic", "p.value")
51 )
52
53 if (conf.int) {
54 ci <- broom_confint_terms(x, level = conf.level)
55 ret <- dplyr::bind_cols(ret, ci[c("conf.low", "conf.high")])
56 }
57
58 as_tibble(ret)
59 }
60
61
62 #' @templateVar class betareg
63 #' @template title_desc_augment
64 #'
65 #' @inherit tidy.betareg params examples
66 #' @template param_data
67 #' @template param_newdata
68 #' @template param_type_predict
69 #' @template param_type_residuals
70 #'
71 #' @evalRd return_augment(".cooksd")
72 #'
73 #' @details For additional details on Cook's distance, see
74 #' [stats::cooks.distance()].
75 #'
76 #' @seealso [augment()], [betareg::betareg()]
77 #' @export
78 augment.betareg <- function(
79 x,
80 data = model.frame(x),
81 newdata = NULL,
82 type.predict,
83 type.residuals,
84 ...
85 ) {
86 augment_columns(
87 x,
88 data,
89 newdata,
90 type.predict = type.predict,
91 type.residuals = type.residuals
92 )
93 }
94
95
96 #' @templateVar class betareg
97 #' @template title_desc_glance
98 #'
99 #' @inherit tidy.betareg params examples
100 #' @template param_unused_dots
101 #'
102 #' @evalRd return_glance(
103 #' "pseudo.r.squared",
104 #' "df.null",
105 #' "logLik",
106 #' "AIC",
107 #' "BIC",
108 #' "df.residual",
109 #' "nobs"
110 #' )
111 #'
112 #' @seealso [glance()], [betareg::betareg()]
113 #' @export
114 glance.betareg <- function(x, ...) {
115 s <- summary(x)
116 as_glance_tibble(
117 pseudo.r.squared = s$pseudo.r.squared,
118 df.null = s$df.null,
119 logLik = as.numeric(stats::logLik(x)),
120 AIC = stats::AIC(x),
121 BIC = stats::BIC(x),
122 df.residual = stats::df.residual(x),
123 nobs = stats::nobs(x),
124 na_types = "rirrrii"
125 )
126 }