我的下面的代码使用卡方的卡方阵“分位数”和概率函数来计算置信区间. 我正在尝试实现此功能,以避免依赖于Boost.有没有资源在哪里可以找到这样的实现? #include boost/math/distribution
我正在尝试实现此功能,以避免依赖于Boost.有没有资源在哪里可以找到这样的实现?
#include <boost/math/distributions/chi_squared.hpp>
#include <boost/cstdint.hpp>
using namespace std;
using boost::math::chi_squared;
using boost::math::quantile;
vector <double> ConfidenceInterval(double x) {
vector <double> ConfInts;
// x is an estimated value in which
// we want to derive the confidence interval.
chi_squared distl(2);
chi_squared distu((x+1)*2);
double alpha = 0.90;
double lower_limit = 0;
if (x != 0) {
chi_squared distl(x*2);
lower_limit = (quantile(distl,((1-alpha)/2)))/2;
}
double upper_limit = (quantile(distu,1-((1-alpha)/2)))/2;
ConfInts.push_back(lower_limit);
ConfInts.push_back(upper_limit);
return ConfInts;
}
如果您正在寻找可以复制/粘贴的源代码,这里有一些链接:
> AlgLib
> Koders
因人而异…
