【问题标题】:I would like to replace the exponential function with the gamma function in calculating the 95% likelihood based confidence interval in R在计算 R 中基于 95% 似然的置信区间时,我想用 gamma 函数替换指数函数
【发布时间】:2021-03-24 11:27:08
【问题描述】:

我想替换指数对数似然


explik <- function(x) {

  sum( dexp(data, 1/x, log=TRUE))
}

伽马负对数似然

gammalike <- function(x) {
  
  -sum(dgamma(data, shape=x, scale=2, log=TRUE))
}

在下面的函数和脚本中

likeqn <- function(mu) {
  
  muhat <- mean(data)
  maxlik <- explik(muhat)
  explik(mu) - maxlik + 0.5 * 3.841
}
source("explik.R")
source("likeqn.R")


# Input data
data <- c(63, 130, 88, 120, 330, 188, 270, 222, 189, 116)

# Find the MLE of an exponential distribution
muhat <- mean(data)

# Solve likelihood equation numerically to find likelihood based CI
vlikeqn <- Vectorize(likeqn)
CIlower <- uniroot(vlikeqn, c(10,muhat) )$root
CIupper <- uniroot(vlikeqn, c(muhat,500) )$root
cbind(CIlower, muhat, CIupper)

# Plot log-likelihood function
x <- seq(80, 350)
vexplik <- Vectorize(explik)
plot(x, vexplik(x), type="l", xlab=expression(mu), ylab="log-likelihood")


我尝试替换 log-like 函数,但结果似乎不合理。

【问题讨论】:

    标签: r optimization statistics mle gamma-distribution


    【解决方案1】:

    具有速率 lambda 的分布 Expo(lambda) 是 Gamma(1, 1/lambda)(形状尺度)。

    gammalike <- function(x) {
      sum(dgamma(data, shape=1, scale=x, log=TRUE))
    }
    

    【讨论】:

      猜你喜欢
      • 2016-11-01
      • 2020-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-01
      • 2021-07-16
      相关资源
      最近更新 更多