Vespucci  1.0.0
confidenceinterval.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (C) 2014-2016 Wright State University - All Rights Reserved
3  Daniel P. Foose - Maintainer/Lead Developer
4 
5  This file is part of Vespucci.
6 
7  Vespucci is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Vespucci is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Vespucci. If not, see <http://www.gnu.org/licenses/>.
19 *******************************************************************************/
20 #include <mlpack/core.hpp>
21 #include <boost/math/distributions.hpp>
23 
31 double Vespucci::Math::Stats::TInterval(double alpha, double stddev, unsigned int n)
32 {
33  using namespace boost::math;
34  using namespace std;
35  students_t dist(n - 1);
36  double T = quantile(complement(dist, alpha/2));
37  return T*stddev / sqrt(double(n));
38 }
39 
47 std::pair<double, double> Vespucci::Math::Stats::ChiSquaredInterval(double alpha, double stddev, unsigned int n)
48 {
49  using namespace boost::math;
50  using namespace std;
51  chi_squared dist(n - 1);
52  double lower_limit = sqrt((n - 1) * stddev*stddev / quantile(complement(dist, alpha/2)));
53  double upper_limit = sqrt((n -1 ) * stddev*stddev / quantile(dist, alpha/2));
54  return pair<double, double>(lower_limit, upper_limit);
55 }
VESPUCCI_EXPORT double TInterval(double alpha, double stddev, unsigned int n)
Vespucci::Math::Stats::TInterval.
VESPUCCI_EXPORT std::pair< double, double > ChiSquaredInterval(double alpha, double stddev, unsigned int n)
Vespucci::Math::Stats::ChiSquaredInterval.
VESPUCCI_EXPORT double quantile(arma::vec &data, double probs)
Definition: accessory.cpp:503