Fitting a student t distribution in R using fitdistr() yields error “non-finite finite-difference value”

余生颓废 提交于 2019-12-12 06:09:24

问题


Reproducable example which will give the mentioned error code every time is: (Note that even without set.seed, the error comes up every time)

library(MASS)
set.seed(seed = 1)
data<-rnorm(n = 10000,mean = 0.0002,sd = 0.001)
fitdistr(x = data,densfun = "t")

The error message is:

Error in stats::optim(x = c(-0.000426453810742332,       0.000383643324222082,  : 
non-finite finite-difference value [2]
In addition: Warning message:
In log(s) : NaNs produced

The problem is the "non-finite finite-difference value". Fitdistr does not give me a result.

My knowledge: I researched and apparently this could mean that a parameter is negative during the iteration. And that the solution could be to provide a better or at least different starting value. But I could not figure out how to do this and I am not sure if this is the issue.

MY QUESTION: a) Why do I get this error message and b)how can I fix it in R, so that I can fit the student-t distribution to my normally distributed data?

来源:https://stackoverflow.com/questions/31073997/fitting-a-student-t-distribution-in-r-using-fitdistr-yields-error-non-finite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!