# Hypergeometic programming

**URL:** <https://discourse.mc-stan.org/t/hypergeometic-programming/7700>\
**Category:** Modeling\
**Created:** [February 13, 2019, 5:57pm UTC](https://discourse.mc-stan.org/t/hypergeometic-programming/7700 "2019-02-13T17:57:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickg1](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@nickg1](https://discourse.mc-stan.org/u/nickg1)\
**Post date:** [February 13, 2019, 5:57pm UTC](https://discourse.mc-stan.org/t/hypergeometic-programming/7700/1 "2019-02-13T17:57:03Z")

</div>

Please share your Stan program and accompanying data if possible.

* * *

When including Stan code in your post it really helps if you make it as readable as possible by using Stan code chunks (```stan) with clear spacing and indentation. For example, use

```stan
model {
  vector[N] mu = alpha + beta * x;
  y ~ normal(mu, sigma); 
} 

```

instead of

model{  
vector[N] mu = alpha+beta\*x;  
y~normal(mu,sigma);  
}

* * *

To include mathematical notation in your post put LaTeX syntax between two `$` symbols, e.g.,  
p(\theta | y) \propto p(\theta) p(y | \theta).

> I’m trying to program a simple Lincoln-Peterson mark-recapture example using the hyperG likelihood:  
> I have easily programmed this example using the more common binomial likelihood, but also want and need to be able to program using the HyperG. I forgot to add that this appears to compile, but when I run it sampling does not occur because ‘b’ takes a values on the order of negative 200000 despite being constrained to no less than 70.

Here are my Rstan and stan files:  
[//HG1.stan](https://HG1.stan). Test of simple Lincoln-Peterson model using a hypergeometric likelihood  
//February 13 2019

data{  
int\<lower = 0\> a;//M  
int\<lower=0\> N; //C  
int\<lower = 0, upper = min(a,N)\> n;//R  
}

transformed data{  
int\<lower = N-n\> b; //N-M  
}

//parameters{  
// real\<lower = (N-n)\> b; //(C-R+M)\> N;  
// }

model {  
// R~binomial(C, M/N);  
n~hypergeometric(N,a,b); //n, N and a known; b is unkown and to be estimated  
}

generated quantities{  
int \<lower = 0\>Pop;  
Pop = a+b; //total population size  
}

#HG1\_stan.R  
#Test: Simple Lincoln-Peterson mark-recp model using a hypergeomtric likelihood  
#February 13 2019

#a = 500; #number marked and released  
#N =100; #number recaptured  
#n = 30; #number marked among the C recaptures

stanDat ← list(a = 500, N = 100, n = 30)

#sample posterior:  
HG1fit ← stan(file=“HG1.stan”, data = stanDat, init=list(list(b = 80)),iter = 100, chains = 1)

print(HG1fit)

The right-most remmed-out notations in the .stan file are the corresponding variables in the mark-recap examples in Section 15.3, pp. 2016-17 of the Stan Reference Manual.
