在 R 中同时估计两个数据集的威布尔分布参数

Estimating the parameters of a weibull distribution to two data sets simultaneously in R

我正在尝试估计 3 参数 weibull 分布的参数(平移参数 beta= -0.5)。问题是我必须同时拟合两组数据。使用 nlc(见下面的代码)我能够单独估计每组数据的分布参数,但不能同时估计。 GAMMA 类似于共享参数(在两个 nlc 估计中估计的 GAMMA 必须相同)。

我的数据是这样的:

x = seq(from =0, to =10, by =1)
y = c(0.1315, 0.2368, 0.2631, 0.1578, 0.1578, 0.0000, 0.0526, 0.0000, 0.0000, 0.0000, 0.0000)
z = c(0.3684, 0.3157, 0.2105, 0.0789, 0.0263, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000)

这是我的代码

# WEIBULL FUNCTION WITH ALPHA_GS and beta=-0.5
weibull_GS = function(x, GAMMA, ALPHA_GS){
  (GAMMA/ALPHA_GS)*(((x-(-0.5))/ALPHA_GS)^(GAMMA-1))*exp(-((x-(-0.5))/ALPHA_GS)^GAMMA)
}

#ESTIMATE ALPHA_GS
nlc <- nls.control(maxiter=100)
n <- nls(y ~ weibull_GS(x, GAMMA, ALPHA_GS), control="nlc",
         start = list(GAMMA=2, ALPHA_GS=3), trace=T, model=F)

summary(n)

# WEIBULL FUNCTION WITH ALPHA_GA beta=-0.5
weibull_GA = function(x, GAMMA, ALPHA_GA){
  (GAMMA/ALPHA_GA)*(((x-(-0.5))/ALPHA_GA)^(GAMMA-1))*exp(-((x-(-0.5))/ALPHA_GA)^GAMMA)
}

# ESTIMATE ALPHA_GA
nlc <- nls.control(maxiter=100)
m <- nls(z ~ weibull_GA(x, GAMMA, ALPHA_GA), control="nlc",
         start = list(GAMMA=2, ALPHA_GA=3), trace=T, model=F)

summary(m)

您正在做的是用 f 威布尔分布的密度函数拟合非线性回归模型 y = f(x) + error。这与将 Weibull 分布拟合到样本无关

如果这确实是您想要做的,请按以下方式回答您的问题:

f <- function(x1, x2, GAMMA, ALPHA_GS, ALPHA_GA){
  c(weibull_GS(x1, GAMMA, ALPHA_GS), weibull_GA(x2, GAMMA, ALPHA_GA))
}
Sample <- c(y, z)
nls(Sample ~ f(x, x, GAMMA, ALPHA_GS, ALPHA_GA), ......)