加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C中的Chi-Sared概率函数

发布时间:2020-12-16 09:23:50 所属栏目:百科 来源:网络整理
导读:我的下面的代码使用卡方的卡方阵“分位数”和概率函数来计算置信区间. 我正在尝试实现此功能,以避免依赖于Boost.有没有资源在哪里可以找到这样的实现? #include boost/math/distributions/chi_squared.hpp#include boost/cstdint.hppusing namespace std; u
我的下面的代码使用卡方的卡方阵“分位数”和概率函数来计算置信区间.

我正在尝试实现此功能,以避免依赖于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

因人而异…

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读