gpt4 book ai didi

c - 给定协方差矩阵和拟合系数,如何计算线性回归的 p 值

转载 作者:行者123 更新时间:2023-12-03 18:20:22 26 4
gpt4 key购买 nike

我使用 GSL 库在 C 中执行了线性回归。我在 R 中执行了相同的回归。我可以使用“摘要”命令在 R 中访问此回归的 p 值。

在 C 中,我有协方差矩阵、残差平方和和拟合系数。使用这些,我如何计算 p 值?

我尝试过使用“Getting p-value for linear regression in C gsl_fit_linear() function from GSL library”这种方法

谁能证实它的有效性?与 R 相比,它给出的结果对我来说有所不同。

我已将这行 C 代码隔离为不正确的,但我不明白为什么:

double pv0=t0<0?2*(1-gsl_cdf_tdist_P(-t0,n-2)):2*(1-gsl_cdf_tdist_P(t0,n-2));//This is the p-value of the constant term

R给出的结果:

系数:

            Estimate Std. Error t value Pr(>|t|)   
(Intercept) -700.000 226.569 -3.090 0.05373 .
x 60.000 6.831 8.783 0.00311 **

C给出的结果:

Coefficients    Estimate Std. Error   t value   Pr(>|t|)
(Intercept) -700.000000 226.568606 -3.089572 -550099700.000000
x 60.000000 6.831301 8.783101 -4.000000

最佳答案

gsl_cdf_tdist_P 应该有两个 double 参数并返回一个介于 0 和 1 之间的 double

首先检查所有类型。

如果在所有类型都正确时返回 0-1 之外的值,则某处存在非常严重的问题。

关于c - 给定协方差矩阵和拟合系数,如何计算线性回归的 p 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26289968/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com