Debian Codegraph @

man/tidy.gmm.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/gmm.R
3 \name{tidy.gmm}
4 \alias{tidy.gmm}
5 \alias{gmm_tidiers}
6 \title{Tidy a(n) gmm object}
7 \usage{
8 \method{tidy}{gmm}(x, conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE, ...)
9 }
10 \arguments{
11 \item{x}{A \code{gmm} object returned from \code{\link[gmm:gmm]{gmm::gmm()}}.}
12
13 \item{conf.int}{Logical indicating whether or not to include a confidence
14 interval in the tidied output. Defaults to \code{FALSE}.}
15
16 \item{conf.level}{The confidence level to use for the confidence interval
17 if \code{conf.int = TRUE}. Must be strictly greater than 0 and less than 1.
18 Defaults to 0.95, which corresponds to a 95 percent confidence interval.}
19
20 \item{exponentiate}{Logical indicating whether or not to exponentiate the
21 the coefficient estimates. This is typical for logistic and multinomial
22 regressions, but a bad idea if there is no log or logit link. Defaults
23 to \code{FALSE}.}
24
25 \item{...}{Additional arguments. Not used. Needed to match generic
26 signature only. \strong{Cautionary note:} Misspelled arguments will be
27 absorbed in \code{...}, where they will be ignored. If the misspelled
28 argument has a default value, the default value will be used.
29 For example, if you pass \code{conf.lvel = 0.9}, all computation will
30 proceed using \code{conf.level = 0.95}. Two exceptions here are:
31 \itemize{
32 \item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if
33 it will be ignored.
34 \item \code{augment()} methods will warn when supplied a \code{newdata} argument if it
35 will be ignored.
36 }}
37 }
38 \description{
39 Tidy summarizes information about the components of a model.
40 A model component might be a single term in a regression, a single
41 hypothesis, a cluster, or a class. Exactly what tidy considers to be a
42 model component varies across models but is usually self-evident.
43 If a model has several distinct types of components, you will need to
44 specify which components to return.
45 }
46 \examples{
47 \dontshow{if (rlang::is_installed(c("gmm", "ggplot2"))) withAutoprint(\{ # examplesIf}
48
49 # load libraries for models and data
50 library(gmm)
51
52 # examples come from the "gmm" package
53 # CAPM test with GMM
54 data(Finance)
55 r <- Finance[1:300, 1:10]
56 rm <- Finance[1:300, "rm"]
57 rf <- Finance[1:300, "rf"]
58
59 z <- as.matrix(r - rf)
60 t <- nrow(z)
61 zm <- rm - rf
62 h <- matrix(zm, t, 1)
63 res <- gmm(z ~ zm, x = h)
64
65 # tidy result
66 tidy(res)
67 tidy(res, conf.int = TRUE)
68 tidy(res, conf.int = TRUE, conf.level = .99)
69
70 # coefficient plot
71 library(ggplot2)
72 library(dplyr)
73
74 tidy(res, conf.int = TRUE) |>
75 mutate(variable = reorder(term, estimate)) |>
76 ggplot(aes(estimate, variable)) +
77 geom_point() +
78 geom_errorbarh(aes(xmin = conf.low, xmax = conf.high)) +
79 geom_vline(xintercept = 0, color = "red", lty = 2)
80
81 # from a function instead of a matrix
82 g <- function(theta, x) {
83 e <- x[, 2:11] - theta[1] - (x[, 1] - theta[1]) \%*\% matrix(theta[2:11], 1, 10)
84 gmat <- cbind(e, e * c(x[, 1]))
85 return(gmat)
86 }
87
88 x <- as.matrix(cbind(rm, r))
89 res_black <- gmm(g, x = x, t0 = rep(0, 11))
90
91 tidy(res_black)
92 tidy(res_black, conf.int = TRUE)
93
94 # APT test with Fama-French factors and GMM
95
96 f1 <- zm
97 f2 <- Finance[1:300, "hml"] - rf
98 f3 <- Finance[1:300, "smb"] - rf
99 h <- cbind(f1, f2, f3)
100 res2 <- gmm(z ~ f1 + f2 + f3, x = h)
101
102 td2 <- tidy(res2, conf.int = TRUE)
103 td2
104
105 # coefficient plot
106 td2 |>
107 mutate(variable = reorder(term, estimate)) |>
108 ggplot(aes(estimate, variable)) +
109 geom_point() +
110 geom_errorbarh(aes(xmin = conf.low, xmax = conf.high)) +
111 geom_vline(xintercept = 0, color = "red", lty = 2)
112 \dontshow{\}) # examplesIf}
113 }
114 \seealso{
115 \code{\link[=tidy]{tidy()}}, \code{\link[gmm:gmm]{gmm::gmm()}}
116
117 Other gmm tidiers:
118 \code{\link{glance.gmm}()}
119 }
120 \concept{gmm tidiers}
121 \value{
122 A \code{\link[tibble:tibble]{tibble::tibble()}} with columns:
123 \item{conf.high}{Upper bound on the confidence interval for the estimate.}
124 \item{conf.low}{Lower bound on the confidence interval for the estimate.}
125 \item{estimate}{The estimated value of the regression term.}
126 \item{p.value}{The two-sided p-value associated with the observed statistic.}
127 \item{statistic}{The value of a T-statistic to use in a hypothesis that the regression term is non-zero.}
128 \item{std.error}{The standard error of the regression term.}
129 \item{term}{The name of the regression term.}
130
131 }