<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hello Dr. Wolfgang,</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Now it is clear. I really appreciate your time and response.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Marimuthu</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Viechtbauer, Wolfgang (NP) <wolfgang.viechtbauer@maastrichtuniversity.nl><br>
<b>Sent:</b> Thursday, March 6, 2025 4:40 AM<br>
<b>To:</b> Marimuthu S <sm@mcmaster.ca>; R Special Interest Group for Meta-Analysis <r-sig-meta-analysis@r-project.org><br>
<b>Subject:</b> RE: Deviance and it d.f. in pairwise meta analysis</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">[You don't often get email from wolfgang.viechtbauer@maastrichtuniversity.nl. Learn why this is important at
<a href="https://aka.ms/LearnAboutSenderIdentification">https://aka.ms/LearnAboutSenderIdentification</a> ]<br>
<br>
Caution: External email.<br>
<br>
<br>
Ah, now I understand. Interesting question, since this is not something that is discussed in any textbooks or articles on meta-analysis as far as I know.<br>
<br>
First, it may help to clarify how the deviance is computed. Often, deviance is just computed as -2 * log likelihood, but metafor takes the slightly more accurate definition of the deviance as described here:<br>
<br>
<a href="https://en.wikipedia.org/wiki/Deviance_(statistics)">https://en.wikipedia.org/wiki/Deviance_(statistics)</a><br>
<br>
that is, deviance is 2 times the difference of the log likelihood of the 'saturated model' compared to the fitted model of interest. The saturated model is the model that has a parameter for every observation and hence fits perfectly. So let's manually compute
 the deviance for an equal-effects model:<br>
<br>
library(metafor)<br>
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)<br>
<br>
# fit the equal-effects model<br>
res.ee <- rma(yi, vi, data=dat, method="EE")<br>
res.ee<br>
<br>
# fit the saturated model<br>
res.s <- rma(yi, vi, mods = ~ 0 + factor(trial), data=dat, method="FE")<br>
res.s<br>
<br>
# computation of the deviance<br>
2 * c(logLik(res.s) - logLik(res.ee))<br>
<br>
# compare with fitstats()<br>
fitstats(res.ee)<br>
<br>
# deviance = Q statistic<br>
res.ee$QE<br>
<br>
Note that in this case, the deviance is identical to the Q statistic. Hence, under the null hypothesis of homogeneity, the deviance follows a chi-square distribution with k-1 degrees of freedom (just like the Q statistic). To be precise, this assumes unbiased
 estimates, normal sampling distributions, and known sampling variances, so the above is only really true when the sample sizes of the individual studies are sufficiently large. On the other hand, k is not relevant here, so the above is true even when k=2.<br>
<br>
Under a random-effects model, the computation is the same:<br>
<br>
# fit the random-effects model<br>
res.re <- rma(yi, vi, data=dat, method="ML")<br>
res.re<br>
<br>
# computation of the deviance<br>
2 * c(logLik(res.s) - logLik(res.re))<br>
<br>
# compare with fitstats()<br>
fitstats(res.re)<br>
<br>
The saturated model is also res.s (one cannot use method="ML" for the saturated model, since then the model is overparameterized, as tau^2 must be 0 in this model by definition).<br>
<br>
The distribution of the deviance is complicated now, since even when the null hypothesis of homogeneity is true, the estimate of tau^2 will be larger than 0 in about half of the cases, leading to a deviance that is closer to res.s than that of res.ee. However,
 as k gets larger, the estimate of tau^2 also gets increasingly closer to 0, so asymptotically (i.e., when k is large) the deviance will also follow a chi^2 distribution with df = k-1.<br>
<br>
As for your last question: df.residual() always returns k-p, irrespective of the model you have fit (with or without tau^2).<br>
<br>
Best,<br>
Wolfgang<br>
<br>
> -----Original Message-----<br>
> From: Marimuthu S <sm@mcmaster.ca><br>
> Sent: Wednesday, March 5, 2025 16:15<br>
> To: Viechtbauer, Wolfgang (NP) <wolfgang.viechtbauer@maastrichtuniversity.nl>; R<br>
> Special Interest Group for Meta-Analysis <r-sig-meta-analysis@r-project.org><br>
> Subject: Re: Deviance and it d.f. in pairwise meta analysis<br>
><br>
> Hello Dr. Wolfgang,<br>
><br>
> Thank you for your response. I apologize for any confusion. I meant to ask about<br>
> the theoretical distribution of deviance statistics.<br>
> Additionally, I am wondering, do the residual degrees of freedom account for the<br>
> heterogeneity parameter (tau)?<br>
><br>
> Marimuthu<br>
> ________________________________________<br>
> From: Viechtbauer, Wolfgang (NP)<br>
> <<a href="mailto:wolfgang.viechtbauer@maastrichtuniversity.nl">mailto:wolfgang.viechtbauer@maastrichtuniversity.nl</a>><br>
> Sent: Wednesday, March 5, 2025 8:36 AM<br>
> To: R Special Interest Group for Meta-Analysis <<a href=""></a>mailto:r-sig-meta-analysis@r-<br>
> project.org><br>
> Cc: Marimuthu S <<a href="mailto:sm@mcmaster.ca">mailto:sm@mcmaster.ca</a>><br>
> Subject: RE: Deviance and it d.f. in pairwise meta analysis<br>
><br>
> Dear Marimuthu,<br>
><br>
> You can use df.residual() to obtain these:<br>
><br>
> > df.residual(res1)<br>
> [1] 12<br>
><br>
> I am not sure what you mean by 'its distribution'. The df are not a statistic,<br>
> so they do not have a distribution.<br>
><br>
> By the way, no need for REML=F in fitstats() if the model was fitted with ML<br>
> (fitstats() automatically then provides the ML values).<br>
><br>
> Best,<br>
> Wolfgang<br>
><br>
> > -----Original Message-----<br>
> > From: R-sig-meta-analysis <<a href="mailto:r-sig-meta-analysis-bounces@r-project.org">mailto:r-sig-meta-analysis-bounces@r-project.org</a>><br>
> On Behalf<br>
> > Of Marimuthu S via R-sig-meta-analysis<br>
> > Sent: Monday, March 3, 2025 22:12<br>
> > To: Marimuthu S via R-sig-meta-analysis <<a href=""></a>mailto:r-sig-meta-analysis@r-<br>
> project.org><br>
> > Cc: Marimuthu S <<a href="mailto:sm@mcmaster.ca">mailto:sm@mcmaster.ca</a>><br>
> > Subject: [R-meta] Deviance and it d.f. in pairwise meta analysis<br>
> ><br>
> > Hello Everyone,<br>
> ><br>
> > I fitted meta-analysis model using rma() function. I can extract all the fit<br>
> > statistics using fitstats() function. But it doesn't give degrees of freedom<br>
> > (d.f) for deviance.<br>
> ><br>
> > Could you please let me know if it's possible to calculate the deviance<br>
> degrees<br>
> > of freedom (d.f.) and derive its distribution in pairwise meta-analysis? If<br>
> it's<br>
> > not feasible, I'd appreciate understanding the reasons behind it. Any insights<br>
> > or leads would be greatly appreciated. Thank you for your time!<br>
> ><br>
> > Here is my code:<br>
> ><br>
> > library(metafor)<br>
> ><br>
> > dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)<br>
> > ### fit random-effects model<br>
> > res1 <- rma(yi, vi, data=dat, method="ML")<br>
> ><br>
> > > fitstats(res1, REML=F)<br>
> >                  ML<br>
> > logLik:   -12.66508<br>
> > deviance:  37.11602<br>
> > AIC:       29.33015<br>
> > BIC:       30.46005<br>
> > AICc:      30.53015<br>
> ><br>
> > Regards,<br>
> ><br>
> > Marimuthu,<br>
> > Ph.D. candidate<br>
> > McMaster University, Canada<br>
</div>
</span></font></div>
</body>
</html>