I have fitted a model

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

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

1 Like

You can extract the pvalues with

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

We should probably come up with a better way.

5 Likes

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

Thanks

Ebby

Well, I understand that if you the following command

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

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

Hope it helps

Ebby

1 Like

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

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

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

For t-statistics, use,

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

Works with GLM `v1.4.2`

3 Likes