r – Getting p-Values from MGCV GAM Results and Calculating Their Average

gamrstatistics

I'm doing many GAM model calculations (mgcv). Their output looks like the attached image. What I want to do is 1) to get only p-values from the output and 2) calculate their average. For example, in the case of the image, I want to get 0.0477 and 0.1518 and get their average (0.09975). I can do one calculation manually but I have many models and want to do it automatically.

I did look at pages like below but I get p-values different from the summary.

(added)

The format of GAM model I used is:

model1 <- gam(dependentx  ~ s(independent1) + s(independent2), data=datatable, method = "REML", bs='cr', family=Gamma(link=log))

https://stackoverflow.com/questions/53389900/extract-p-value-from-gam-check-in-rhttps://stackoverflow.com/questions/53389900/extract-p-value-from-gam-check-in-r

enter image description here

Best Answer

You've not given us any code to show what you are doing. Please try and include a reproducible example in your questions. I'll use the first example from help(gam), which ends with b:

> b <- gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat)

Then if you do:

> sb = summary(b)

and look at:

> sb$s.table
           edf   Ref.df         F       p-value
s(x0) 2.500168 3.115115  6.920610  1.293448e-04
s(x1) 2.401079 2.983817 81.857629  9.886217e-46
s(x2) 7.697714 8.564323 88.157916 4.267512e-130
s(x3) 1.000000 1.000000  4.343072  3.780565e-02

you should be able to see that the fourth column:

> sb$s.table[,4]
        s(x0)         s(x1)         s(x2)         s(x3) 
 1.293448e-04  9.886217e-46 4.267512e-130  3.780565e-02 

Is the p-values printed by summary:

> summary(b)

[...]

Approximate significance of smooth terms:
        edf Ref.df      F  p-value    
s(x0) 2.500  3.115  6.921 0.000129 ***
s(x1) 2.401  2.984 81.858  < 2e-16 ***
s(x2) 7.698  8.564 88.158  < 2e-16 ***
s(x3) 1.000  1.000  4.343 0.037806 *  
[...]

If you want the mean of the p-values from a gam model in one line then it looks like:

> mean(summary(b)$s.table[,4])
[1] 0.009483748

but if that doesn't work for you its because you've not shown us how you are creating your model object.