broom (version 0.4.1)

gmm_tidiers: Tidying methods for generalized method of moments "gmm" objects

Description

These methods tidy the coefficients of "gmm" objects from the gmm package, or glance at the model-wide statistics (especially the J-test).

Usage

"tidy"(x, conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE, quick = FALSE, ...)
"glance"(x, ...)

Arguments

x
gmm object
conf.int
whether to include a confidence interval
conf.level
confidence level of the interval, used only if conf.int=TRUE
exponentiate
whether to exponentiate the coefficient estimates and confidence intervals (typical for logistic regression)
quick
whether to compute a smaller and faster version, containing only the term and estimate columns (and confidence interval if requested, which may be slower)
...
extra arguments (not used)

Value

All tidying methods return a data.frame without rownames. The structure depends on the method chosen.tidy.gmm returns one row for each coefficient, with six columns:
term
The term in the model being estimated
estimate
The estimated coefficient
std.error
The standard error from the linear model
statistic
t-statistic
p.value
two-sided p-value
If all the the terms have _ in them (e.g. WMK_(Intercept)), they are split into variable and term.If conf.int=TRUE, it also includes columns for conf.low and conf.high, computed with confint.glance.gmm returns a one-row data.frame with the columns
df
Degrees of freedom
statistic
Statistic from J-test for E(g)=0
p.value
P-value from J-test
df.residual
Residual degrees of freedom, if included in "gmm" object

Details

If conf.int=TRUE, the confidence interval is computed with the confint function.

Note that though the "gmm" object contains residuals and fitted values, there is not yet an augment method implemented. This is because the input to gmm is not tidy (it's a "wide" matrix), so it is not immediately clear what the augmented results should look like.

Examples

Run this code

if (require("gmm", quietly = TRUE)) {
  # examples come from the "gmm" package
  ## CAPM test with GMM
  data(Finance)
  r <- Finance[1:300, 1:10]
  rm <- Finance[1:300, "rm"]
  rf <- Finance[1:300, "rf"]
  
  z <- as.matrix(r-rf)
  t <- nrow(z)
  zm <- rm-rf
  h <- matrix(zm, t, 1)
  res <- gmm(z ~ zm, x = h)
  
  # tidy result
  tidy(res)
  tidy(res, conf.int = TRUE)
  tidy(res, conf.int = TRUE, conf.level = .99)
  
  # coefficient plot
  library(ggplot2)
  library(dplyr)
  tidy(res, conf.int = TRUE) %>%
    mutate(variable = reorder(variable, estimate)) %>%
    ggplot(aes(estimate, variable)) +
    geom_point() +
    geom_errorbarh(aes(xmin = conf.low, xmax = conf.high)) +
    facet_wrap(~ term) +
    geom_vline(xintercept = 0, color = "red", lty = 2)
  
  # from a function instead of a matrix
  g <- function(theta, x) {
  	e <- x[,2:11] - theta[1] - (x[,1] - theta[1]) %*% matrix(theta[2:11], 1, 10)
  	gmat <- cbind(e, e*c(x[,1]))
  	return(gmat) }
  
  x <- as.matrix(cbind(rm, r))
  res_black <- gmm(g, x = x, t0 = rep(0, 11))
  
  tidy(res_black)
  tidy(res_black, conf.int = TRUE)
  
  ## APT test with Fama-French factors and GMM
  
  f1 <- zm
  f2 <- Finance[1:300, "hml"] - rf
  f3 <- Finance[1:300, "smb"] - rf
  h <- cbind(f1, f2, f3)
  res2 <- gmm(z ~ f1 + f2 + f3, x = h)
  
  td2 <- tidy(res2, conf.int = TRUE)
  td2
  
  # coefficient plot
  td2 %>%
    mutate(variable = reorder(variable, estimate)) %>%
    ggplot(aes(estimate, variable)) +
    geom_point() +
    geom_errorbarh(aes(xmin = conf.low, xmax = conf.high)) +
    facet_wrap(~ term) +
    geom_vline(xintercept = 0, color = "red", lty = 2)
}

Run the code above in your browser using DataCamp Workspace