Re: [R] standardized random effects with ranef.lme()

2006-07-31 Thread Doran, Harold
OK, I see how the standardized random effects are calculated. Here is
what I now see

library(nlme)

fm2 - lme(distance~age, Orthodont)

# unstandardized
age_ranef - ranef(fm2)[,2]

#standardized
age_Sranef - ranef(fm2, standard=TRUE)[,2]

# We can use these to solve for the standard error, because the formula
according to help for ranef.lme is

# Standardized_randomEffects = random_effects/standard error

age_ranef/age_Sranef

# OK, now note the values are exactly the same. Now, look at

VarCorr(fm2)

You can see the value used to standardize is the standard deviation of
the random effect for age.

Now, the help function does say divided by the corresponding standard
error. 

I've copied Doug Bates because the values in the stdDev column are the
standard deviations of the variance components and not standard errors
of those variance components. So, I'm not sure why the help says that
the standardized random effects are divided by the corresponding SE.
Maybe he can clarify if he has time.

I hope that helps
Harold


 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Doran, Harold
 Sent: Sunday, July 30, 2006 3:40 PM
 To: Spencer Graves; Dirk Enzmann
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] standardized random effects with ranef.lme()
 
  
   Why do the results differ although the estimates (random
  effects and
   thus their variances) are almost identical? I noticed that
  lme() does
   not compute the standard errors of the variances of the
  random effects
   - for several reasons, but if this is true, how does
  ranef() calculate
   the standardized random effects (the help says: 
  'standardized (i.e.
   divided by the corresponding estimated standard error)').
   
   Is there a way to obtain similar results as in MLWin (or: 
 should I 
   prefer the results of ranef() for certain reasons)?
 
 I think there are two different issues here. The lme function 
 does not produce a standard error of the variance component 
 as some other multilevel packages do. It is often recommended 
 in the multilevel literature to consider the p-value of the 
 variance components and fix
 or retain the variance if p  .05. There are good reasons not 
 to follow this practice.
 
 If you were using lmer(), you still wouldn't get this 
 statistic, but you could use the MCMCsamp() function to 
 examine the distribution of the random effects.
 
 The second issue (I think) is that the conditional variance 
 of the random effect is not the same as the standard error of 
 the variance of the random effect. From the definition in the 
 help of ranef.lme, I believe it is the random effect divided 
 by its conditional standard error. I don't know how to get 
 the posterior variance of the random effects in lme, but I do 
 in lmer, so we can experiment a bit. It has been a while 
 since I have really used lme and I do not think there is an 
 extractor function to get these and I didn't see the 
 variances in the model object.
 
 Let's work through an example to see what we get. Here is what I see
 
 library(nlme)
 data(Orthodont)
 detach(package:nlme)
 
 library(Matrix)
 fm1 - lmer(distance ~ age + (age|Subject), data = Orthodont) 
 # equivalent to # fm1 - lme(distance ~ age, data=Orthodont)
 
 # Extract the variances of the random effects qq - 
 attr(ranef(fm1, postVar = TRUE)[[1]], postVar)
 
 # divide the random effects by their standard error of age
 Sranef_lmer - ranef(fm1)[[1]][,2]/ sqrt(qq[2,2,])
 
 library(nlme)
 # Now, run the lme model
 fm2 - lme(distance ~ age, Orthodont)
 
 # get the standardized random effects from lme Sranef_lme - 
 ranef(fm2, standard=T)[2]
 
 cor(Sranef_lmer, Sranef_lme)
 [1] 1
 
 Notice the perfect correlation. But, the actual values in 
 Sranef_lme and Sranef_lmer are a bit different and I cannot 
 see why just yet. I need to go eat lunch, but I'll think about this. 
 
 Maybe somebody else sees something.
 
 __
 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
 and provide commented, minimal, self-contained, reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] standardized random effects with ranef.lme()

2006-07-30 Thread Spencer Graves
  Have you tried RSiteSearch(MLWin)?  I just got 29 hits.  I wonder 
if any one of these might relate to your question?

  If you would like more help on this issue from this listserve, please 
submit another post, preferably illustrating your question with the 
simplest possible self-contained example that illustrates your question, 
perhaps like the following:

  fm1.16 - lme(distance~age, data=Orthodont[1:16,],
random=~age|Subject)

  Hope this helps.
  Spencer Graves
p.s.  PLEASE do read the posting guide 
www.R-project.org/posting-guide.html and provide commented, minimal, 
self-contained, reproducible code.

Dirk Enzmann wrote:
 Using ranef() (package nlme, version 3.1-75) with an 'lme' object I can 
 obtain random effects for intercept and slope of a certain level (say: 
 1) - this corresponds to (say level 1) residuals in MLWin. Maybe I'm 
 mistaken here, but the results are identical.
 
 However, if I try to get the standardized random effects adding the 
 paramter standard=T to the specification of ranef(), the results 
 differ considerably from the results of MLWin (although MLWin defines 
 standardized in the same way as divided by its estimated (diagnostic) 
 standard error).
 
 Why do the results differ although the estimates (random effects and 
 thus their variances) are almost identical? I noticed that lme() does 
 not compute the standard errors of the variances of the random effects - 
 for several reasons, but if this is true, how does ranef() calculate the 
 standardized random effects (the help says: 'standardized (i.e. 
 divided by the corresponding estimated standard error)').
 
 Is there a way to obtain similar results as in MLWin (or: should I 
 prefer the results of ranef() for certain reasons)?
 
 Dirk
 
 -
 R version: 2.3.1 Patched (2006-06-21 r38367)
 
 
 *
 Dr. Dirk Enzmann
 Institute of Criminal Sciences
 Dept. of Criminology
 Edmund-Siemers-Allee 1
 D-20146 Hamburg
 Germany
 
 phone: +49-(0)40-42838.7498 (office)
 +49-(0)40-42838.4591 (Billon)
 fax:   +49-(0)40-42838.2344
 email: [EMAIL PROTECTED]
 www: 
 http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Enzmann.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
 and provide commented, minimal, self-contained, reproducible code.

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] standardized random effects with ranef.lme()

2006-07-30 Thread Doran, Harold
 
  Why do the results differ although the estimates (random 
 effects and 
  thus their variances) are almost identical? I noticed that 
 lme() does 
  not compute the standard errors of the variances of the 
 random effects 
  - for several reasons, but if this is true, how does 
 ranef() calculate 
  the standardized random effects (the help says: 
 'standardized (i.e.
  divided by the corresponding estimated standard error)').
  
  Is there a way to obtain similar results as in MLWin (or: should I 
  prefer the results of ranef() for certain reasons)?

I think there are two different issues here. The lme function does not
produce a standard error of the variance component as some other
multilevel packages do. It is often recommended in the multilevel
literature to consider the p-value of the variance components and fix
or retain the variance if p  .05. There are good reasons not to follow
this practice.

If you were using lmer(), you still wouldn't get this statistic, but you
could use the MCMCsamp() function to examine the distribution of the
random effects.

The second issue (I think) is that the conditional variance of the
random effect is not the same as the standard error of the variance of
the random effect. From the definition in the help of ranef.lme, I
believe it is the random effect divided by its conditional standard
error. I don't know how to get the posterior variance of the random
effects in lme, but I do in lmer, so we can experiment a bit. It has
been a while since I have really used lme and I do not think there is an
extractor function to get these and I didn't see the variances in the
model object.

Let's work through an example to see what we get. Here is what I see

library(nlme)
data(Orthodont)
detach(package:nlme)

library(Matrix)
fm1 - lmer(distance ~ age + (age|Subject), data = Orthodont)
# equivalent to
# fm1 - lme(distance ~ age, data=Orthodont)

# Extract the variances of the random effects
qq - attr(ranef(fm1, postVar = TRUE)[[1]], postVar)

# divide the random effects by their standard error of age
Sranef_lmer - ranef(fm1)[[1]][,2]/ sqrt(qq[2,2,])

library(nlme)
# Now, run the lme model
fm2 - lme(distance ~ age, Orthodont)

# get the standardized random effects from lme
Sranef_lme - ranef(fm2, standard=T)[2]

cor(Sranef_lmer, Sranef_lme)
[1] 1

Notice the perfect correlation. But, the actual values in Sranef_lme and
Sranef_lmer are a bit different and I cannot see why just yet. I need to
go eat lunch, but I'll think about this. 

Maybe somebody else sees something.

__
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
and provide commented, minimal, self-contained, reproducible code.


[R] standardized random effects with ranef.lme()

2006-07-24 Thread Dirk Enzmann
Using ranef() (package nlme, version 3.1-75) with an 'lme' object I can 
obtain random effects for intercept and slope of a certain level (say: 
1) - this corresponds to (say level 1) residuals in MLWin. Maybe I'm 
mistaken here, but the results are identical.

However, if I try to get the standardized random effects adding the 
paramter standard=T to the specification of ranef(), the results 
differ considerably from the results of MLWin (although MLWin defines 
standardized in the same way as divided by its estimated (diagnostic) 
standard error).

Why do the results differ although the estimates (random effects and 
thus their variances) are almost identical? I noticed that lme() does 
not compute the standard errors of the variances of the random effects - 
for several reasons, but if this is true, how does ranef() calculate the 
standardized random effects (the help says: 'standardized (i.e. 
divided by the corresponding estimated standard error)').

Is there a way to obtain similar results as in MLWin (or: should I 
prefer the results of ranef() for certain reasons)?

Dirk

-
R version: 2.3.1 Patched (2006-06-21 r38367)


*
Dr. Dirk Enzmann
Institute of Criminal Sciences
Dept. of Criminology
Edmund-Siemers-Allee 1
D-20146 Hamburg
Germany

phone: +49-(0)40-42838.7498 (office)
+49-(0)40-42838.4591 (Billon)
fax:   +49-(0)40-42838.2344
email: [EMAIL PROTECTED]
www: 
http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Enzmann.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
and provide commented, minimal, self-contained, reproducible code.