我试图从 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
.
有人可以给我建议吗:
- 为什么
MASS::fitdistr
会产生警告而通过优化fGarch::optim
成功而没有警告? - 为什么没有
df
输出MASS::fitdistr
? - 有没有办法
MASS:fitdistr
在没有警告的情况下运行这些数据并获取df
?
免责声明: