Hi

Thank you to everyone for their comments.  I have produced an example 
below that tests some of these suggestions.

*Suggestion 1*
As suggested by AJ, Stamps et al have paper (just out in Animal 
behaviour) that show you calculate the difference between the predicted 
values and the residuals.  This then produces variances (or sd) for each 
level of the random effect.
*Suggestion 2*
To use lme and extract the within individual variance

I have run both suggestions and the variance component estimated 
differs.  I used lme (which I am much familiar with than lmer) as I 
think its important to know that the differences are not due to 
differences in model fitting.    I am wondering if method one is 
estimating the variance AFTER controlled for the fixed effects and 
method two is just directly measuring the variation in the raw data?

Any advice or direction as to possible references would be great.

Many thanks again; code below

Sam


 > data2
               y Block Time
1   0.977819245     1    1
2   0.306242178     1    2
3   0.265774140     1    3
4   0.819177345     1    4
5   0.610355692     1    5
6   0.467026036     1    6
7   0.275805483     1    7
8   0.926585897     1    8
9   0.890203294     1    9
10  0.392368450     1   10
11  0.190502621     2    1
12  0.238668971     2    2
13  0.043556818     2    3
14  0.128361382     2    4
15  0.136682601     2    5
16  0.460275559     2    6
17  0.249634883     2    7
18  0.416955509     2    8
19  0.792641427     2    9
20  0.599289483     2   10
21  0.336284310     3    1
22  0.876126239     3    2
23  0.130996247     3    3
24  0.466843232     3    4
25  0.271740334     3    5
26  0.732592376     3    6
27  0.712552187     3    7
28  0.277677487     3    8
29  0.287206525     3    9
30  0.304498359     3   10
31  0.455101650     4    1
32  0.846517960     4    2
33  0.912369545     4    3
34  0.604695926     4    4
35  0.237085531     4    5
36  0.170722768     4    6
37  0.879433398     4    7
38  0.241689802     4    8
39  0.987422313     4    9
40  0.933385790     4   10
41  0.368632540     5    1
42  0.261411309     5    2
43  0.469305922     5    3
44  0.796264513     5    4
45  0.652836283     5    5
46  0.946473034     5    6
47  0.379856922     5    7
48  0.531121811     5    8
49  0.645196312     5    9
50  0.504268732     5   10
51  0.805114775     6    1
52  0.901109327     6    2
53  0.518454319     6    3
54  0.681273434     6    4
55  0.195278530     6    5
56  0.978644194     6    6
57  0.670394298     6    7
58  0.714575365     6    8
59  0.059195227     6    9
60  0.841575562     6   10
61  0.304905008     7    1
62  0.565829044     7    2
63  0.694229494     7    3
64  0.732948738     7    4
65  0.434869158     7    5
66  0.921195936     7    6
67  0.337104752     7    7
68  0.229010248     7    8
69  0.531911872     7    9
70  0.394782682     7   10
71  0.906618996     8    1
72  0.609400039     8    2
73  0.860838522     8    3
74  0.651871570     8    4
75  0.884503377     8    5
76  0.745266319     8    6
77  0.442963967     8    7
78  0.704702252     8    8
79  0.188519983     8    9
80  0.855435914     8   10
81  0.433171295     9    1
82  0.111167792     9    2
83  0.220680767     9    3
84  0.007358407     9    4
85  0.477189772     9    5
86  0.586904276     9    6
87  0.538873005     9    7
88  0.495513779     9    8
89  0.558610846     9    9
90  0.484776136     9   10
91  0.213045639    10    1
92  0.914657432    10    2
93  0.356709341    10    3
94  0.187208544    10    4
95  0.733852696    10    5
96  0.694574279    10    6
97  0.174437282    10    7
98  0.860861288    10    8
99  0.221450340    10    9
100 0.526692213    10   10

library(lme4)
attach(data2)
head(data2)
m1<-lme(y~ Time , random= ~1|Block, weights=varIdent(form=~1|Block))

## to extract the var directly from lmer using post Var


ranef(m1)
ranef(m1, postVar=TRUE)
attr((ranef(m1, postVar = TRUE))[[1]],"postVar")

##I get the same variance per level of random effect

#Using methods outlines in Stamps et al. Animal Behaviour June 2012
#(I keep the names of the terms the same as theirs)

data2$pearsonsresidual1<-resid(m1)

mm = model.matrix(terms(m1),data2)
data2$Pred= mm %*% fixef(m1)

data2$Resid <-data2$y - data2$Pred
data2$squaredresid <- data2$Resid^2
data2$absolutedeviation <-abs(data2$Resid)

# probably a very inefficeint way to do this...
residsoutput=0
for (i in 1:10) {
     datasub <-subset(data2, Block==i)   ##
     sumdev= sum(datasub$absolutedeviation)
     SS=sum(datasub$squaredresid)
     variance = SS/9
     sd1 = sqrt(variance)
     averabsdev= sumdev/10
     averpred =sum(datasub$Pred)/10
     residsoutput<-rbind(residsoutput,sd1)
       }
residsoutput<-residsoutput[-1]


##this produces a different answer to the direct output from lmer
## If i then run the model as an lme

m2<-lme(y~ Time, random= ~1|Block, weights=varIdent(form=~1|Block))
variancelme<-summary(m2)$modelStruct$varStruct

## as i was having problems corecing this I just re-entered the data for 
ease...
variancelme<-cbind(1.0000000,0.7824019,0.8897331,1.1239647,0.7015587,1.0826729,0.7832847,0.8768453,0.6609932,1.0120726) 


## to then compare the two different methods
plot(variancelme,residsoutput)




Le 18/06/2012 12:43, Luca Borger a écrit :
> >Perhaps theres a way to get at the estimates it produces...
>
> summary(myModel)$modelStruc$varStruc
>
>
>
> Le 18/06/2012 11:39, Alan Haynes a écrit :
>> Hi there,
>>
>> If youre not fixed on either lmer or mcmcglmm particularly, ot might be
>> possible using lme...
>> Using the weights argument you can allow an individuals variance (in 
>> your
>> case) to vary. Perhaps theres a way to get at the estimates it 
>> produces...
>>
>>
>> HTH
>>
>> Alan
>>
>> --------------------------------------------------
>> Email: aghaynes@gmail.com
>> Mobile: +41794385586
>> Skype: aghaynes
>>
>>
>> On 18 June 2012 11:06, Luca Borger <lborger@cebc.cnrs.fr> wrote:
>>
>>> Hello,
>>>
>>> I think there have been some recent papers on estimating individual
>>> variability in behaviour, but in any case is this useful?:
>>>
>>> library(lme4)
>>> fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
>>> str(ranef(fm1, postVar = TRUE))
>>> attr((ranef(fm1, postVar = TRUE))[[1]],"postVar")
>>>
>>>
>>> HTH
>>> Luca
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> # Forthcoming book chapter
>>> # Dispersal Ecology and Evolution (ch. 17)
>>> # 
>>> http://ukcatalogue.oup.com/**product/9780199608904.do<http://ukcatalogue.oup.com/product/9780199608904.do>
>>> ------------------------------**------------------------------**--------- 
>>>
>>> Luca Borger
>>> Postdoctoral Research Fellow
>>>
>>> Centre d'Etudes Biologiques de Chizé
>>> CNRS (UPR1934); INRA (USC1339)
>>> 79360 Villiers-en-Bois, France
>>>
>>> Tel: +33 (0)549 09 96 13
>>> Fax: +33 (0)549 09 65 26
>>> email: lborger@cebc.cnrs.fr
>>> Web: 
>>> http://cnrs.academia.edu/**LucaBorger<http://cnrs.academia.edu/LucaBorger>
>>> Researcher ID: 
>>> http://www.researcherid.com/**rid/C-6003-2008<http://www.researcherid.com/rid/C-6003-2008>
>>> Google Scholar: 
>>> http://scholar.google.com/**citations?user=D5CTvNUAAAAJ<http://scholar.google.com/citations?user=D5CTvNUAAAAJ>
>>> ------------------------------**------------------------------**--------- 
>>>
>>> # Newly published! Animal Migration: A synthesis (ch. 8):
>>> # 
>>> http://ukcatalogue.oup.com/**product/9780199568994.do<http://ukcatalogue.oup.com/product/9780199568994.do>
>>>
>>> Le 18/06/2012 10:29, Samantha Patrick a écrit :
>>>
>>>   Hi
>>>>
>>>> I am currently trying to estimate how consistent individuals are in a
>>>> trait.  I want to produce an estimate of the variability for each 
>>>> level of
>>>> a random effect (ID).  I can do this simply by calculation the 
>>>> variance for
>>>> each ID separately but I am trying to extract this information from 
>>>> a mixed
>>>> model (either in lmer or mcmcglmm).  I have trawled the mailing 
>>>> list but
>>>> can not find any answers.
>>>>
>>>> As an simplified dummy example I have 2 individuals, each with 5
>>>> observations of a trait.  I can calculate 2 variances, using the 5
>>>> observations for each individual.
>>>>
>>>> head(Data)
>>>> ID    trait1
>>>> 1        10
>>>> 1        15
>>>> 1        12
>>>> 1        19
>>>> 1        11
>>>> 2        9
>>>> 2        10
>>>> 2        9
>>>> 2        10
>>>> 2        10
>>>>
>>>> Variance for 1 = 4.67
>>>> Variance for 2 = 0.3
>>>>
>>>> Alternatively I can fit a model of:
>>>>
>>>> model1<-lmer(trait1 ~(1|ID))
>>>>
>>>>  From the variance covariance matrix I can easily extract the 
>>>> between and
>>>> within group variances, but is there a way to extract individual 
>>>> variance
>>>> estimates?
>>>>
>>>> Many Thanks
>>>>
>>>> Sam
>>>>
>>>>
>>> ______________________________**_________________
>>> R-sig-mixed-models@r-project.**org 
>>> <R-sig-mixed-models@r-project.org>mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-sig-mixed-models<https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models> 
>>>
>>>
>>
>
>
>
>

-- 

Dr Samantha Patrick
Post Doctoral Fellow
Centre d'Etudes Biologiques de Chizé - CNRS
79360 Villiers-en-Bois
France
T:+33 549 097 846
M:+33 675 603 451
Skype: sammy_patrick
http://www.cebc.cnrs.fr/Fidentite/patrick/patrick.htm
http://www.researchgate.net/profile/Samantha_Patrick/


	[[alternative HTML version deleted]]

