1 #ifndef STAN_MATH_PRIM_FUN_CORR_FREE_HPP
2 #define STAN_MATH_PRIM_FUN_CORR_FREE_HPP
3 
4 #include <stan/math/prim/meta.hpp>
5 #include <stan/math/prim/err.hpp>
6 #include <stan/math/prim/fun/atanh.hpp>
7 
8 namespace stan {
9 namespace math {
10 
11 /**
12  * Return the unconstrained scalar that when transformed to
13  * a valid correlation produces the specified value.
14  *
15  * <p>This function inverts the transform defined for
16  * <code>corr_constrain(T)</code>, which is the inverse hyperbolic
17  * tangent,
18  *
19  * <p>\f$ f^{-1}(y)
20  *          = \mbox{atanh}\, y
21  *          = \frac{1}{2} \log \frac{y + 1}{y - 1}\f$.
22  *
23  * @tparam T Type of correlation
24  * @param[in] y correlation
25  * @return free scalar that transforms to the specified input
26  */
27 template <typename T>
corr_free(const T & y)28 inline T corr_free(const T& y) {
29   check_bounded("lub_free", "Correlation variable", y, -1.0, 1.0);
30   return atanh(y);
31 }
32 
33 }  // namespace math
34 }  // namespace stan
35 #endif
36