-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mu Niu
committed
Apr 16, 2020
1 parent
059830a
commit 7e62374
Showing
5 changed files
with
111 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
## input | ||
## lambda_sw switching rate, ou-bm or bm-ou. | ||
## pro_pon_ind the indicator vector of states, pn - potential switch, OB - ou to bm, BO - bm to ou. | ||
|
||
## output | ||
## the loglikelihood given the lambdas. | ||
|
||
lam_lik<-function( lambda_sw, pro_pon_ind) | ||
{ | ||
lambda_BO = lambda_sw[2] | ||
lambda_OB = lambda_sw[1] | ||
|
||
p_BO = lambda_BO /Kappa # | ||
p_OB = lambda_OB /Kappa # | ||
|
||
all_pon = pro_pon_ind[ which( pro_pon_ind != 'sp') ] | ||
pn_inx = which(all_pon=='pn') | ||
OB_inx = which(all_pon=='OB') | ||
BO_inx = which(all_pon=='BO') | ||
|
||
num_pon = all_pon | ||
num_pon[pn_inx] = 0 | ||
num_pon[OB_inx] = -1 | ||
num_pon[BO_inx] = 1 | ||
num_pon = as.numeric(num_pon) | ||
|
||
cum_pon =cumsum(num_pon) + nai ## if nai in cum_pon, all animal doing OU at that time. | ||
|
||
num_pon[OB_inx] = p_OB | ||
num_pon[BO_inx] = p_BO | ||
num_pon[pn_inx] = 1 - (p_BO*(nai-cum_pon[pn_inx]) + p_OB*(cum_pon[pn_inx])) | ||
|
||
sum(log(num_pon)) | ||
} | ||
|
||
|
||
|
||
|