1 #ifndef STAN_MATH_PRIM_MAT_FUN_VARIANCE_HPP 2 #define STAN_MATH_PRIM_MAT_FUN_VARIANCE_HPP 7 #include <boost/math/tools/promotion.hpp> 23 typename boost::math::tools::promote_args<T>::type
30 for (
size_t i = 0; i < v.size(); ++i) {
31 T diff = v[i] - v_mean;
32 sum_sq_diff += diff * diff;
34 return sum_sq_diff / (v.size() - 1);
43 template <
typename T,
int R,
int C>
45 typename boost::math::tools::promote_args<T>::type
51 typename boost::math::tools::promote_args<T>::type
53 typename boost::math::tools::promote_args<T>::type
55 for (
int i = 0; i < m.size(); ++i) {
56 typename boost::math::tools::promote_args<T>::type
58 sum_sq_diff += diff * diff;
60 return sum_sq_diff / (m.size() - 1);
void check_nonzero_size(const char *function, const char *name, const T_y &y)
Check if the specified matrix/vector is of non-zero size.
boost::math::tools::promote_args< T >::type variance(const std::vector< T > &v)
Returns the sample variance (divide by length - 1) of the coefficients in the specified standard vect...
boost::math::tools::promote_args< T >::type mean(const std::vector< T > &v)
Returns the sample mean (i.e., average) of the coefficients in the specified standard vector...