- 阅读权限
- 255
- 威望
- 1 级
- 论坛币
- 170716 个
- 通用积分
- 8029.6016
- 学术水平
- 207 点
- 热心指数
- 257 点
- 信用等级
- 151 点
- 经验
- 878 点
- 帖子
- 2429
- 精华
- 0
- 在线时间
- 4069 小时
- 注册时间
- 2005-11-15
- 最后登录
- 2025-11-15
|
- n <- length(y);m <- 100
- a <- c(10,20,30);b <- c(10,20,30);c <- c(10,20,30);q <- c(10,20,30)
- out_mat <- matrix(numeric(3*(m+1)),ncol=3)
- out_mat[1,] <- c(2,2,2)#initial values
- #step1-4
- times <- 1
- ##par1 =lambda,par2=y,par3=theta,par4=beta
- subfunc <- function(par1,par2,par3,par4){
- subs1 <- prod((1-exp(par1*par2))^par3)
- subs2 <- prod((1-subs1)^par4)
- return(subs1*subs2)
- }
- dfunc <- function(x1){
- denomionator <- subfunc(x1,y,out_mat[1,2],out_mat[1,3])
- numerator <- subfunc(out_mat[1,1],y,out_mat[1,2],out_mat[1,3])
- return(numerator/denomionator)
- }
- while (times<m+1){
- theta <- rdevroye(param)
- x <- rglambda(n+a[2],b[2]+sum(y))
- u <- runif(1,0,1)
- d_compare<- dfunc(times,x,theta)
- if (u<d_compare) {
- times<<-times+1
- out_mat[times,1] <<-x
- out_mat[times,2] <<-theta
- sub1 <- (1-exp(-out_mat[1,1]*y))^out_mat[1,2])
- out_mat[times,3] <<-rgbeta(n-sum(d)+a[3],b[3]-sum(log(1-sub1))
- }
- }
- #step5
- comp_mat <- out_mat[-1,]
- theta_head <- (-1/c[1])*log(sum(exp(-c[1]*comp_mat[,2]))/m)
- lambda_head <- (-1/c[2])*log(sum(exp(-c[2]*comp_mat[,1]))/m)
- beta_head <- (-1/c[3])*log(sum(exp(-c[3]*comp_mat[,3]))/m)
- #step6
- theta_ge <- (sum(comp_mat[,2]^(-q1))/m)^(-1/q[1])
- lambda_ge <- (sum(comp_mat[,1]^(-q2))/m)^(-1/q[2])
- beta_ge <- (sum(comp_mat[,3]^(-q3))/m)^(-1/q[3])
复制代码先看看思路吧,改天再写log-concave 的随机数生成函数
|
|