Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用fitdist函数(FitDistripPlus软件包)估计比例和形状参数的缩放_R_Parameters_Weibull_Fitdistrplus - Fatal编程技术网

使用fitdist函数(FitDistripPlus软件包)估计比例和形状参数的缩放

使用fitdist函数(FitDistripPlus软件包)估计比例和形状参数的缩放,r,parameters,weibull,fitdistrplus,R,Parameters,Weibull,Fitdistrplus,如标题所述,我在R(fitdistrpluspackage)中的fitdist函数存在缩放问题 请查看以下代码: # Initialize arrays for storing result fit_store_scale <- rep(NA, 3) fit_store_shape <- rep(NA, 3) # load data data1 <- c(7.616593e-05, 5.313253e-05, 1.604328e-04, 6.482365e-05,

如标题所述,我在R(
fitdistrplus
package)中的
fitdist
函数存在缩放问题

请查看以下代码:

# Initialize arrays for storing result
fit_store_scale <- rep(NA, 3)
fit_store_shape <- rep(NA, 3)

# load data
data1 <- c(7.616593e-05, 5.313253e-05, 1.604328e-04, 6.482365e-05,
           4.217499e-05, 6.759114e-05, 3.531301e-05, 1.934228e-05,
           6.263665e-05, 8.796205e-06)
data2 <- c(7.616593e-06, 5.313253e-06, 1.604328e-05, 6.482365e-06,
           4.217499e-06, 6.759114e-06, 3.531301e-06, 1.934228e-06,
           6.263665e-06, 8.796205e-07)
data3 <- c(7.616593e-07, 5.313253e-07, 1.604328e-06, 6.482365e-07,
           4.217499e-07, 6.759114e-07, 3.531301e-07, 1.934228e-07,
           6.263665e-07, 8.796205e-08)
# form data frame
data <- data.frame(data1, data2, data3)

# set scaling factor
scaling <- 1        #works without warnings and errors at:    
                    #10000 (data1), 100000 (data2) or
                    #1000000 (data3)

# store scale and shape parameter of data1, data2 and data3 in Array
for(i in 1:3)
{
    fit.w1 <- fitdist(data[[i]]*scaling,"weibull", method = "mle")
    fit_store_scale[i] <- fit.w1$estimate[[2]]*1/scaling
    #1/scaling is needed for correcting scale parameter
    fit_store_shape[i] <- fit.w1$estimate[[1]]
}
#初始化数组以存储结果

fit_store_scale解决这一问题的一种方法是通过
10^j
缩放来不断尝试适应分布:

for(i in 1:3)
{
  j <- 0
  while(inherits(try(fitdist(data[[i]] * 10^j, "weibull", method = "mle"), silent = TRUE), "try-error"))
  {
    j <- j + 1
  }
  cat("\nFor data[[", i, "]], used j =", j, "\n\n")
  fit.w1 <- fitdist(data[[i]] * 10^j, "weibull", method = "mle")
  fit_store_scale[i] <- fit.w1$estimate[[2]] * 1/10^j
  #1/scaling is needed for correcting scale parameter
  fit_store_shape[i] <- fit.w1$estimate[[1]]
}


# For data[[ 1 ]], used j = 2 
# For data[[ 2 ]], used j = 3 
# For data[[ 3 ]], used j = 4 

# > fit_store_scale
# [1] 6.590503e-05 6.590503e-06 6.590503e-07
# > fit_store_shape
# [1] 1.56613 1.56613 1.56613
for(1:3中的i)
{

j如果你不是绝对地拘泥于
fitdist
,你可以使用更稳健的方法——下面的方法用对数标度上的参数拟合威布尔函数,并使用内尔德-米德方法,而不是基于梯度的方法。 拟合这些数据似乎没有任何问题

dd <- data.frame(data1,data2,data3)
library("bbmle")
fx <- function(x) {
    m1 <- mle2(y~dweibull(shape=exp(logshape),scale=exp(logscale)),
           data=data.frame(y=x),start=list(logshape=0,logscale=0),
           method="Nelder-Mead")
    exp(coef(m1))
}
t(sapply(dd,fx))  ## not quite the output format you asked for,
                  ##  but easy enough to convert.
##       logshape     logscale
## data1 1.565941 6.589057e-05
## data2 1.565941 6.589054e-06
## data3 1.565941 6.589055e-07
dd