1 #ifndef STAN_MATH_PRIM_FUN_MAKE_NU_HPP
2 #define STAN_MATH_PRIM_FUN_MAKE_NU_HPP
3
4 #include <stan/math/prim/meta.hpp>
5 #include <stan/math/prim/fun/Eigen.hpp>
6
7 namespace stan {
8 namespace math {
9
10 /**
11 * Return the degrees of freedom for the t distribution that
12 * corresponds to the shape parameter in the LKJ distribution.
13 *
14 * @tparam T scalar type
15 * @param eta LKJ distribution parameter in (0, inf)
16 * @param K number of variables in correlation matrix
17 */
18 template <typename T>
make_nu(const T & eta,size_t K)19 Eigen::Array<T, Eigen::Dynamic, 1> make_nu(const T& eta, size_t K) {
20 using size_type = index_type_t<Eigen::Matrix<T, Eigen::Dynamic, 1>>;
21
22 // Best (1978) implies nu = 2 * alpha for the dof in a t
23 // distribution that generates a beta variate on (-1, 1)
24 Eigen::Array<T, Eigen::Dynamic, 1> nu(K * (K - 1) / 2);
25 T alpha = eta + 0.5 * (K - 2.0); // from Lewandowski et. al.
26 T alpha2 = 2.0 * alpha;
27 for (size_type j = 0; j < (K - 1); ++j) {
28 nu(j) = alpha2;
29 }
30 size_t counter = K - 1;
31 for (size_type i = 1; i < (K - 1); ++i) {
32 alpha -= 0.5;
33 alpha2 = 2.0 * alpha;
34 for (size_type j = i + 1; j < K; ++j, ++counter) {
35 nu(counter) = alpha2;
36 }
37 }
38 return nu;
39 }
40
41 } // namespace math
42 } // namespace stan
43
44 #endif
45