-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOnlyP_countyEndangered_NotEndemics.stan
67 lines (34 loc) · 1.19 KB
/
OnlyP_countyEndangered_NotEndemics.stan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
data{
int<lower=1> nCounties; //Number of counties
int<lower=1> nSpecies; //Number of species
int<lower=1> nEnd; //Number of endangeredspecies
int<lower=1> nNotEnd; //Number of not endangered species
matrix [nSpecies,nCounties] spOccMat; //Matrix of species occurence
int<lower=0> endSpp[nEnd]; //which species are enangered
int<lower=0> notEndSpp[nNotEnd]; //which species are NOT enangered
}
transformed data{
matrix [nEnd,nCounties] endSpOccMat; //Matrix of species occurence
matrix [nNotEnd,nCounties] notEndSpOccMat; //Matrix of species occurence
endSpOccMat = spOccMat[endSpp,] ;
notEndSpOccMat = spOccMat[notEndSpp,] ;
}
parameters{
vector <upper=0> [nCounties] logP;
}
transformed parameters {
vector [nCounties] log1mP;
log1mP = log1m_exp(logP);
}
model
{
//Not Endangered Species (sum of the probabilities that it is not endangered in ANY of the counties)
target += notEndSpOccMat * log1mP;
// Endangered Species (see algebra for getting here)
target += log1m_exp(endSpOccMat * log1mP);
}
generated quantities
{
vector<lower=0, upper=1>[nCounties] p;
p = exp(logP);
}