【问题标题】:Plot the likelihood of weibull绘制威布尔的可能性
【发布时间】:2020-09-10 07:01:47
【问题描述】:

我想用一系列形状参数 theta 绘制大小为 1000 的威布尔样本的似然函数。我使用了标准化的 weibull,因此标度 lambda 为 1。但是输出是水平直线。

n<-1000
lik <- function(theta, x){
  K<- length(theta)
  n<- length(x)
  out<- rep(0,K)
  for(k in 1:K){
    out[k] <- prod(dweibull(x, shape= theta[k], scale=1))   
  }
  return(out)
}
theta<-seq(0.01, 10, by = 0.01)
x <- rweibull(n, shape= 0.5, scale= 1)
plot(theta, lik(theta, x), type="l", lwd=2)

【问题讨论】:

  • 尝试绘制 log0likelihood; sum(dweibull(x, shape= theta[k], scale=1, log=TRUE)) 并将 theta 保持在更合理的范围内 seq(0.01, 1, by = 0.01)
  • @user20650,请发帖作为答案?

标签: r plot statistics weibull


【解决方案1】:

您所做的并没有真正错误,但计算机难以计算许多小数的乘积,因此最终可能为零(即使 0.99^1000 = 4^-5)。所以更容易log 转换然后sum。 (由于对数变换是单调递增函数,最大化对数似然与最大化似然相同)。因此变化

prod(dweibull(x, shape= theta[k], scale=1)) 

sum(dweibull(x, shape= theta[k], scale=1, log=TRUE))  

另一个小的变化是在theta 的合理范围内绘制可能性,这样 你可以看到曲线。

工作代码:

set.seed(1)
n<-1000
lik <- function(theta, x){
  K <- length(theta)
  n <- length(x)
  out <- rep(0,K)
  for(k in 1:K){
    out[k] <- sum(dweibull(x, shape= theta[k], scale=1, log=TRUE))   
  }
  return(out)
}

popTheta = 0.5
theta = seq(0.01, 1.5, by = 0.01)
x = rweibull(n, shape=popTheta, scale= 1)
plot(theta, lik(theta, x), type="l", lwd=2)
abline(v=popTheta)

theta[which.max( lik(theta, x))]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    • 2019-08-18
    • 2019-01-13
    • 2012-03-27
    • 2020-08-14
    相关资源
    最近更新 更多