使用fitdistrplus拟合truncnorm

时间:2016-08-08 20:53:56

标签: r model-fitting fitdistrplus

我正在尝试将截断的正态分布拟合到某些数据。但是,我遇到了以下错误:

<simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs = data,     gr = gradient, ddistnam = ddistname, hessian = TRUE, method = meth,     lower = lower, upper = upper, ...): non-finite finite-difference value [1]>
Error in fitdist(testData, "truncnorm", start = list(a = 0, mean = 0.8,  : 
  the function mle failed to estimate the parameters, 
                with the error code 100

我不确定出了什么问题 - 我已经读过,在某些情况下,如果最初的猜测是错误的或高于实际值,可能会出现问题,但是我&#39 ;我尝试了许多不同的起始值,似乎都没有。

以下是我的数据的一小部分示例,以及我用来获取错误的代码:

library(fitdistrplus)
library(truncnorm)
testData <- c(3.2725167726, 0.1501345235, 1.5784128343, 1.218953218, 1.1895520932, 
              2.659871271, 2.8200152609, 0.0497193249, 0.0430677458, 1.6035277181, 
              0.2003910167, 0.4982836845, 0.9867184303, 3.4082793339, 1.6083770189, 
              2.9140912221, 0.6486576911, 0.335227878, 0.5088426851, 2.0395797721, 
              1.5216239237, 2.6116576364, 0.1081283479, 0.4791143698, 0.6388625172, 
              0.261194346, 0.2300098384, 0.6421213993, 0.2671907741, 0.1388568942, 
              0.479645736, 0.0726750815, 0.2058983462, 1.0936704833, 0.2874115077, 
              0.1151566887, 0.0129750118, 0.152288794, 0.1508512023, 0.176000366, 
              0.2499423442, 0.8463027325, 0.0456045486, 0.7689214668, 0.9332181529, 
              0.0290242892, 0.0441181842, 0.0759601229, 0.0767983979, 0.1348839304
)

fitdist(testData, "truncnorm", start = list(a = 0, mean = 0.8, sd = 0.9))

1 个答案:

答案 0 :(得分:1)

问题是mle估算器对参数mean提供越来越多的负估计,因为下限a趋于零(请注意,后者不能在start中指定参数,但在fix.arg)内:

fitdist(testData, "truncnorm", fix.arg=list(a=-.5),
        start = list(mean = mean(testData), sd = sd(testData)))
fitdist(testData, "truncnorm", fix.arg=list(a=-.2),
        start = list(mean = mean(testData), sd = sd(testData)))
fitdist(testData, "truncnorm", fix.arg=list(a=-.15),
        start = list(mean = mean(testData), sd = sd(testData)))

防止mean的大负值的一种可能性是使用优化的下限:

fitdist(testData, "truncnorm", fix.arg=list(a=0),
        start = list(mean = mean(testData), sd = sd(testData)),
        optim.method="L-BFGS-B", lower=c(0, 0))

然而,这改变了估计程序;实际上,您对参数施加了额外的约束,并且可能获得具有不同下限的不同答案。