Statistics
| Revision:

root / branches / pthreads-737 / examples / admb-re / weights / binomial.tpl @ 765

History | View | Annotate | Download (992 Bytes)

1
// Biomial with random effects
2

    
3
DATA_SECTION
4

    
5
 init_int n					
6
 init_vector y(1,n)		
7

    
8
PARAMETER_SECTION
9
  init_bounded_number mu(-5.0,5.0)     	
10
  init_bounded_number sigma(.001,5,2)	
11

    
12
  random_effects_vector u(1,n,2)
13

    
14
  objective_function_value g    
15

    
16
PROCEDURE_SECTION
17

    
18
  int i;
19

    
20
  for (i=1;i<=n;i++)
21
    f1(i,mu, sigma,u(i));
22

    
23
SEPARABLE_FUNCTION void f1(const int& i, const prevariable & mu, const prevariable & sigma, const prevariable& ui)
24
  #ifdef PI
25
  g -= -0.5*log(2.0*PI) - 0.5*square(ui);
26
  #else
27
  g -= -0.5*log(2.0*3.14) - 0.5*square(ui);
28
  #endif
29

    
30

    
31
  dvariable  eta = mu + sigma*ui;
32
  dvariable  p = mfexp(eta)/(1.0 + mfexp(eta));
33

    
34
  //for (int j=0;j<=2;j++)
35
  //  if(y(i)==j)
36
  //    g -= j*log(p) + (2.0-j)*log(1-p); 
37

    
38
  g -= y(i)*eta + 2.0*log(1.0 - p + .0000001); 
39

    
40

    
41
TOP_OF_MAIN_SECTION
42
  arrmblsize = 4000000L;
43
  gradient_structure::set_GRADSTACK_BUFFER_SIZE(300000);
44
  gradient_structure::set_CMPDIF_BUFFER_SIZE(20000);
45
  gradient_structure::set_MAX_NVAR_OFFSET(100000);
46

    
47