C++ 中的卡方概率函数 [英] Chi-Squared Probability Function in C++

查看:47
本文介绍了C++ 中的卡方概率函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的以下代码使用卡方的分位数"和 Boost 的概率函数计算置信区间.

The following code of mine computes the confidence interval using Chi-square's 'quantile' and probability function from Boost.

我正在尝试实现此功能以避免对 Boost 的依赖.有什么资源可以找到这样的实现吗?

I am trying to implement this function as to avoid dependency to Boost. Is there any resource where can I find such implementation?

#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;         
}

推荐答案

如果您正在寻找可以复制/粘贴的源代码,这里有一些链接:

If you're looking for source code you can copy/paste, here are some links:

天啊...

这篇关于C++ 中的卡方概率函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆