Skip to content
Prev 4484 / 20628 Next

MCMCglmm for binomial models?

so much for intuition.  consolidating the b's doesn't make any
material speed difference, but it does simplify the model code a bit.

btw, this run and the previous post were using 1e6 interations, 1e5
burn-in, and 50 thin: m.sample(1e6,1e5,50).

-Whit


warmstrong at krypton:~/dvl/c++/CppBugs/test$ g++ -I.. -Wall -O2
herd.fast.cpp -llapack
warmstrong at krypton:~/dvl/c++/CppBugs/test$ time ./a.out
samples: 17999
b:
  -1.5077
  -1.2344
  -1.3518
  -1.8819

tau_overdisp: 1.54806
tau_b_herd: 22.059
sigma_overdisp: 0.878115
sigma_b_herd: 0.245386
b_herd:
   0.1464
  -0.0475
   0.0739
   0.0070
  -0.0353
  -0.0866
   0.1661
   0.0658
  -0.0585
  -0.0904
   0.0052
  -0.0138
  -0.1324
   0.0947
  -0.0902


real	0m21.905s
user	0m21.880s
sys	0m0.020s
warmstrong at krypton:~/dvl/c++/CppBugs/test$


updated code:
class HerdModel: public MCModel {
  const ivec incidence;
  const ivec size;
  const ivec herd;
  const mat fixed;
  int N, N_herd;
  mat permutation_matrix;

public:
  NormalStatic<vec> b;
  UniformStatic<double> tau_overdisp;
  UniformStatic<double> tau_b_herd;
  Deterministic<double> sigma_overdisp;
  Deterministic<double> sigma_b_herd;
  Normal<vec> b_herd;
  Normal<vec> overdisp;
  Deterministic<vec> phi;
  Binomial<ivec> likelihood;


  HerdModel(const ivec& incidence_,const ivec& size_,const ivec&
herd_,const mat& fixed_,int N_, int N_herd_):
    incidence(incidence_),size(size_),herd(herd_),
    fixed(fixed_),N(N_),N_herd(N_herd_),permutation_matrix(N,N_herd),
    b(randn<vec>(4),0,0.001),tau_overdisp(1,0,1000),tau_b_herd(1,0,100),
    sigma_overdisp(1),sigma_b_herd(1),
    b_herd(randn<vec>(N_herd_)),overdisp(randn<vec>(N)),
    phi(randu<vec>(N)),
    likelihood(incidence_,true)
  {
    permutation_matrix.fill(0.0);
    for(uint i = 0; i < herd.n_elem; i++) {
      permutation_matrix(i,herd[i]) = 1.0;
    }
    add(b);
    add(tau_overdisp);
    add(tau_b_herd);
    add(sigma_overdisp);
    add(sigma_b_herd);
    add(b_herd);
    add(overdisp);
    add(phi);
    add(likelihood);
  }

  void update() {
    phi.value = fixed*b.value + sum(permutation_matrix*b_herd.value,1)
+ overdisp.value;
    phi.value = 1/(1+exp(-phi.value));
    sigma_overdisp.value = 1/sqrt(tau_overdisp.value);
    sigma_b_herd.value = 1/sqrt(tau_b_herd.value);
  }
  double logp() const {
    return b.logp() + tau_overdisp.logp() + tau_b_herd.logp() +
b_herd.logp(0, tau_b_herd.value) +
      overdisp.logp(0,tau_overdisp.value) + likelihood.logp(size,phi.value);
  }
};



On Tue, Sep 21, 2010 at 3:41 PM, Whit Armstrong
<armstrong.whit at gmail.com> wrote: