如何将 GARCH 输出导出到 Latex?

4 latex r

我想将装有该包的 GARCH 模型的结果导出rugarch到 Latex,但我找不到合适的包。

通常该包stargazer非常适合此目的,但stargazer仅支持包的输出fGarchprint()也不行。

微量元素:

x <- rnorm(1:100)

spec <- rugarch::ugarchspec(
          variance.model = list(model = "sGARCH"),
          mean.model = list(armaOrder = c(0, 0),
                            include.mean = TRUE),
          distribution = "std")
fit <- rugarch::ugarchfit(spec = spec, data = x)
Run Code Online (Sandbox Code Playgroud)

Emi*_*mil 5

您可以将texreg包用于此目的,并根据包ugarchfit的功能对其进行自定义rugarch


library(texreg)

#define dependent variable:

y <- x #to generalize  your case (y is usually the dependent variable)

extract.rugarch <- function(fit, 
                            include.rsquared = TRUE, include.loglike = TRUE, include.aic = TRUE, include.bic = TRUE) {
  
  # extract coefficient table from fit:
  coefnames <- rownames(as.data.frame(fit@fit$coef))
  coefs <- fit@fit$coef
  se <- as.vector(fit@fit$matcoef[, c(2)])
  pvalues <-  as.vector(fit@fit$matcoef[, c(4)])       # numeric vector with p-values
  
  # create empty GOF vectors and subsequently add GOF statistics from model:
  gof <- numeric()
  gof.names <- character()
  gof.decimal <- logical()
  if (include.rsquared == TRUE) {
    r2 <-  1 - (var(fit@fit$residuals) / var(y))
    gof <- c(gof, r2)
    gof.names <- c(gof.names, "R^2")
    gof.decimal <- c(gof.decimal, TRUE)
  }
  if (include.loglike == TRUE) {
    loglike <- fit@fit$LLH
    gof <- c(gof, loglike)
    gof.names <- c(gof.names, "Log likelihood")
    gof.decimal <- c(gof.decimal, TRUE)
  }
  if (include.aic == TRUE) {
    aic <- infocriteria(fit)[c(1)]
    gof <- c(gof, aic)
    gof.names <- c(gof.names, "AIC")
    gof.decimal <- c(gof.decimal, TRUE)
  }
  
  if (include.bic == TRUE) {
    bic <- infocriteria(fit)[c(2)]
    gof <- c(gof, bic)
    gof.names <- c(gof.names, "BIC")
    gof.decimal <- c(gof.decimal, TRUE)
  }

  # create texreg object:
  tr <- createTexreg(
    coef.names = coefnames, 
    coef = coefs,
    se = se,
    pvalues = pvalues, 
    gof.names = gof.names, 
    gof = gof, 
    gof.decimal = gof.decimal
  )
  return(tr)
}

#print table:
texreg(extract.rugarch(fit, include.rsquared = FALSE)) #for latex # as R^2 is zero in this example.

Run Code Online (Sandbox Code Playgroud)

软件包作者 Philip Leifeld 提供了关于如何为不受支持的软件包自定义 texreg 的非常好的详细解释:Print "pretty" table for h2o models in R