简体   繁体   English

我想用伽玛 function 替换指数 function 在计算 R 中基于 95% 似然的置信区间

[英]I would like to replace the exponential function with the gamma function in calculating the 95% likelihood based confidence interval in R

I would like to replace the exponential log likelihood我想替换指数对数似然


explik <- function(x) {

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

with the gamma negative log-likelihood伽马负对数似然

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

in the following function and script在以下 function 和脚本中

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")


I have tried to replace the log-lik functions however the result does not seem reasonable.我试图替换 log-like 函数,但结果似乎不合理。

The distribution Expo(lambda) with rate lambda, is Gamma(1, 1/lambda) (shape-scale).具有速率 lambda 的分布 Expo(lambda) 是 Gamma(1, 1/lambda)(形状尺度)。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用rq函数计算R中分位数回归的95%置信区间 - Calculating 95% confidence intervals in quantile regression in R using rq function 在 R 中一次计算多个列的 95% 置信区间 - Calculating 95% Confidence Interval for Several Columns at Once in R 如何使用方程式中的95%置信区间在r中使用95%置信区间? - How do I use the 95% confidence interval in r using the equation for a 95% confidence interval? 指数 function 的参数,最大似然为 R - Parameters for Exponential function with maximum likelihood in R 基于 R 中累积概率函数计算结果似然的问题 - Problems with calculating the likelihood of an outcome based on cumulative probability function in R 是否有用于从 nls 模型计算插值 X 的 95% 置信区间的 R 函数? - Is there an R function for computing 95% confidence interval of interpolated X from an nls model? 为什么 R 中的 CI() function 对于 95% 置信区间返回的结果与 qnorm 不同? - Why does the CI() function in R return different results than qnorm for a 95% confidence interval? 使用“ci”函数计算置信区间 - Calculating confidence interval using "ci" function R - 通过自举带线性模型计算R平方和残差标准误差的95%置信区间 - R - calculating 95% confidence interval for R-squared and residual standard error by boot strap linear model R I 绘制对数 - 指数拟合的置信区间 - R I Plotting a confidence interval for a logarithmic - exponential fitting
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM