以下代码使用卡方的卡方阵“分位数”和概率函数来计算置信区间。
我正在尝试实现此功能,以避免依赖于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;
}
答案 0 :(得分:2)
查看Gnu Scientific library。或者查看Numerical Recipes。在Apache Commons Math中还有一个Java版本,应该可以直接翻译。
答案 1 :(得分:2)
答案 2 :(得分:2)
我正在尝试实现此功能,以避免依赖Boost。
另一种选择是 降低 提升依赖关系,但 避免 。如果减少依赖关系,则可以使用 INITIAL_CONTEXT_FACTORY=com.sun.jndi.ldap.LdapCtxFactory
PROVIDER_URL=ldap://localhost:1389
SECURITY_AUTHENTICATION=simple
SECURITY_PRINCIPAL=cn=Directory Manager
SECURITY_CREDENTIALS=secret
文件夹,例如200或300个源文件,而不是整个1 GB以上的材料。 (是的,200或300可以准确 - 这是我在复制[branch]
autosetupmerge = always
时最终得到的结果。)
要减少依赖关系,请使用bcp
(boost copy)仅复制Boost
所需的文件。不好的是,您通常必须从源代码构建shared_ptr
,因为它不是在ZIP或TARBALL中分发的。
要查找有关构建chi_squared.hpp
的说明,请参阅How to checkout latest stable Boost (not development or bleeding edge)?