全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
4132 16
2013-12-07
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-12-7 06:37:20
################
#  WinBUGS code for Finite Mixture model (Carlin and Louis, 2008, Example 2.19)
#  data are "eyes" data from WinBUGS manual
################

model
{
for( i in 1 : N ) {
   y[i] ~ dnorm(mu[i], tau)
   mu[i] <- lambda[T[i]]
   T[i] ~ dcat(P[])
   }
P[1:2] ~ ddirch(alpha[])
theta ~ dnorm(0.0, 1.0E-6) I(0.0, )
lambda[2] <- lambda[1] + theta
lambda[1] ~ dnorm(0.0, 1.0E-6)

Ystar1 ~ dnorm(lambda[1], tau)
Ystar2 ~ dnorm(lambda[2], tau)
Tstar ~ dcat(P[]);  astar <- Tstar-1
Ystar <- Ystar1*(1-astar) + Ystar2*astar

sigma ~ dunif(0.01,100)   #  vague Gelman prior for sigma
tau<- 1/(sigma*sigma)
}

DATA:
list(y = c(529.0, 530.0, 532.0, 533.1, 533.4,
           533.6, 533.7, 534.1, 534.8, 535.3,
           535.4, 535.9, 536.1, 536.3, 536.4,
           536.6, 537.0, 537.4, 537.5, 538.3,
           538.5, 538.6, 539.4, 539.6, 540.4,
           540.8, 542.0, 542.8, 543.0, 543.5,
           543.8, 543.9, 545.3, 546.2, 548.8,
           548.7, 548.9, 549.0, 549.4, 549.9,
           550.6, 551.2, 551.4, 551.5, 551.6,
           552.8, 552.9,553.2), N = 48, alpha = c(1, 1),
    T = c(1, NA, NA, NA, NA, NA, NA, NA, NA, NA,
          NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
          NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
          NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
          NA, NA, NA, NA, NA, NA, NA, 2))


INITS (two sets):

list(lambda = c(535, NA), theta = 5, sigma = 1.0, P=c(0.5, 0.5))
list(lambda = c(535, NA), theta =15, sigma = 5.0, P=c(0.2, 0.8))
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-12-7 06:39:54
Shifted-Wald mixture models in WinBUGS


Suppose you want a two component normal model. You might use something like this:

    model {
      for(i in 1:nobs){
        C ~ dcat(pi[1:2])
        d ~ dnorm(mu[C],tau[C])
      }
      pi[1:2] ~ ddirch(xi[1:2])
      for(j in 1:2){
        xi[j] <- 1
      }
      mu[1] ~ dnorm(1,1)
      tau[1] ~ dgamma(1,.1)
      mu[2] ~ dnorm(5,1)
      tau[2] ~ dgamma(4,.1)
      }
    }
In this model, C indexes the mixture components, and is distributed as a categorical random variable, which is to say that it takes the value ’1′ with probability pi[1] and the value ’2′ with probability pi[2] = 1-pi[1]. The vector pi is distributed as a Dirichlet random variable with parameters 1 and 1, which is to say that pi[1] is uniformly distributed. The vector d has the data in it, and the idea is that each element of d is being modeled as a normal variate with either mu[1] and tau[1] or mu[2] and tau[2], each of which is given its own distinct prior.

This model works just fine, so you might think that, after getting WinBUGS to recognize the shifted Wald distribution, it would work to make the appropriate changes and, say, try this (the parameters in the priors are arbitrary here – I’m just trying to get the model to work at all right now):

    model {
      for(i in 1:nobs){
        C ~ dcat(pi[1:2])
        d ~ ShiftedWald(v[C],a[C],b[C])
      }
      pi[1:2] ~ ddirch(xi[1:2])
      for(j in 1:2){
        xi[j] <- 1
      }
      v[1] ~ dgamma(8,4)
      a[1] ~ dgamma(10,2)
      b[1] ~ dgamma(6,3)
      v[2] ~ dgamma(2,1)
      a[2] ~ dgamma(4,4)
      b[2] ~ dgamma(16,2)
      }
    }
But this doesn’t work, and I have no idea why. When I try to run this, I get an ‘index out of range’ trap error. To the (small) extent that I can figure out what’s going wrong, the dcat distribution is allowing C to take values other than 1 or 2. Now, because I only want two mixture components, I can do the following instead, which seems to be working just fine (on simulated data):

    model {
      for(i in 1:nobs){
        C ~ dbern(pi)
        Cp <- C + 1
        d ~ ShiftedWald(v[Cp],a[Cp],b[Cp])
      }
      pi ~ dbeta(xi,nu)
      xi <- 1
      nu <- 1
      v[1] ~ dgamma(8,4)
      a[1] ~ dgamma(10,2)
      b[1] ~ dgamma(6,3)
      v[2] ~ dgamma(2,1)
      a[2] ~ dgamma(4,4)
      b[2] ~ dgamma(16,2)
      }
    }
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-12-7 06:42:14
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-12-7 06:45:08
Hierarchical Spatial N-mixture and Occupancy Models using WinBUGS

http://www.esapubs.org/archive/ecol/E092/036/suppl-1.htm
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-12-7 06:47:58
Fitting N-mixture models with random observer effects in BUGS and ADMB
附件列表

nmix.pdf

大小:249.81 KB

只需: 1 个论坛币  马上下载

Fitting N-mixture models with random observer effects in BUGS and ADMB

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
栏目导航
热门文章
推荐文章

分享

扫码加好友,拉您进群