首页 > 解决方案 > 如何计算 R 中拟合 T 分布的矩(均值、方差、偏度、峰度)?

问题描述

我已经将样本数据(标准普尔 500 指数回报)拟合到 T 分布,现在必须计算前四个时刻。但是,我不知道如何处理它,我的代码如下所示:这基本上是情节以及我如何将其与 rugarch 配合使用。有什么方法可以快速计算方差/均值/峰度/偏度?谢谢

   library(QRM)
library(rugarch)

dist_st2 <- fitdist("std", training_sample,
                    control=list(tol=1e-20, delta=1e-6))
dist_st2$pars

dist_st2$pars["sigma"]

density_st2 <- ddist(distribution = "std", x,
                     mu = dist_st2$pars["mu"],
                     sigma = dist_st2$pars["sigma"],
                     shape = dist_st2$pars["shape"])

hist(training_sample, freq = FALSE, breaks = 40,
     ylim = c(0, 0.85), xlim = c(-5, 5), border = "gray")


points(x, density_norm, type = "l", lwd = 2, col = COLORS[1])
points(x, density_st2, type = "l", lwd = 2, col = COLORS[2])
lines(density_emp, lwd = 2, lty = 2, col = COLORS[3])
legend("topleft", lty = c(1, 1, 2), col = COLORS[1:3], bty = "n",
       legend = c("Normal distribution", "Student-t distribution",
                  "Empirical distribution"))

标签: rstatistics

解决方案


我不能肯定地说,因为我不熟悉 rugarch 包并且文档有点肤浅。但在我看来,你已经拥有它们了。

  • dist_st2$pars["mu"]是第一个时刻。
  • dist_st2$pars["sigma"]^2应该是第二个(请不要将标准差平方才能得到方差)。
  • dist_st2$pars["shape"]是第四个。
  • 应该有dist_st2$pars["skew"]第三个。

推荐阅读