| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/gmm.R |
| 3 |
\name{glance.gmm} |
| 4 |
\alias{glance.gmm} |
| 5 |
\title{Glance at a(n) gmm object} |
| 6 |
\usage{ |
| 7 |
\method{glance}{gmm}(x, ...) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{x}{A \code{gmm} object returned from \code{\link[gmm:gmm]{gmm::gmm()}}.} |
| 11 |
|
| 12 |
\item{...}{Additional arguments. Not used. Needed to match generic |
| 13 |
signature only. \strong{Cautionary note:} Misspelled arguments will be |
| 14 |
absorbed in \code{...}, where they will be ignored. If the misspelled |
| 15 |
argument has a default value, the default value will be used. |
| 16 |
For example, if you pass \code{conf.lvel = 0.9}, all computation will |
| 17 |
proceed using \code{conf.level = 0.95}. Two exceptions here are: |
| 18 |
\itemize{ |
| 19 |
\item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if |
| 20 |
it will be ignored. |
| 21 |
\item \code{augment()} methods will warn when supplied a \code{newdata} argument if it |
| 22 |
will be ignored. |
| 23 |
}} |
| 24 |
} |
| 25 |
\description{ |
| 26 |
Glance accepts a model object and returns a \code{\link[tibble:tibble]{tibble::tibble()}} |
| 27 |
with exactly one row of model summaries. The summaries are typically |
| 28 |
goodness of fit measures, p-values for hypothesis tests on residuals, |
| 29 |
or model convergence information. |
| 30 |
|
| 31 |
Glance never returns information from the original call to the modeling |
| 32 |
function. This includes the name of the modeling function or any |
| 33 |
arguments passed to the modeling function. |
| 34 |
|
| 35 |
Glance does not calculate summary measures. Rather, it farms out these |
| 36 |
computations to appropriate methods and gathers the results together. |
| 37 |
Sometimes a goodness of fit measure will be undefined. In these cases |
| 38 |
the measure will be reported as \code{NA}. |
| 39 |
|
| 40 |
Glance returns the same number of columns regardless of whether the |
| 41 |
model matrix is rank-deficient or not. If so, entries in columns |
| 42 |
that no longer have a well-defined value are filled in with an \code{NA} |
| 43 |
of the appropriate type. |
| 44 |
} |
| 45 |
\examples{ |
| 46 |
\dontshow{if (rlang::is_installed(c("gmm", "ggplot2"))) withAutoprint(\{ # examplesIf} |
| 47 |
|
| 48 |
# load libraries for models and data |
| 49 |
library(gmm) |
| 50 |
|
| 51 |
# examples come from the "gmm" package |
| 52 |
# CAPM test with GMM |
| 53 |
data(Finance) |
| 54 |
r <- Finance[1:300, 1:10] |
| 55 |
rm <- Finance[1:300, "rm"] |
| 56 |
rf <- Finance[1:300, "rf"] |
| 57 |
|
| 58 |
z <- as.matrix(r - rf) |
| 59 |
t <- nrow(z) |
| 60 |
zm <- rm - rf |
| 61 |
h <- matrix(zm, t, 1) |
| 62 |
res <- gmm(z ~ zm, x = h) |
| 63 |
|
| 64 |
# tidy result |
| 65 |
tidy(res) |
| 66 |
tidy(res, conf.int = TRUE) |
| 67 |
tidy(res, conf.int = TRUE, conf.level = .99) |
| 68 |
|
| 69 |
# coefficient plot |
| 70 |
library(ggplot2) |
| 71 |
library(dplyr) |
| 72 |
|
| 73 |
tidy(res, conf.int = TRUE) |> |
| 74 |
mutate(variable = reorder(term, estimate)) |> |
| 75 |
ggplot(aes(estimate, variable)) + |
| 76 |
geom_point() + |
| 77 |
geom_errorbarh(aes(xmin = conf.low, xmax = conf.high)) + |
| 78 |
geom_vline(xintercept = 0, color = "red", lty = 2) |
| 79 |
|
| 80 |
# from a function instead of a matrix |
| 81 |
g <- function(theta, x) { |
| 82 |
e <- x[, 2:11] - theta[1] - (x[, 1] - theta[1]) \%*\% matrix(theta[2:11], 1, 10) |
| 83 |
gmat <- cbind(e, e * c(x[, 1])) |
| 84 |
return(gmat) |
| 85 |
} |
| 86 |
|
| 87 |
x <- as.matrix(cbind(rm, r)) |
| 88 |
res_black <- gmm(g, x = x, t0 = rep(0, 11)) |
| 89 |
|
| 90 |
tidy(res_black) |
| 91 |
tidy(res_black, conf.int = TRUE) |
| 92 |
|
| 93 |
# APT test with Fama-French factors and GMM |
| 94 |
|
| 95 |
f1 <- zm |
| 96 |
f2 <- Finance[1:300, "hml"] - rf |
| 97 |
f3 <- Finance[1:300, "smb"] - rf |
| 98 |
h <- cbind(f1, f2, f3) |
| 99 |
res2 <- gmm(z ~ f1 + f2 + f3, x = h) |
| 100 |
|
| 101 |
td2 <- tidy(res2, conf.int = TRUE) |
| 102 |
td2 |
| 103 |
|
| 104 |
# coefficient plot |
| 105 |
td2 |> |
| 106 |
mutate(variable = reorder(term, estimate)) |> |
| 107 |
ggplot(aes(estimate, variable)) + |
| 108 |
geom_point() + |
| 109 |
geom_errorbarh(aes(xmin = conf.low, xmax = conf.high)) + |
| 110 |
geom_vline(xintercept = 0, color = "red", lty = 2) |
| 111 |
\dontshow{\}) # examplesIf} |
| 112 |
} |
| 113 |
\seealso{ |
| 114 |
\code{\link[=glance]{glance()}}, \code{\link[gmm:gmm]{gmm::gmm()}} |
| 115 |
|
| 116 |
Other gmm tidiers: |
| 117 |
\code{\link{tidy.gmm}()} |
| 118 |
} |
| 119 |
\concept{gmm tidiers} |
| 120 |
\value{ |
| 121 |
A \code{\link[tibble:tibble]{tibble::tibble()}} with exactly one row and columns: |
| 122 |
\item{df}{Degrees of freedom used by the model.} |
| 123 |
\item{df.residual}{Residual degrees of freedom.} |
| 124 |
\item{nobs}{Number of observations used.} |
| 125 |
\item{p.value}{P-value corresponding to the test statistic.} |
| 126 |
\item{statistic}{Test statistic.} |
| 127 |
|
| 128 |
} |