[R-sig-ME] [R] lme nesting/interaction advice
Federico Calboli
f.calboli at imperial.ac.uk
Mon May 12 15:31:43 CEST 2008
On 12 May 2008, at 13:39, toby909 at gmail.com wrote:
> this is not an easy and not a standard model.
I know it is not easy, but I would be able to calculate the model by
hand, were it not for the fact that I would like to understand how to
do it using R
>
> if your 3-way anova is fully factorial, with one factor being random,
> then you have a LOT of random effects. you have a random main effect,
> you will have a number of random 2-way interction terms, and also a
> random 3-way interaction effect, their covariance matrix most
> likely to
> be nonpositive definite.
>
> The nested model is actually the simpler one, and I have the hint that
> the "basics" book does not present such a complicated model in its
> introductory chapter.
>
> also, you don't make it easy for people to help you. I could not
> easily
> read in your data and I had to generate own data. :-(
I am sorry about this, it might be because I wrote the data to a text
file with write.table() in OSX. The data was nothing more than a toy
model
>
> Maybe you are looking for something similar to:
>
> set.seed(78987)
> a = rep(1:3,each=120)
> b = rep(1:3,3, each=40)
> c = rep(1:10,9,each=4)
> y = rnorm(360,0,10)
> x = cbind(a,b,c,y)
> colnames(x) = c("a", "b", "c", "y")
> x = as.data.frame(x)
>
> lme = lme(y ~ factor(a)*factor(b)*factor(c)-1, x, ~factor(c))
> anova(lme)
With the very same model you're using I get:
> lme.mod = lme(y ~ selection * males * month-1, random = ~month,
testdat)
Error in getGroups.data.frame(dataMix, groups) :
Invalid formula for groups
> lme.mod = lme(y ~ selection * males * (month-1), random = ~month,
testdat)
Error in getGroups.data.frame(dataMix, groups) :
Invalid formula for groups
I copy/paste the datset below, in case it makes things clearer.
Thanks,
Federico
selection line males month block y
L L1 1 a 1 13.8156357121188
L L1 1 a 1 12.5678496952169
L L1 1 a 1 17.1313698710874
L L1 1 a 1 3.87016302696429
L L1 1 a 1 13.2627072110772
L L2 1 a 1 17.835768135963
L L2 1 a 1 19.3615794742946
L L2 1 a 1 1.73416316602379
L L2 1 a 1 12.9440758333076
L L2 1 a 1 2.09191741654649
S S1 1 a 1 1.56137526640669
S S1 1 a 1 17.6580698778853
S S1 1 a 1 18.1417595115490
S S1 1 a 1 15.5621050691698
S S1 1 a 1 17.0240987658035
S S2 1 a 1 12.4378062419128
S S2 1 a 1 6.63962595071644
S S2 1 a 1 16.6060689473525
S S2 1 a 1 7.1222553497646
S S2 1 a 1 18.0590278783347
L L1 2 a 1 1.24710303940810
L L1 2 a 1 4.62720696791075
L L1 2 a 1 16.0327167815994
L L1 2 a 1 6.12926463945769
L L1 2 a 1 7.65810538828373
L L2 2 a 1 7.44077128893696
L L2 2 a 1 14.9197938004509
L L2 2 a 1 13.4244954204187
L L2 2 a 1 11.5361888066400
L L2 2 a 1 2.60056478204206
S S1 2 a 1 14.8965472229756
S S1 2 a 1 18.777876078384
S S1 2 a 1 6.80722737265751
S S1 2 a 1 13.1697203880176
S S1 2 a 1 3.74557441123761
S S2 2 a 1 5.41025308240205
S S2 2 a 1 19.8277674221899
S S2 2 a 1 4.76206006342545
S S2 2 a 1 3.08200096315704
S S2 2 a 1 11.7220768791158
L L1 1 a 2 17.8684629611671
L L1 1 a 2 18.5609889889602
L L1 1 a 2 1.33335256157443
L L1 1 a 2 12.2590920312796
L L1 1 a 2 10.3133576815017
L L2 1 a 2 9.08117202203721
L L2 1 a 2 11.8387454338372
L L2 1 a 2 2.17258459446020
L L2 1 a 2 7.64467771397904
L L2 1 a 2 10.1472946784925
S S1 1 a 2 6.33078282815404
S S1 1 a 2 14.2109518861398
S S1 1 a 2 2.86901426501572
S S1 1 a 2 1.33705932833254
S S1 1 a 2 3.62769498769194
S S2 1 a 2 10.6116549053695
S S2 1 a 2 19.2579759012442
S S2 1 a 2 4.93543729488738
S S2 1 a 2 14.0185110287275
S S2 1 a 2 13.0477287801914
L L1 2 a 2 7.81632485729642
L L1 2 a 2 15.8365131700411
L L1 2 a 2 13.6505087725818
L L1 2 a 2 4.30545190884732
L L1 2 a 2 5.62008981755935
L L2 2 a 2 11.6415019945707
L L2 2 a 2 17.4424436504487
L L2 2 a 2 5.51907726703212
L L2 2 a 2 3.24006642703898
L L2 2 a 2 2.96195078082383
S S1 2 a 2 16.2962908495683
S S1 2 a 2 11.919979267288
S S1 2 a 2 2.93063819734380
S S1 2 a 2 15.6936508698855
S S1 2 a 2 2.295168728102
S S2 2 a 2 11.7390888168011
S S2 2 a 2 10.4391786744818
S S2 2 a 2 11.1727120177820
S S2 2 a 2 11.4406719871331
S S2 2 a 2 5.20650001661852
L L1 1 b 3 9.53833453846164
L L1 1 b 3 1.95979442284442
L L1 1 b 3 8.31046994985081
L L1 1 b 3 4.39192276610993
L L1 1 b 3 16.0887561799027
L L2 1 b 3 5.20481191016734
L L2 1 b 3 8.32888073613867
L L2 1 b 3 3.47083900799043
L L2 1 b 3 12.2260039008688
L L2 1 b 3 12.2011876017787
S S1 1 b 3 10.6229240614921
S S1 1 b 3 9.49411644623615
S S1 1 b 3 18.4179708964657
S S1 1 b 3 4.12228938611224
S S1 1 b 3 5.55325478035957
S S2 1 b 3 10.4130052563269
S S2 1 b 3 12.6257456133608
S S2 1 b 3 19.8305484240409
S S2 1 b 3 2.6487210446503
S S2 1 b 3 15.9869729799684
L L1 2 b 3 14.6902481422294
L L1 2 b 3 16.9090498948935
L L1 2 b 3 3.90413530776277
L L1 2 b 3 1.89122105599381
L L1 2 b 3 14.2131580882706
L L2 2 b 3 16.1121652075090
L L2 2 b 3 16.8070402105805
L L2 2 b 3 2.19568496150896
L L2 2 b 3 2.96183063089848
L L2 2 b 3 12.6824307644274
S S1 2 b 3 12.8504637307487
S S1 2 b 3 6.1809710978996
S S1 2 b 3 7.47571811126545
S S1 2 b 3 8.81466605700552
S S1 2 b 3 12.3395618333016
S S2 2 b 3 19.9728567516431
S S2 2 b 3 11.3028548071161
S S2 2 b 3 6.50141697842628
S S2 2 b 3 13.0698232366703
S S2 2 b 3 11.474319845438
L L1 1 b 4 1.03187379334122
L L1 1 b 4 9.6801089819055
L L1 1 b 4 4.00592510355636
L L1 1 b 4 4.63362230593339
L L1 1 b 4 15.4505966042634
L L2 1 b 4 14.9346919001546
L L2 1 b 4 18.3153922208585
L L2 1 b 4 8.57050257665105
L L2 1 b 4 1.31918784533627
L L2 1 b 4 19.5731912786141
S S1 1 b 4 4.34415089036338
S S1 1 b 4 9.66746214497834
S S1 1 b 4 12.4202494181227
S S1 1 b 4 17.0269973296672
S S1 1 b 4 15.1591323411558
S S2 1 b 4 7.3169305799529
S S2 1 b 4 14.9331590640359
S S2 1 b 4 13.4191052850801
S S2 1 b 4 3.8695620871149
S S2 1 b 4 14.8654785933904
L L1 2 b 4 18.5652933202218
L L1 2 b 4 1.33474090369418
L L1 2 b 4 12.9836367180105
L L1 2 b 4 8.14379613753408
L L1 2 b 4 17.5245339989197
L L2 2 b 4 19.4962712256238
L L2 2 b 4 8.36269160197116
L L2 2 b 4 16.4331527492031
L L2 2 b 4 19.9028004400898
L L2 2 b 4 8.9440936667379
S S1 2 b 4 5.1467830883339
S S1 2 b 4 13.0068403361365
S S1 2 b 4 17.9727395507507
S S1 2 b 4 7.75389035535045
S S1 2 b 4 13.1991689843126
S S2 2 b 4 1.86596546205692
S S2 2 b 4 13.6726454407908
S S2 2 b 4 5.46787238144316
S S2 2 b 4 14.9116268747021
S S2 2 b 4 17.4470446316991
L L1 1 c 5 6.0449733575806
L L1 1 c 5 9.23758197389543
L L1 1 c 5 11.8805425714236
L L1 1 c 5 11.097381018335
L L1 1 c 5 6.2186355558224
L L2 1 c 5 15.4524628254585
L L2 1 c 5 10.8791305767372
L L2 1 c 5 8.53259862400591
L L2 1 c 5 17.7329147965647
L L2 1 c 5 7.95771266217344
S S1 1 c 5 14.2891584723257
S S1 1 c 5 18.7194010075182
S S1 1 c 5 5.8396331758704
S S1 1 c 5 12.2250114120543
S S1 1 c 5 19.9965940725524
S S2 1 c 5 8.086333316518
S S2 1 c 5 1.02154314704239
S S2 1 c 5 2.71978635899723
S S2 1 c 5 11.7734509080183
S S2 1 c 5 10.7842262475751
L L1 2 c 5 15.3013315075077
L L1 2 c 5 6.12277858285233
L L1 2 c 5 6.58965252665803
L L1 2 c 5 13.0980647155084
L L1 2 c 5 11.3858233471401
L L2 2 c 5 13.8056075817440
L L2 2 c 5 11.4665438272059
L L2 2 c 5 6.37498314119875
L L2 2 c 5 3.85318743507378
L L2 2 c 5 7.959969348507
S S1 2 c 5 13.8249646106269
S S1 2 c 5 13.3112728327978
S S1 2 c 5 9.67586784437299
S S1 2 c 5 17.8595201659482
S S1 2 c 5 3.14554875413887
S S2 2 c 5 10.4300375301391
S S2 2 c 5 15.4386686717626
S S2 2 c 5 7.93477151589468
S S2 2 c 5 3.66100515658036
S S2 2 c 5 13.5765222932678
L L1 1 c 6 11.3484169594012
L L1 1 c 6 12.7286028855015
L L1 1 c 6 17.2616694702301
L L1 1 c 6 19.8529832861386
L L1 1 c 6 13.6375724875834
L L2 1 c 6 1.47241126280278
L L2 1 c 6 1.95706973574124
L L2 1 c 6 5.88739864598028
L L2 1 c 6 8.16921139019541
L L2 1 c 6 15.4799758975860
S S1 1 c 6 2.47244948730804
S S1 1 c 6 4.87303283042274
S S1 1 c 6 6.15663269115612
S S1 1 c 6 1.31718108500354
S S1 1 c 6 16.4325702653732
S S2 1 c 6 8.77171974466182
S S2 1 c 6 13.4219867731445
S S2 1 c 6 15.79551491444
S S2 1 c 6 8.52955200499855
S S2 1 c 6 14.4046092615463
L L1 2 c 6 17.4255252447911
L L1 2 c 6 5.80786765902303
L L1 2 c 6 3.27889802469872
L L1 2 c 6 7.55257236934267
L L1 2 c 6 10.3537469459698
L L2 2 c 6 10.1472219382413
L L2 2 c 6 15.3184245729353
L L2 2 c 6 12.6165662519634
L L2 2 c 6 11.2075877587777
L L2 2 c 6 17.0927850408480
S S1 2 c 6 19.5778706537094
S S1 2 c 6 5.56091665173881
S S1 2 c 6 6.32830694783479
S S1 2 c 6 7.46368952002376
S S1 2 c 6 14.5648785342928
S S2 2 c 6 14.7789344959892
S S2 2 c 6 3.21725518512540
S S2 2 c 6 2.26359746395610
S S2 2 c 6 9.14707987429574
S S2 2 c 6 8.6291270784568
--
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St. Mary's Campus
Norfolk Place, London W2 1PG
Tel +44 (0)20 75941602 Fax +44 (0)20 75943193
f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com
More information about the R-sig-mixed-models
mailing list