[R-sig-ME] Hierarchical modelling using lmer v lme and including weights

Tom Wilding Tom.Wilding at sams.ac.uk
Tue Sep 13 00:10:55 CEST 2011


Dear Mailing List
 
Earlier last week I posted a question on R-help 'Power analysis in hierarchical models' requesting guidance on power analysis, using a simulation approach.  Many thanks to Thierry Onkelinx for his useful suggestions which included submitting such requests to this, more appropriate, forum.  
 
I am stepping backward now in attempting to best model the pilot data that I have.  These data (243 x 4) are appended below this email and I apologise in advance if this is an inappropriate method of getting data out.  To get the data into R copy them to the clipboard prior to running the attached script.  My questions are in the script behind #

I'd be glad to receive any sources of information* on the subject of analysis of hierarchical models (i.e. book recommendations) or websites.  

Many thanks for your help (and patience). 

Tom. 
* Crawley, The R Book, Page 649 demonstrates recoding factor levels prior to constructing the lmer model (for nested rat liver data, cross ref:  Sokal and Rohlf, Biometry (3rd ed), page 291).  Anyone know why it is necessary to recode, the factors as per Crawley ?  Using the model Glycogen~Treatment+(1|rat)+(1|liver) (as per Crawley) seems to indicate that there are six rats whilst using the 'alternative' Glycogen~Treatment+(1|Rat/Liver) seems to indicate (correctly) that there are two rats.  

============================================================

library(psych);  library(lme4);  library(nlme)
 
data4=read.clipboard(sep='\t')
data4$Treat=factor(data4$Treat)#  Treat is a factor
str(data4)  #LogG =response,Treat=fixed effect, Tank and Pot=random. Several measurements of LogG were made in each pot, there were several pots in each Tank.  

with (data4, tapply(LogG,list(Tank,Treat),mean));# show some data structure
with (data4, tapply(LogG,list(Pot,Treat),mean));# as above.

# I AM INTERESTED IN THE RESPONSE (LOGG) TO DIFFERENT LEVELS OF TREAT. 
# THE TANKS REPRESENT THE TRUE REPLICATES IN THIS EXPERIMENTS 
 
#IMPLEMENT RANDOM EFFECTS MODEL
model_1.1=lmer(LogG~Treat+(1|Tank/Pot),weights=vf1,data=data4);  summary(model_1.1)
#OR
model_1=lmer(LogG~Treat+(1|Tank)+(1|Pot), data=data4);summary(model_1)
# Q 0.1 - WHAT IS THE DIFFERENCE BETWEEN (1|Tank/Pot) AND (1|Tank)+(1|Pot) IN THE ABOVE MODELS?

#Q1 - CAN I GET P VALUES? (Treat0.1 - looks 'significant' (P<0.05) but only just

#check residuals: 
Res1=residuals(model_1,type=n);  plot(Res1~Treat,data=data4)

#model_1 shows difference variances for different levels of Treat, try varIdent
vf1=varIdent(form=~1|Treat)
model_2=lmer(LogG~Treat+(1|Tank)+(1|Pot), weights=vf1, data=data4);summary(model_2)#OR
model_2=lmer(LogG~Treat+(1|Tank/Pot), weights=vf1, data=data4);summary(model_2)
# Q2 - model_2 fails, why the error message - '...variable lengths differ'?
 
#Different approach 
#USE lme 
model_3=lme(LogG~Treat,random=~1|Tank+1|Pot,weights=vf1,data=data4); summary(model_3)
#Q3 - Model_3 'runs' but get error message '....+ not meaningful for factors'. Why?


#respecify random component - looks more encouraging:
model_3=lme(LogG~Treat,random=~1|Tank/Pot,weights=vf1,data=data4);  summary(model_3)
#Q3.1 - Should I assume from these results that the variances components indicate that most of the variance is occurring at the residual level 
# i.e. the level of individual measurements within each pot and that, therefore, I could usefully additionally replicate these measurements?


#Q3.2 can I get appropriate degrees of freedom with the parameter estimates (for fixed effects)?  This would reassure that correct analysis is being conducted?



====================
RAW DATA (copy the headers)

Tank	Treat	Pot	LogG
Tank 1	0.1	A	3.258096538
Tank 1	0.1	A	3.044522438
Tank 1	0.1	A	4.262679877
Tank 1	0.1	A	3.33220451
Tank 1	0.1	A	1.791759469
Tank 1	0.1	A	1.386294361
Tank 1	0.1	B	4.430816799
Tank 1	0.1	B	4.890349128
Tank 1	0.1	B	4.584967479
Tank 1	0.1	B	5.225746674
Tank 1	0.1	B	3.871201011
Tank 1	0.1	B	2.302585093
Tank 1	0.1	B	1.945910149
Tank 1	0.1	C	3.044522438
Tank 1	0.1	C	5.398162702
Tank 1	0.1	C	0
Tank 1	0.1	C	2.890371758
Tank 1	0.1	C	3.761200116
Tank 1	0.1	C	3.713572067
Tank 1	0.1	C	4.406719247
Tank 1	0.1	D	4.143134726
Tank 1	0.1	D	4.709530201
Tank 1	0.1	D	2.564949357
Tank 1	0.1	D	3.871201011
Tank 1	0.1	D	4.672828834
Tank 1	0.1	D	4.48863637
Tank 1	0.1	D	4.094344562
Tank 2	0.02	A	3.33220451
Tank 2	0.02	A	2.708050201
Tank 2	0.02	A	3.17805383
Tank 2	0.02	A	3.401197382
Tank 2	0.02	A	2.564949357
Tank 2	0.02	A	1.386294361
Tank 2	0.02	A	4.48863637
Tank 2	0.02	B	4.025351691
Tank 2	0.02	B	4.369447852
Tank 2	0.02	B	2.63905733
Tank 2	0.02	B	3.433987204
Tank 2	0.02	B	3.401197382
Tank 2	0.02	B	3.33220451
Tank 2	0.02	C	1.609437912
Tank 2	0.02	C	2.890371758
Tank 2	0.02	C	3.17805383
Tank 2	0.02	C	4.143134726
Tank 2	0.02	C	3.044522438
Tank 2	0.02	C	3.135494216
Tank 2	0.02	C	2.63905733
Tank 2	0.02	D	2.197224577
Tank 2	0.02	D	2.397895273
Tank 2	0.02	D	2.995732274
Tank 2	0.02	D	3.828641396
Tank 2	0.02	E	1.386294361
Tank 2	0.02	E	2.995732274
Tank 2	0.02	E	3.258096538
Tank 2	0.02	E	3.17805383
Tank 2	0.02	E	4.262679877
Tank 2	0.02	E	3.610917913
Tank 2	0.02	E	2.890371758
Tank 2	0.02	E	3.465735903
Tank 2	0.02	F	3.044522438
Tank 2	0.02	F	5.298317367
Tank 2	0.02	F	2.890371758
Tank 2	0.02	F	3.850147602
Tank 2	0.02	F	3.091042453
Tank 2	0.02	F	3.761200116
Tank 2	0.02	F	4.204692619
Tank 3	0.1	A	3.80666249
Tank 3	0.1	A	3.465735903
Tank 3	0.1	A	4.276666119
Tank 3	0.1	A	2.708050201
Tank 3	0.1	A	5.587248658
Tank 3	0.1	A	2.48490665
Tank 3	0.1	A	4.276666119
Tank 3	0.1	B	2.890371758
Tank 3	0.1	B	2.564949357
Tank 3	0.1	B	3.135494216
Tank 3	0.1	B	2.197224577
Tank 3	0.1	C	5.837730447
Tank 3	0.1	C	1.609437912
Tank 3	0.1	C	4.96284463
Tank 3	0.1	C	5.384495063
Tank 3	0.1	C	4.317488114
Tank 3	0.1	D	4.317488114
Tank 3	0.1	D	3.988984047
Tank 3	0.1	D	2.48490665
Tank 3	0.1	D	4.663439094
Tank 3	0.1	D	2.48490665
Tank 3	0.1	D	4.304065093
Tank 3	0.1	D	1.609437912
Tank 4	0	A	2.63905733
Tank 4	0	A	1.791759469
Tank 4	0	A	3.044522438
Tank 4	0	A	3.33220451
Tank 4	0	A	2.833213344
Tank 4	0	A	0
Tank 4	0	A	2.890371758
Tank 4	0	A	3.496507561
Tank 4	0	B	3.433987204
Tank 4	0	B	3.044522438
Tank 4	0	B	3.135494216
Tank 4	0	B	2.63905733
Tank 4	0	B	2.772588722
Tank 4	0	B	3.610917913
Tank 4	0	C	3.713572067
Tank 4	0	C	2.197224577
Tank 4	0	C	4.394449155
Tank 4	0	C	3.433987204
Tank 4	0	C	3.17805383
Tank 4	0	C	2.564949357
Tank 4	0	C	2.995732274
Tank 4	0	C	2.302585093
Tank 4	0	D	3.688879454
Tank 4	0	D	3.737669618
Tank 4	0	D	2.833213344
Tank 4	0	D	2.564949357
Tank 4	0	D	3.044522438
Tank 4	0	D	3.401197382
Tank 4	0	D	3.401197382
Tank 5	0.02	A	4.382026635
Tank 5	0.02	A	4.025351691
Tank 5	0.02	A	4.262679877
Tank 5	0.02	A	4.043051268
Tank 5	0.02	A	3.465735903
Tank 5	0.02	A	3.044522438
Tank 5	0.02	A	3.17805383
Tank 5	0.02	B	3.091042453
Tank 5	0.02	B	4.709530201
Tank 5	0.02	B	4.127134385
Tank 5	0.02	B	3.970291914
Tank 5	0.02	B	3.80666249
Tank 5	0.02	B	2.197224577
Tank 5	0.02	B	2.48490665
Tank 5	0.02	C	2.944438979
Tank 5	0.02	C	2.302585093
Tank 5	0.02	C	3.555348061
Tank 5	0.02	C	3.33220451
Tank 5	0.02	C	3.465735903
Tank 5	0.02	C	2.63905733
Tank 5	0.02	C	3.555348061
Tank 5	0.02	D	2.708050201
Tank 5	0.02	D	3.218875825
Tank 5	0.02	D	3.33220451
Tank 5	0.02	D	3.044522438
Tank 5	0.02	D	3.496507561
Tank 5	0.02	D	1.609437912
Tank 5	0.02	D	3.33220451
Tank 5	0.02	E	3.610917913
Tank 5	0.02	E	2.772588722
Tank 5	0.02	E	2.772588722
Tank 5	0.02	E	3.465735903
Tank 5	0.02	E	2.63905733
Tank 5	0.02	E	3.17805383
Tank 5	0.02	F	3.465735903
Tank 5	0.02	F	1.945910149
Tank 5	0.02	F	3.737669618
Tank 5	0.02	F	2.995732274
Tank 5	0.02	F	3.951243719
Tank 5	0.02	F	2.772588722
Tank 5	0.02	F	1.098612289
Tank 6	0.1	A	4.521788577
Tank 6	0.1	A	1.609437912
Tank 6	0.1	A	4.418840608
Tank 6	0.1	A	3.218875825
Tank 6	0.1	A	3.218875825
Tank 6	0.1	A	4.787491743
Tank 6	0.1	B	1.791759469
Tank 6	0.1	B	4.718498871
Tank 6	0.1	B	4.248495242
Tank 6	0.1	B	2.63905733
Tank 6	0.1	B	3.36729583
Tank 6	0.1	B	5.030437921
Tank 6	0.1	B	2.302585093
Tank 6	0.1	C	4.9698133
Tank 6	0.1	C	2.772588722
Tank 6	0.1	C	3.688879454
Tank 6	0.1	C	4.382026635
Tank 6	0.1	C	2.564949357
Tank 6	0.1	C	3.465735903
Tank 6	0.1	C	4.304065093
Tank 6	0.1	C	4.584967479
Tank 6	0.1	D	2.944438979
Tank 6	0.1	D	3.871201011
Tank 6	0.1	D	4.290459441
Tank 6	0.1	D	4.454347296
Tank 6	0.1	D	5.451038454
Tank 6	0.1	D	3.583518938
Tank 7	0	A	4.110873864
Tank 7	0	A	3.871201011
Tank 7	0	A	3.555348061
Tank 7	0	A	3.688879454
Tank 7	0	A	3.988984047
Tank 7	0	A	4.189654742
Tank 7	0	A	5.087596335
Tank 7	0	A	3.091042453
Tank 7	0	B	3.871201011
Tank 7	0	B	3.610917913
Tank 7	0	B	2.890371758
Tank 7	0	B	2.772588722
Tank 7	0	B	3.091042453
Tank 7	0	B	4.219507705
Tank 7	0	B	4.262679877
Tank 7	0	B	3.871201011
Tank 7	0	C	3.583518938
Tank 7	0	C	2.995732274
Tank 7	0	C	1.386294361
Tank 7	0	C	2.944438979
Tank 7	0	C	2.995732274
Tank 7	0	C	3.761200116
Tank 7	0	C	3.610917913
Tank 7	0	C	3.850147602
Tank 7	0	D	3.17805383
Tank 7	0	D	4.025351691
Tank 7	0	D	3.970291914
Tank 7	0	D	3.555348061
Tank 7	0	D	3.663561646
Tank 7	0	D	4.343805422
Tank 7	0	D	4.219507705
Tank 7	0	D	3.33220451
Tank 8	0	A	2.079441542
Tank 8	0	A	3.63758616
Tank 8	0	A	4.59511985
Tank 8	0	A	4.234106505
Tank 8	0	B	2.995732274
Tank 8	0	B	3.258096538
Tank 8	0	B	3.091042453
Tank 8	0	B	1.609437912
Tank 8	0	B	2.197224577
Tank 8	0	B	4.17438727
Tank 8	0	B	3.583518938
Tank 8	0	B	4.532599493
Tank 8	0	C	3.555348061
Tank 8	0	C	2.890371758
Tank 8	0	C	2.48490665
Tank 8	0	C	3.135494216
Tank 8	0	C	3.688879454
Tank 8	0	C	2.890371758
Tank 8	0	C	3.258096538
Tank 8	0	D	3.258096538
Tank 8	0	D	3.17805383
Tank 8	0	D	2.079441542
Tank 8	0	D	2.63905733
Tank 8	0	D	3.401197382
Tank 8	0	E	3.17805383




-------------------------------------------------------------------------
Tom Wilding, MSc, PhD, Dip. Stat.
Scottish Association for Marine Science,
Scottish Marine Institute,
OBAN
Argyll.  PA37 1QA
United Kingdom.
Phone (+44) (0) 1631 559214
Fax (+44) (0) 1631 559001
------------------------------------------------------------------------
+++++++++++++++++++++++++++++++
The Scottish Association for Marine Science (SAMS) is registered in Scotland as a Company Limited by Guarantee (SC009292) and is a registered charity (9206).  SAMS has an actively trading wholly owned subsidiary company: SAMS Research Services Ltd a Limited Company (SC224404). All Companies in the group are registered in Scotland and share a registered office at Scottish Marine Institute, Oban Argyll PA37 1QA.

The content of this message may contain personal views which are not the views of SAMS unless specifically stated.

Please note that all email traffic is monitored for purposes of security and spam filtering. As such individual emails may be examined in more detail.
+++++++++++++++++++++++++++++++




More information about the R-sig-mixed-models mailing list