Re: [R] lme: null deviance, deviance due to the random effects, residual deviance

2006-05-02 Thread Prof Brian Ripley
On Mon, 1 May 2006, Spencer Graves wrote:

 As far as I know, the term deviance has no standard definition.  A
 good, fairly common definition (I think) is that the deviance is up to
 [an additive] constant, minus twice the maximised log-likelihood. Where
 sensible, the constant is chosen so that a saturated model has deviance
 zero.  (http://finzi.psych.upenn.edu/R/library/gnm/html/gnm.html;.)
 Because of this constant, the the proportion of deviance 'explained'
 by the model in not a well defined concept.  I found this definition
 using RSiteSearch(deviance define).  However, even this definition is
 not used consistently;  it's not even used for 'deviance.lm', which I
 discovered using methods(deviance) and methods(logLik) followed by
 'getAnywhere(deviance.lm), etc.

It _is_ used by deviance.lm.  In that case the saturated model has 
infinite log-likelihood, so it would not be sensible to choose an infinite 
constant and if you did the result for the saturated model would be NaN 
(= Inf - Inf).

McCullagh  Nelder (1989) would be the authorative reference, but the 1982 
first edition manages to use 'deviance' in three separate senses on one 
page.  In particular, what you are describing is the unscaled residual 
deviance.

 This is not a trivial and stupid question.  Instead, it's connected
 to subtle issues in statistical methods, and this reply may contribute
 more obfuscation than enlightenment.  If you describe some more specific
 application where you might want to use something like this and what you
 are trying to achieve, you might get a more useful reply.

He may be looking for extensions/analogues of R^2, of which there exist 
several.

 hope this helps,
 spencer graves

 Patrick Giraudoux wrote:

 A maybe trivial and stupid question:

 In the case of a lm or glm fit, it is quite informative (to me) to have
 a look to the null deviance and the residual deviance of a model. This
 is generally provided in the print method or the summary, eg:

 Null Deviance:  658.8
 Residual Deviance: 507.3

 and (a bit simpled minded) I like to think that the proportion of
 deviance 'explained' by the model is (658.8-507.3)/658.8 = 23%

 In the case of lme models, is it possible and reasonable to try and get the:
 - null deviance
 - the total deviance due to the the random effect(s)
 - the residual deviance?

 With the idea that Null deviance = Fixed effects + Random Effects +
 Residuals

 If yes how to do it ? A lme object provides the following:

  names(glm6)
  [1] modelStruct  dims contrastscoefficients
  [5] varFix   sigmaapVarlogLik
  [9] numIter  groups   call method
 [13] fitted   residualsfixDFfamily

 so no $null.deviance and $deviance elements as in glm objects...

 I tried to find out an answer on R-help  Pineihro  Bates (2000).
 Partial success only:

 - null deviance: Response: possibly yes: see
 http://tolstoy.newcastle.edu.au/R/help/05/12/17796.html (Spencer
 Graves). The (null?) deviance is -2*logLik(mylme), but a personnal trial
 with some glm objects did not led to the same numbers that the one given
 by the print.glm method...

 - the deviance due to the the random effect(s). I was supposing that the
 coefficients given by ranef(mylme) may be an entry... but beyond this, I
 guess those coefficients must be weighed in some way... which is a far
 beyond my capacities in this matter...

 - residual deviance. I was supposing that it may be
 sum(residuals(mylme)^2). With some doubts as far as I feel that I am
 thinking sum of squares estimation in the context of likelihood and
 deviance estimations... So  most likely irrelevant. Moreover, in the
 case I was exploring, this quantity is much larger than the null
 deviance computed as above...

 Any hint appreciated,

 Patrick Giraudoux

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] lme: null deviance, deviance due to the random effects, residual deviance

2006-05-02 Thread Spencer Graves
Dear Prof. Ripley:
comments in line

Prof Brian Ripley wrote:
 On Mon, 1 May 2006, Spencer Graves wrote:
snip
 
 McCullagh  Nelder (1989) would be the authorative reference, but the 
 1982 first edition manages to use 'deviance' in three separate senses on 
 one page.  In particular, what you are describing is the unscaled 
 residual deviance.
 
Thanks:  I'll review this carefully.

Best Wishes,
spencer graves

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] lme: null deviance, deviance due to the random effects, residual deviance

2006-05-01 Thread Spencer Graves
  As far as I know, the term deviance has no standard definition.  A 
good, fairly common definition (I think) is that the deviance is up to 
[an additive] constant, minus twice the maximised log-likelihood. Where 
sensible, the constant is chosen so that a saturated model has deviance 
zero.  (http://finzi.psych.upenn.edu/R/library/gnm/html/gnm.html;.) 
Because of this constant, the the proportion of deviance 'explained' 
by the model in not a well defined concept.  I found this definition 
using RSiteSearch(deviance define).  However, even this definition is 
not used consistently;  it's not even used for 'deviance.lm', which I 
discovered using methods(deviance) and methods(logLik) followed by 
'getAnywhere(deviance.lm), etc.

  This is not a trivial and stupid question.  Instead, it's connected 
to subtle issues in statistical methods, and this reply may contribute 
more obfuscation than enlightenment.  If you describe some more specific 
application where you might want to use something like this and what you 
are trying to achieve, you might get a more useful reply.

  hope this helps,
  spencer graves

Patrick Giraudoux wrote:

 A maybe trivial and stupid question:
 
 In the case of a lm or glm fit, it is quite informative (to me) to have 
 a look to the null deviance and the residual deviance of a model. This 
 is generally provided in the print method or the summary, eg:
 
 Null Deviance:  658.8
 Residual Deviance: 507.3
 
 and (a bit simpled minded) I like to think that the proportion of 
 deviance 'explained' by the model is (658.8-507.3)/658.8 = 23%
 
 In the case of lme models, is it possible and reasonable to try and get the:
 - null deviance
 - the total deviance due to the the random effect(s)
 - the residual deviance?
 
 With the idea that Null deviance = Fixed effects + Random Effects + 
 Residuals
 
 If yes how to do it ? A lme object provides the following:
 
   names(glm6)
  [1] modelStruct  dims contrastscoefficients
  [5] varFix   sigmaapVarlogLik 
  [9] numIter  groups   call method 
 [13] fitted   residualsfixDFfamily
 
 so no $null.deviance and $deviance elements as in glm objects...
 
 I tried to find out an answer on R-help  Pineihro  Bates (2000). 
 Partial success only:
 
 - null deviance: Response: possibly yes: see 
 http://tolstoy.newcastle.edu.au/R/help/05/12/17796.html (Spencer 
 Graves). The (null?) deviance is -2*logLik(mylme), but a personnal trial 
 with some glm objects did not led to the same numbers that the one given 
 by the print.glm method...
 
 - the deviance due to the the random effect(s). I was supposing that the 
 coefficients given by ranef(mylme) may be an entry... but beyond this, I 
 guess those coefficients must be weighed in some way... which is a far 
 beyond my capacities in this matter...
 
 - residual deviance. I was supposing that it may be 
 sum(residuals(mylme)^2). With some doubts as far as I feel that I am 
 thinking sum of squares estimation in the context of likelihood and 
 deviance estimations... So  most likely irrelevant. Moreover, in the 
 case I was exploring, this quantity is much larger than the null 
 deviance computed as above...
 
 Any hint appreciated,
 
 Patrick Giraudoux
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] lme: null deviance, deviance due to the random effects, residual deviance

2006-05-01 Thread Andrew Robinson
I often want to know what proportion of the variation is being
contributed by different levels of random effects. 

When the random effects are only intercepts, with no slopes, then you
can compute the intra-class correlation, which is the proportion of
the variation explained by the different levels of random effects,
using components from the output of VarCorr.  I wrote a function that
extracts the components and computes them for such models:

varianceDetails - function(model) {
  if (class(model) != lme) 
  stop(Input must be an lme!)
  dimension - floor(dim(VarCorr(model))[1])/2
  j - c(1:dimension) * 2
  if (length(j) == 1) 
  j - 1
  i - c(j, dim(VarCorr(model))[1])
  variances - as.numeric(VarCorr(model)[i, 1])
  mse - sum(variances)
  icc - rep(0, length(j))
  for (k in 1:length(j)) icc[k] - as.numeric(VarCorr(model)[j[k], 
  1])/mse
  rmse - sqrt(mse)
  list(icc = icc, rmse = rmse)
}

e.g.

 require(nlme)
 fm1 - lme(distance ~ age, data = Orthodont)
 varianceDetails(fm1)

(Any feedback on that function is welcomed!)

This function uses the ReML estimates of the variance components (if
the fiting method is ReML!).  When the random effects have slopes then
the problem is more tricky, as the proportion of variance explained
will depend on the predictor variables (see Goldstein et al. at

http://www.mlwin.com/team/materials/pvmm.pdf

).  As a loose rule of thumb, I tend to take a method-of-moments type
of estimate of the standard deviation of the residuals at each level,
and compare those.

Thus,

 sd(Orthodont$distance)
 sd(residuals(fm1, level=0, type=response))
 sd(residuals(fm1, level=1, type=response))

You can compute an ad-hoc icc from those components, if you are
comfortable averaging across the random effects.  They will not be the
same as those from varianceDetails, above, because they're not based
on the ReML estimates of the variance components.

I suspect that fitting more complex random effects structures will
render these estimates invalid.  I welcome any further comments on
these ideas.

Cheers

Andrew

 Patrick Giraudoux wrote:
 
 A maybe trivial and stupid question:
 
 In the case of a lm or glm fit, it is quite informative (to me) to have 
 a look to the null deviance and the residual deviance of a model. This 
 is generally provided in the print method or the summary, eg:
 
 Null Deviance:  658.8
 Residual Deviance: 507.3
 
 and (a bit simpled minded) I like to think that the proportion of 
 deviance 'explained' by the model is (658.8-507.3)/658.8 = 23%
 
 In the case of lme models, is it possible and reasonable to try and get the:
 - null deviance
 - the total deviance due to the the random effect(s)
 - the residual deviance?
 
 With the idea that Null deviance = Fixed effects + Random Effects + 
 Residuals
 
 If yes how to do it ? A lme object provides the following:
 
   names(glm6)
  [1] modelStruct  dims contrastscoefficients
  [5] varFix   sigmaapVarlogLik 
  [9] numIter  groups   call method 
 [13] fitted   residualsfixDFfamily
 
 so no $null.deviance and $deviance elements as in glm objects...
 
 I tried to find out an answer on R-help  Pineihro  Bates (2000). 
 Partial success only:
 
 - null deviance: Response: possibly yes: see 
 http://tolstoy.newcastle.edu.au/R/help/05/12/17796.html (Spencer 
 Graves). The (null?) deviance is -2*logLik(mylme), but a personnal trial 
 with some glm objects did not led to the same numbers that the one given 
 by the print.glm method...
 
 - the deviance due to the the random effect(s). I was supposing that the 
 coefficients given by ranef(mylme) may be an entry... but beyond this, I 
 guess those coefficients must be weighed in some way... which is a far 
 beyond my capacities in this matter...
 
 - residual deviance. I was supposing that it may be 
 sum(residuals(mylme)^2). With some doubts as far as I feel that I am 
 thinking sum of squares estimation in the context of likelihood and 
 deviance estimations... So  most likely irrelevant. Moreover, in the 
 case I was exploring, this quantity is much larger than the null 
 deviance computed as above...
 
 Any hint appreciated,
 
 Patrick Giraudoux
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

-- 
Andrew Robinson  
Department of Mathematics and StatisticsTel: +61-3-8344-9763
University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599
Email: [EMAIL PROTECTED] http://www.ms.unimelb.edu.au

__

Re: [R] lme: null deviance, deviance due to the random effects, residual deviance

2006-05-01 Thread Patrick Giraudoux
Andrew and Spencer,

Thanks for your answers. I was feeling that moving from variance and 
least-square estimates to deviance and MLE or REML was the reason why 
I could not find easy equivalent estimates for the proportion of 
variation of a given effect to the total. Thus this was not a trivial 
issue... I will try and understand Andrew's function which will be 
helpful to make the things clearer in my mind. Your advice both are 
useful and drive people on the good track.

All the best,

Patrick

Spencer Graves a écrit :
   As far as I know, the term deviance has no standard 
 definition.  A good, fairly common definition (I think) is that the 
 deviance is up to [an additive] constant, minus twice the maximised 
 log-likelihood. Where sensible, the constant is chosen so that a 
 saturated model has deviance zero.  
 (http://finzi.psych.upenn.edu/R/library/gnm/html/gnm.html;.) Because 
 of this constant, the the proportion of deviance 'explained' by the 
 model in not a well defined concept.  I found this definition using 
 RSiteSearch(deviance define).  However, even this definition is not 
 used consistently;  it's not even used for 'deviance.lm', which I 
 discovered using methods(deviance) and methods(logLik) followed by 
 'getAnywhere(deviance.lm), etc.

   This is not a trivial and stupid question.  Instead, it's 
 connected to subtle issues in statistical methods, and this reply may 
 contribute more obfuscation than enlightenment.  If you describe some 
 more specific application where you might want to use something like 
 this and what you are trying to achieve, you might get a more useful 
 reply.

   hope this helps,
   spencer graves

 Patrick Giraudoux wrote:

 A maybe trivial and stupid question:

 In the case of a lm or glm fit, it is quite informative (to me) to 
 have a look to the null deviance and the residual deviance of a 
 model. This is generally provided in the print method or the summary, 
 eg:

 Null Deviance:  658.8
 Residual Deviance: 507.3

 and (a bit simpled minded) I like to think that the proportion of 
 deviance 'explained' by the model is (658.8-507.3)/658.8 = 23%

 In the case of lme models, is it possible and reasonable to try and 
 get the:
 - null deviance
 - the total deviance due to the the random effect(s)
 - the residual deviance?

 With the idea that Null deviance = Fixed effects + Random Effects + 
 Residuals

 If yes how to do it ? A lme object provides the following:

   names(glm6)
  [1] modelStruct  dims contrastscoefficients
  [5] varFix   sigmaapVarlogLik  [9] 
 numIter  groups   call method [13] 
 fitted   residualsfixDFfamily

 so no $null.deviance and $deviance elements as in glm objects...

 I tried to find out an answer on R-help  Pineihro  Bates (2000). 
 Partial success only:

 - null deviance: Response: possibly yes: see 
 http://tolstoy.newcastle.edu.au/R/help/05/12/17796.html (Spencer 
 Graves). The (null?) deviance is -2*logLik(mylme), but a personnal 
 trial with some glm objects did not led to the same numbers that the 
 one given by the print.glm method...

 - the deviance due to the the random effect(s). I was supposing that 
 the coefficients given by ranef(mylme) may be an entry... but beyond 
 this, I guess those coefficients must be weighed in some way... which 
 is a far beyond my capacities in this matter...

 - residual deviance. I was supposing that it may be 
 sum(residuals(mylme)^2). With some doubts as far as I feel that I am 
 thinking sum of squares estimation in the context of likelihood and 
 deviance estimations... So  most likely irrelevant. Moreover, in the 
 case I was exploring, this quantity is much larger than the null 
 deviance computed as above...

 Any hint appreciated,

 Patrick Giraudoux

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] lme: null deviance, deviance due to the random effects, residual deviance

2006-04-23 Thread Patrick Giraudoux
A maybe trivial and stupid question:

In the case of a lm or glm fit, it is quite informative (to me) to have 
a look to the null deviance and the residual deviance of a model. This 
is generally provided in the print method or the summary, eg:

Null Deviance:  658.8
Residual Deviance: 507.3

and (a bit simpled minded) I like to think that the proportion of 
deviance 'explained' by the model is (658.8-507.3)/658.8 = 23%

In the case of lme models, is it possible and reasonable to try and get the:
- null deviance
- the total deviance due to the the random effect(s)
- the residual deviance?

With the idea that Null deviance = Fixed effects + Random Effects + 
Residuals

If yes how to do it ? A lme object provides the following:

  names(glm6)
 [1] modelStruct  dims contrastscoefficients
 [5] varFix   sigmaapVarlogLik 
 [9] numIter  groups   call method 
[13] fitted   residualsfixDFfamily

so no $null.deviance and $deviance elements as in glm objects...

I tried to find out an answer on R-help  Pineihro  Bates (2000). 
Partial success only:

- null deviance: Response: possibly yes: see 
http://tolstoy.newcastle.edu.au/R/help/05/12/17796.html (Spencer 
Graves). The (null?) deviance is -2*logLik(mylme), but a personnal trial 
with some glm objects did not led to the same numbers that the one given 
by the print.glm method...

- the deviance due to the the random effect(s). I was supposing that the 
coefficients given by ranef(mylme) may be an entry... but beyond this, I 
guess those coefficients must be weighed in some way... which is a far 
beyond my capacities in this matter...

- residual deviance. I was supposing that it may be 
sum(residuals(mylme)^2). With some doubts as far as I feel that I am 
thinking sum of squares estimation in the context of likelihood and 
deviance estimations... So  most likely irrelevant. Moreover, in the 
case I was exploring, this quantity is much larger than the null 
deviance computed as above...

Any hint appreciated,

Patrick Giraudoux

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html