Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
neg_binomial_2_ccdf_log.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_2_CCDF_LOG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_2_CCDF_LOG_HPP
3 
4 #include <boost/math/special_functions/digamma.hpp>
5 #include <boost/random/negative_binomial_distribution.hpp>
6 #include <boost/random/variate_generator.hpp>
23 #include <vector>
24 
25 namespace stan {
26 
27  namespace math {
28 
29  // Temporary neg_binomial_2_ccdf implementation that
30  // transforms the input parameters and calls neg_binomial_ccdf
31  template <typename T_n, typename T_location, typename T_precision>
32  typename return_type<T_location, T_precision>::type
34  const T_location& mu,
35  const T_precision& phi) {
36  if ( !( stan::length(n) && stan::length(mu) && stan::length(phi) ) )
37  return 0.0;
38 
44 
45  static const char* function("stan::math::neg_binomial_2_cdf");
46  check_positive_finite(function, "Location parameter", mu);
47  check_positive_finite(function, "Precision parameter", phi);
48  check_not_nan(function, "Random variable", n);
49  check_consistent_sizes(function,
50  "Random variable", n,
51  "Location parameter", mu,
52  "Precision Parameter", phi);
53 
54  VectorView<const T_n> n_vec(n);
56  VectorView<const T_precision> phi_vec(phi);
57 
58  size_t size_beta = max_size(mu, phi);
59 
60  std::vector<typename return_type<T_location, T_precision>::type>
61  beta_vec(size_beta);
62  for (size_t i = 0; i < size_beta; ++i)
63  beta_vec[i] = phi_vec[i] / mu_vec[i];
64 
65  // Cast a vector of size 1 down to a
66  // scalar to avoid dimension mismatch
67  if (size_beta == 1)
68  return neg_binomial_ccdf_log(n, phi, beta_vec[0]);
69  else
70  return neg_binomial_ccdf_log(n, phi, beta_vec);
71  }
72  }
73 }
74 #endif
bool check_less(const char *function, const char *name, const T_y &y, const T_high &high)
Return true if y is strictly less than high.
Definition: check_less.hpp:81
bool check_not_nan(const char *function, const char *name, const T_y &y)
Return true if y is not NaN.
return_type< T_location, T_precision >::type neg_binomial_2_ccdf_log(const T_n &n, const T_location &mu, const T_precision &phi)
size_t length(const std::vector< T > &x)
Definition: length.hpp:10
return_type< T_shape, T_inv_scale >::type neg_binomial_ccdf_log(const T_n &n, const T_shape &alpha, const T_inv_scale &beta)
size_t max_size(const T1 &x1, const T2 &x2)
Definition: max_size.hpp:9
bool check_consistent_sizes(const char *function, const char *name1, const T1 &x1, const char *name2, const T2 &x2)
Return true if the dimension of x1 is consistent with x2.
bool check_nonnegative(const char *function, const char *name, const T_y &y)
Return true if y is non-negative.
VectorView is a template metaprogram that takes its argument and allows it to be used like a vector...
Definition: VectorView.hpp:41
bool check_positive_finite(const char *function, const char *name, const T_y &y)
Return true if y is positive and finite.

     [ Stan Home Page ] © 2011–2015, Stan Development Team.