X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FrTrait.c;h=43dc73ad85f3163b65e49333889a2088d30a06a5;hb=646d8be3497d656d95331e2c7f6bef5d2ff86b2c;hp=2e7371f850f808ec54abcfef8479f2d0629b3778;hpb=2419de65ffb4f7c45eb8c2448bcba3d0df64744f;p=ape.git diff --git a/src/rTrait.c b/src/rTrait.c index 2e7371f..43dc73a 100644 --- a/src/rTrait.c +++ b/src/rTrait.c @@ -1,6 +1,6 @@ -/* rTrait.c 2010-05-26 */ +/* rTrait.c 2011-06-25 */ -/* Copyright 2010 Emmanuel Paradis */ +/* Copyright 2010-2011 Emmanuel Paradis */ /* This file is part of the R-package `ape'. */ /* See the file ../COPYING for licensing issues. */ @@ -12,6 +12,7 @@ void rTraitCont(int *model, int *Nedge, int *edge1, int *edge2, double *el, { /* The tree must be in pruningwise order */ int i; + double alphaT, M, S; switch(*model) { case 1 : for (i = *Nedge - 1; i >= 0; i--) { @@ -21,8 +22,16 @@ void rTraitCont(int *model, int *Nedge, int *edge1, int *edge2, double *el, } break; case 2 : for (i = *Nedge - 1; i >= 0; i--) { + if (alpha[i]) { + alphaT = alpha[i] * el[i]; + M = exp(-alphaT); + S = sigma[i] * sqrt((1 - exp(-2 * alphaT))/(2 * alpha[i])); + } else { /* same than if (alpha[i] ==0) */ + M = 1; + S = sqrt(el[i]) * sigma[i]; + } GetRNGstate(); - x[edge2[i]] = x[edge1[i]] + (sigma[i]*norm_rand() - alpha[i]*(x[edge1[i]] - theta[i])) * el[i]; /* need sqrt(el[i]) ? */ + x[edge2[i]] = x[edge1[i]] * M + theta[i] * (1 - M) + S * norm_rand(); PutRNGstate(); } break;