aboutsummaryrefslogtreecommitdiff
path: root/src/tranprobs.cpp
blob: 76c5173b0291ebf4083b3d199ad776f2403c4f3e (plain)
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
68
69
70
71
#include "tranprobs.h"


using namespace Rcpp ;



// constant model
void tp1(arma::mat& g3, int nrI, int nrI1, Rcpp::IntegerVector N, arma::imat I, arma::imat I1, Rcpp::List Ib, Rcpp::List Ip, double gam, double om) {
  Rcpp::NumericVector pois1 = dpois(N, gam, true);
  arma::vec pois = as<arma::vec>(pois1);
  arma::vec bin = arma::zeros<arma::vec>(nrI1);
  for(int i=0; i<nrI1; i++) {
    bin(i) = Rf_dbinom(I1(i,0), I1(i,1), om, true);
  }
  for(int s=0; s<nrI; s++) {
    arma::uvec indB = as<arma::uvec>(Ib[s]);
    arma::uvec indP = as<arma::uvec>(Ip[s]);
    int nc = indB.n_elem;
    for(int q=0; q<nc; q++) {
      g3(s) += exp(bin(indB(q)) + pois(indP(q)));
    }
  }
}


// autoregressive + immigration model
void tp2(arma::mat& g3, int lk, double gam, double om, double imm) {
    int Nmin=0;
    for(int n1=0; n1<lk; n1++) {
	for(int n2=0; n2<lk; n2++) {
	    Nmin = std::min(n1, n2);
	    for(int c=0; c<=Nmin; c++) {
		g3.at(n1, n2) += exp(Rf_dbinom(c, n1, om, true) +
				  Rf_dpois(n2-c, gam*n1 + imm, true));
	    }
	}
    }
}
 
// trend + immigration model 
void tp3(arma::mat& g3, int lk, double gam, double imm) {
    for(int n1=0; n1<lk; n1++) {
      for(int n2=0; n2<lk; n2++) {
        g3.at(n1, n2) = Rf_dpois(n2, n1*gam+imm, false);
      }
    }
}





// Ricker + immigration model
void tp4(arma::mat& g3, int lk, double gam, double om, double imm) {
    for(int n1=0; n1<lk; n1++) {
	for(int n2=0; n2<lk; n2++) {
	  g3.at(n1, n2) = Rf_dpois(n2, n1*exp(gam*(1-n1/om)) + imm, false);
	}
    }
}

// Gompertz + immigration model
void tp5(arma::mat& g3, int lk, double gam, double om, double imm) {
    for(int n1=0; n1<lk; n1++) {
	   for(int n2=0; n2<lk; n2++) {
	     g3.at(n1, n2) = Rf_dpois(n2, n1*exp(gam * (1 - log(double (n1) + 1)/log(om + 1))) + imm, false);
	   }
    }
}