Re: [R] Quoting smooth random terms mccv::gam

2018-12-17 Thread Smith, Desmond
Thanks very much, Simon!

On 12/17/18, 8:23 AM, "Simon Wood"  wrote:

I would quote the p-value, but not the statistic (as it is not a 
standard F stat). The actual statistic is given here:


https://urldefense.proofpoint.com/v2/url?u=https-3A__academic.oup.com_biomet_article-2Dpdf_100_4_1005_566200_ast038.pdf=DwIDaQ=UXmaowRpu5bLSLEQRunJ2z-YIUZuUoa9Rw_x449Hd_Y=y6YM-SSv8WOxR70LMzwwFohC41WMNU4ZGFcHpTmGWLo=CqMTgm500nmgBrPfC2cLIc45sZ6h0I2odVPYT8qCmYA=epymthgL8_opS9pITmfKRJnH_uzCCzEWTYU9qEwQ_q0=

On 14/12/2018 04:33, Smith, Desmond wrote:
> Dear All,
>
> I have a mgcv::gam model of the form:
>
> m1 <- gam(Y ~ A + s(B, bs = "re"), data = dataframe, family = gaussian, 
method = "REML")
>
> The random term is quoted in summary(m1) as, for example,
>
> Approximate significance of smooth terms:
> # edf Ref.df  F p-value
> s(B)  4.486  5 97.195 6.7e-08 ***
>
> My question is, how would I quote this result (statistic and P value) in 
a formal document?
>
> For example, one possibility is F[4.486,5] = 97.195, P = 6.7e-08. 
However, arguing against this, “reverse engineering” of the result using
>
> pf(q= 97.195, df1= 4.486, df2= 5, lower.tail=FALSE)
>
> gives an incorrect p value:
>
> [1] 0.1435508
>
> I would be very grateful for your advice. Many thanks for your help!
>
> 
>
> UCLA HEALTH SCIENCES IMPORTANT WARNING: This email (and any attachments) 
is only intended for the use of the person or entity to which it is addressed, 
and may contain information that is privileged and confidential. You, the 
recipient, are obligated to maintain it in a safe, secure and confidential 
manner. Unauthorized redisclosure or failure to maintain confidentiality may 
subject you to federal and state penalties. If you are not the intended 
recipient, please immediately notify us by return email, and delete this 
message from your computer.
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp=DwIDaQ=UXmaowRpu5bLSLEQRunJ2z-YIUZuUoa9Rw_x449Hd_Y=y6YM-SSv8WOxR70LMzwwFohC41WMNU4ZGFcHpTmGWLo=CqMTgm500nmgBrPfC2cLIc45sZ6h0I2odVPYT8qCmYA=XCgKsfTTCyRoegz5hqMvtEt9m0KRm-qD0HtpXGYdxzg=
> PLEASE do read the posting guide 
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html=DwIDaQ=UXmaowRpu5bLSLEQRunJ2z-YIUZuUoa9Rw_x449Hd_Y=y6YM-SSv8WOxR70LMzwwFohC41WMNU4ZGFcHpTmGWLo=CqMTgm500nmgBrPfC2cLIc45sZ6h0I2odVPYT8qCmYA=hyi1_CVKTW4c_7lyb3TlmtPnSpsQfnI7BhRjVOLhXdI=
> and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Quoting smooth random terms mccv::gam

2018-12-13 Thread Smith, Desmond
Dear All,

I have a mgcv::gam model of the form:

m1 <- gam(Y ~ A + s(B, bs = "re"), data = dataframe, family = gaussian, method 
= "REML")

The random term is quoted in summary(m1) as, for example,

Approximate significance of smooth terms:
   # edf Ref.df  F p-value
s(B)  4.486  5 97.195 6.7e-08 ***

My question is, how would I quote this result (statistic and P value) in a 
formal document?

For example, one possibility is F[4.486,5] = 97.195, P = 6.7e-08. However, 
arguing against this, “reverse engineering” of the result using

pf(q= 97.195, df1= 4.486, df2= 5, lower.tail=FALSE)

gives an incorrect p value:

[1] 0.1435508

I would be very grateful for your advice. Many thanks for your help!



UCLA HEALTH SCIENCES IMPORTANT WARNING: This email (and any attachments) is 
only intended for the use of the person or entity to which it is addressed, and 
may contain information that is privileged and confidential. You, the 
recipient, are obligated to maintain it in a safe, secure and confidential 
manner. Unauthorized redisclosure or failure to maintain confidentiality may 
subject you to federal and state penalties. If you are not the intended 
recipient, please immediately notify us by return email, and delete this 
message from your computer.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Fixed effects in negative binomial mixed model mgcv::gam

2018-10-19 Thread Smith, Desmond
I am using gam from the mgcv package to analyze a dataset with 24 entries :

ran  f1 f2   y
1   30005   545
1   300010  1045
1   1   5   536
1   1   10  770
2   30005   842
2   300010  2042
2   1   5   615
2   1   10  1361
3   30005   328
3   300010  1028
3   1   5   262
3   1   10  722
4   30005   349
4   300010  665
4   1   5   255
4   1   10  470
5   30005   680
5   300010  1510
5   1   5   499
5   1   10  1422
6   30005   628
6   300010  2062
6   1   5   499
6   1   10  2158

The data has two fixed effects (f1 and f2) and one random effect (ran). The 
dependent data is y. Because the dependent data y represents counts and is 
overdispersed, I am using a negative binomial model.

The gam model and its summary output is as follows:

library(mgcv)
summary(gam(y ~ f1 * f2 + s(ran, bs = "re"), data = df2, family = nb, method = 
"REML"))

Family: Negative Binomial(27.376)
Link function: log

Formula:
y ~ f1 * f2 + s(ran, bs = "re")

Parametric coefficients:
  Estimate Std. Error z value Pr(>|z|)
(Intercept)  5.500e+00  3.137e-01  17.533  < 2e-16 ***
f1  -3.421e-05  3.619e-05  -0.9450.345
f2   1.760e-01  3.355e-02   5.247 1.55e-07 ***
f1:f22.665e-07  4.554e-06   0.0590.953
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Approximate significance of smooth terms:
 edf Ref.df Chi.sq p-value
s(ran) 4.726  5  85.66  <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

R-sq.(adj) =  0.866   Deviance explained = 93.6%
-REML = 185.96  Scale est. = 1 n = 24

The Wald test from summary gives very high significance for f2 (P = 1.55e-07). 
However, when I test the significance of f2 by comparing two different models 
using anova, I get dramatically different results:

anova(gam(y ~ f1 * f2 + s(ran, bs = "re"), data = df2, family = nb, method = 
"ML"),
gam(y ~ f1 + s(ran, bs = "re"), data = df2, family = nb, method = "ML"),
test="Chisq")

Analysis of Deviance Table

Model 1: y ~ f1 * f2 + s(ran, bs = "re")
Model 2: y ~ f1 + s(ran, bs = "re")
  Resid. Df Resid. Dev  Df Deviance Pr(>Chi)
114.843 18.340
216.652 21.529 -1.8091   -3.188   0.1752

f2 is no longer significant. The models were changed from REML to ML, as 
recommended for evaluation of fixed effects.

If the interaction is preserved, f2 still remains insignificant using anova:

anova(gam(y ~ f1 + f2 + f1:f2 + s(ran, bs = "re"), data = df2, family = nb, 
method = "ML"),
gam(y ~ f1 + f1:f2 + s(ran, bs = "re"), data = df2, family = nb, method = "ML"),
test="Chisq")
Analysis of Deviance Table

Model 1: y ~ f1 + f2 + f1:f2 + s(ran, bs = "re")
Model 2: y ~ f1 + f1:f2 + s(ran, bs = "re")
  Resid. Df Resid. Dev   Df Deviance Pr(>Chi)
114.843 18.340
215.645 19.194 -0.80159 -0.85391   0.2855

I would be very grateful for advice on which of these approaches is most 
appropriate. Many thanks!



UCLA HEALTH SCIENCES IMPORTANT WARNING: This email (and any attachments) is 
only intended for the use of the person or entity to which it is addressed, and 
may contain information that is privileged and confidential. You, the 
recipient, are obligated to maintain it in a safe, secure and confidential 
manner. Unauthorized redisclosure or failure to maintain confidentiality may 
subject you to federal and state penalties. If you are not the intended 
recipient, please immediately notify us by return email, and delete this 
message from your computer.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.