How to Calculate Linear Regression P Values ​​Given Covariance Matrix and Fit Rates

I have performed linear regression in C using the GSL library. I have performed the same regression in R. I can access the p values ​​for this regression in R using the "summary" command.

In C, I have a covariance matrix, the sum of the squares of the values ​​and the fit coefficients. Using these, how do I calculate the p values?

I tried this approach using Get p-value for linear regression in the C function gsl_fit_linear () from the GSL library "

Can anyone confirm its validity? The results it gives are different for me compared to R.

I have highlighted this line of C code as invalid, but I don't understand why:

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

      

Results given by R:

Odds:

            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 **

      

Results given by 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

      

+3


source to share


2 answers


gsl_cdf_tdist_P

should expect two arguments double

and return a double

between 0 and 1.

Check all your types first.



If it returns values ​​outside of 0-1 when all types are correct, there is a very serious problem somewhere.

+2


source


It turns out I was compiling with no warnings and I didn't see that gsl_cdf_tdist_P is implicitly declared. This made the compiler think that the function should return an integer. I included the appropriate gsl header and got the values ​​corresponding to R.



+1


source







All Articles