Created
January 18, 2017 03:08
-
-
Save aforren1/fb08a81ae3ab2d4cb8fb3774656fb3f4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// almost word-for-word transcribed from the qrLMM R package | |
// if you want to operate in unconstrained space, | |
// mu can be left be | |
// sigma should be > 0, so log transform | |
// p should be 0 < p < 1, so logit transform | |
namespace ald { | |
// density function | |
template<class Type> | |
Type dald(Type y, Type mu, Type sigma, Type p) { | |
if (y < mu) { | |
return (p * (1 - p)/sigma) * exp((1 - p) * (y - mu)/sigma); | |
} else { | |
return (p * (1 - p)/sigma) * exp(-p * (y - mu)/sigma); | |
} | |
} | |
// quantile function, lower tail only | |
template<class Type> | |
Type qald(Type prob, Type mu, Type sigma, Type p) { | |
if (prob < p) { | |
return mu + (sigma * log(prob/p))/(1 - p); | |
} else { | |
return mu - ((sigma * log((1 - prob)/(1 - p)))/p); | |
} | |
} | |
// random number generator | |
template<class Type> | |
Type rald(Type mu, Type sigma, Type p) { | |
Type tmp = runif(0, 1); | |
return qald(tmp, mu, sigma, p); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment