# How to obtain the pvalues of the coefficients in GLM.jl?

**URL:** <https://discourse.julialang.org/t/how-to-obtain-the-pvalues-of-the-coefficients-in-glm-jl/9531>\
**Category:** Statistics\
**Tags:** glm\
**Created:** [March 6, 2018, 10:08am UTC](https://discourse.julialang.org/t/how-to-obtain-the-pvalues-of-the-coefficients-in-glm-jl/9531 "2018-03-06T10:08:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [March 6, 2018, 10:08am UTC](https://discourse.julialang.org/t/how-to-obtain-the-pvalues-of-the-coefficients-in-glm-jl/9531/1 "2018-03-06T10:08:01Z")

</div>

I have fitted a model

```julia
using DataFrames
df = DataFrame(
  x = 2*y + 1 + rand(100),
  y = rand(100)
)
using GLM
mdl = lm(@formula(y~x), df)

```

now I can see the pvalues of the coefficients. How do I obtain the pvalues and set them to a variable?

The output from above

```julia
Formula: y ~ 1 + x

Coefficients:
             Estimate Std.Error t value Pr(>|t|)
(Intercept) 1.46518 0.0514909 28.4552 <1e-48
x 2.08846 0.0889749 23.4724 <1e-41

```

---

<div class="post-metadata">

**Author:** ![andreasnoack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasnoack/32/27_2.png) [@andreasnoack](https://discourse.julialang.org/u/andreasnoack)\
**Post date:** [March 6, 2018, 10:34am UTC](https://discourse.julialang.org/t/how-to-obtain-the-pvalues-of-the-coefficients-in-glm-jl/9531/2 "2018-03-06T10:34:07Z")

</div>

You can extract the pvalues with

```julia
julia> coeftable(mdl).cols[4]
2-element Array{StatsBase.PValue,1}:
 0.4706
 <1e-30

```

We should probably come up with a better way.

---

<div class="post-metadata">

**Author:** ![ebbythomas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ebbythomas/32/9705_2.png) [@ebbythomas](https://discourse.julialang.org/u/ebbythomas)\
**Post date:** [April 30, 2018, 8:03am UTC](https://discourse.julialang.org/t/how-to-obtain-the-pvalues-of-the-coefficients-in-glm-jl/9531/3 "2018-04-30T08:03:46Z")

</div>

It works. However, How can i extract the p-value of a particular variable, say :ENERGY from the model, say model…?  
Thanks  
Ebby

---

<div class="post-metadata">

**Author:** ![lukaebby](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lukaebby/32/4055_2.png) [@lukaebby](https://discourse.julialang.org/u/lukaebby)\
**Post date:** [May 1, 2018, 8:50am UTC](https://discourse.julialang.org/t/how-to-obtain-the-pvalues-of-the-coefficients-in-glm-jl/9531/4 "2018-05-01T08:50:14Z")

</div>

Well, I understand that if you the following command

```julia
coeftable(mdl).cols[4]

```

you will have limited option to use those as they are in StatsBase.  
If you try this (may not be very efficient), it works better

```julia
a = coeftable(model).cols[4]
pVals = [a[i].v for i in 1:length(a) ]

```

Hope it helps  
Ebby

---

<div class="post-metadata">

**Author:** ![v-i-s-h](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/v-i-s-h/32/46152_2.png) [@v-i-s-h](https://discourse.julialang.org/u/v-i-s-h)\
**Post date:** [May 10, 2021, 1:54am UTC](https://discourse.julialang.org/t/how-to-obtain-the-pvalues-of-the-coefficients-in-glm-jl/9531/5 "2021-05-10T01:54:55Z")

</div>

May be very late, but I thought this solution could be useful for other people coming to this page:

```julia
coeftable(lm_fit) |> c -> c.cols[c.pvalcol][c.rownms .== "x"]

```

This will give the p-value for variable “x”.

For t-statistics, use,

```julia
coeftable(lm_fit) |> c -> c.cols[c.teststatcol][c.rownms .== "x"]

```

Works with GLM `v1.4.2`

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [December 19, 2025, 9:50pm UTC](https://discourse.julialang.org/t/how-to-obtain-the-pvalues-of-the-coefficients-in-glm-jl/9531/6 "2025-12-19T21:50:09Z")

</div>

With current GLM.jl you can now also use classic DataFrames operations:

```julia-auto
ct = DataFrame(coeftable(mdl))
ct."Pr(>|t|)"
ct[findfirst(==("x"), ct.Name), "Pr(>|t|)"]

```

And even without DataFrames:

```julia-auto
using Tables
Tables.columntable(coeftable(mdl))[Symbol("Pr(>|t|)")]

```
