首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用student_t_distribution计算t统计量的p值

使用student_t_distribution计算t统计量的p值
EN

Stack Overflow用户
提问于 2020-08-24 18:08:32
回答 1查看 96关注 0票数 0

我想要计算t统计量的p值,用于具有5%显著性水平的双尾检验。我想用标准库做到这一点。我想知道是否可以使用< random >模块中的student_t_distribution。我目前的代码如下

代码语言:javascript
复制
#include <iostream>

int main(){
    double t_stat = 0.0267; // t-statistic
    double alpha_los = 0.05; // level of significance
    double dof = 30; // degrees of freedom
    // calculate P > |t| and compare with alpha_los
    return 0;
}

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-24 23:01:10

<random>头只为您提供了从不同发行版获得随机数的能力。

如果您能够使用boost,则可以执行以下操作:

代码语言:javascript
复制
#include <boost/math/distributions/students_t.hpp>

int main() {
    double t_stat = 0.0267; // t-statistic
    double alpha_los = 0.05; // level of significance
    double dof = 30; // degrees of freedom
    boost::math::students_t dist(dof);

    double P_x_greater_t = 1.0 - boost::math::cdf(dist, t_stat);
    double P_x_smaller_negative_t = boost::math::cdf(dist, -t_stat);

    if(P_x_greater_t + P_x_smaller_negative_t < alpha_los) {
        
    } else {
        
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63558941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档