0

我试图从 David Ruppert 的“金融工程的统计和数据分析”中重现以下示例,该示例适合学生 t 分布到历史无风险利率:

library(MASS)
data(Capm, package = "Ecdat")
x <-  Capm$rf
fitt <- fitdistr(x,"t", start = list(m=mean(x),s=sd(x)), df=3)
as.numeric(fitt$estimate)
0.437310595161651 0.152205764779349

输出伴随着以下警告消息:

警告信息:

In log(s): NaNs producedWarning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs producedWarning message:
In log(s): NaNs produced

它出现在 R 的帮助文件中,它MASS::fitdistr使用最大似然来寻找最佳参数。但是,当我手动进行优化(同一本书)时,一切顺利并且没有警告:

library(fGarch)
loglik_t <- function(beta) {sum( - dt((x - beta[1]) / beta[2],
                                      beta[3], log = TRUE) + log(beta[2]) )}

start <- c(mean(x), sd(x), 5)
lower <- c(-1, 0.001, 1)
fit_t <- optim(start, loglik_t, hessian = T, method = "L-BFGS-B", lower = lower)
fit_t$par
0.44232633269102 0.163306955396773 4.12343777572566

拟合参数在可接受的标准误差范围内,并且除了 mean 和 sd 之外,我还得到了df.

有人可以给我建议吗:

  1. 为什么MASS::fitdistr会产生警告而通过优化fGarch::optim成功而没有警告?
  2. 为什么没有df输出MASS::fitdistr
  3. 有没有办法MASS:fitdistr在没有警告的情况下运行这些数据并获取df

免责声明:

类似的问题在此处此处被问了几次而没有答案

4

1 回答 1

2

您没有将lower参数传递给fitdistr导致它在正域和负域中进行搜索的函数。通过将lower参数传递给函数

fitt <- fitdistr(x,"t", start = list(m=mean(x),s=sd(x)), df=3, lower=c(-1, 0.001))

你没有得到 NaN——就像你在手动优化中所做的那样。

编辑:

fitt <- fitdistr(x,"t", start = list(m=mean(x),s=sd(x),df=3),lower=c(-1, 0.001,1))

返回非整数自由度结果。但是,我猜它的舍入值,round(fitt$estimate['df'],0)可用于拟合自由度参数。

于 2016-02-10T15:02:06.627 回答