EDIT:
I am currently writing my master thesis on the effect of a certain insecticide on bumble bee colonies. I was for example checking if damaged/diseased appearing bees were more prevalent in colonies that were exposed to the insecticide compared to the control.
The study design is hierarchical. 16 fields were paired according to landscape characteristics. In each pair one field was randomly assigned to be treated with the insecticide, while the other is the control field. In each field there are 2 boxes and in each box are 2 bumble bee hives. From each hive I have up to ten pupae per sex.
This is how my data looks like:
structure(list(pair = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L
), .Label = c("P01", "P02", "P03", "P04", "P05", "P10", "P11",
"P12"), class = "factor"), field = structure(c(6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L), .Label = c("VR02", "VR03",
"VR04", "VR05", "VR06", "VR07", "VR09", "VR12", "VR13", "VR14",
"VR16", "VR17", "VR18", "VR20", "VR21", "VR23"), class = "factor"),
treatment = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2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L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L), .Label = c("Clothianidin", "Control"), class = "factor"),
box.nested = c(11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 23, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24,
24, 24, 24, 24, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3,
3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 19, 19, 19, 19, 19, 19,
19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
26, 26, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14,
31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 15, 15, 15, 15, 15, 16, 16, 16, 18, 18, 18,
18, 18, 18, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18,
5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 21, 21, 21, 21, 21, 21, 21,
21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
10, 10, 10, 10, 10, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28,
28, 28, 28, 28, 28, 28, 28, 28, 30, 30, 30, 30, 29, 29, 29,
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30), hive.nested = c(21L,
21L, 21L, 21L, 21L, 22L, 22L, 22L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 45L, 45L,
45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 46L, 46L, 48L,
48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 3L, 3L, 4L, 4L, 4L, 6L, 6L, 6L, 6L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 37L, 37L, 37L, 37L, 38L, 38L, 38L,
38L, 38L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L,
49L, 49L, 49L, 50L, 50L, 51L, 52L, 25L, 25L, 25L, 26L, 26L,
26L, 27L, 27L, 27L, 27L, 28L, 28L, 28L, 61L, 61L, 61L, 61L,
61L, 62L, 62L, 62L, 62L, 64L, 64L, 64L, 64L, 64L, 64L, 64L,
64L, 64L, 64L, 30L, 30L, 30L, 30L, 30L, 32L, 32L, 32L, 36L,
36L, 36L, 36L, 36L, 36L, 34L, 34L, 34L, 34L, 34L, 34L, 34L,
34L, 35L, 35L, 35L, 36L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 41L, 41L,
41L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 43L, 43L,
43L, 43L, 43L, 43L, 44L, 44L, 44L, 44L, 44L, 13L, 14L, 14L,
14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 16L, 16L, 16L, 16L, 16L, 16L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 19L, 20L, 20L, 20L, 20L, 17L, 17L, 17L, 17L,
17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 19L,
19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 53L, 53L, 53L, 53L,
54L, 54L, 54L, 54L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 56L,
56L, 56L, 60L, 60L, 60L, 60L, 57L, 57L, 57L, 57L, 57L, 57L,
57L, 58L, 58L, 58L, 58L, 58L, 58L, 59L, 59L, 59L, 59L, 59L,
59L, 59L, 59L, 60L, 60L, 60L, 60L, 60L, 60L), stage = structure(c(2L,
1L, 1L, 3L, 1L, 1L, 1L, 1L, 2L, 3L, 2L, 2L, 3L, 2L, 2L, 2L,
1L, 3L, 1L, 2L, 3L, 2L, 1L, 3L, 2L, 2L, 1L, 2L, 3L, 2L, 1L,
3L, 2L, 3L, 1L, 1L, 2L, 3L, 1L, 3L, 3L, 3L, 1L, 3L, 2L, 2L,
2L, 2L, 3L, 3L, 2L, 2L, 2L, 3L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 2L, 2L, 3L, 3L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 2L,
3L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L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, 1, 1, 1, 1, 1, 1, 1, 0,
1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0,
0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1,
1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0)), .Names = c("pair",
"field", "treatment", "box.nested", "hive.nested", "stage", "condition",
"sex", "diseased"), class = "data.frame", row.names = c(5L, 7L,
8L, 9L, 10L, 14L, 15L, 16L, 21L, 23L, 24L, 26L, 28L, 29L, 30L,
31L, 32L, 33L, 34L, 37L, 38L, 39L, 40L, 42L, 45L, 47L, 48L, 49L,
50L, 51L, 52L, 53L, 54L, 55L, 58L, 60L, 66L, 67L, 68L, 72L, 73L,
74L, 77L, 83L, 85L, 87L, 90L, 92L, 95L, 97L, 100L, 104L, 108L,
115L, 117L, 123L, 125L, 133L, 134L, 137L, 144L, 155L, 156L, 157L,
158L, 159L, 160L, 161L, 162L, 163L, 164L, 166L, 169L, 170L, 172L,
175L, 178L, 179L, 180L, 184L, 185L, 189L, 190L, 191L, 192L, 193L,
194L, 195L, 196L, 197L, 199L, 201L, 202L, 203L, 205L, 206L, 207L,
211L, 212L, 213L, 215L, 217L, 221L, 222L, 224L, 226L, 230L, 244L,
247L, 255L, 258L, 262L, 271L, 272L, 274L, 280L, 281L, 284L, 285L,
288L, 289L, 295L, 296L, 297L, 299L, 300L, 305L, 308L, 309L, 312L,
314L, 326L, 327L, 328L, 329L, 330L, 331L, 332L, 333L, 334L, 335L,
356L, 359L, 362L, 364L, 366L, 375L, 378L, 381L, 388L, 389L, 390L,
391L, 392L, 393L, 404L, 405L, 406L, 407L, 408L, 409L, 410L, 412L,
417L, 418L, 420L, 424L, 425L, 426L, 427L, 428L, 429L, 430L, 431L,
432L, 433L, 435L, 436L, 438L, 439L, 440L, 441L, 442L, 443L, 444L,
446L, 447L, 450L, 453L, 454L, 455L, 456L, 458L, 459L, 461L, 462L,
465L, 466L, 468L, 475L, 476L, 477L, 478L, 479L, 480L, 481L, 482L,
483L, 484L, 485L, 486L, 487L, 490L, 491L, 494L, 495L, 496L, 500L,
501L, 508L, 518L, 519L, 521L, 522L, 524L, 525L, 526L, 527L, 528L,
529L, 530L, 531L, 532L, 533L, 534L, 535L, 538L, 540L, 542L, 543L,
544L, 548L, 549L, 551L, 552L, 553L, 554L, 555L, 556L, 557L, 559L,
560L, 563L, 568L, 569L, 571L, 572L, 576L, 577L, 578L, 579L, 580L,
581L, 582L, 583L, 584L, 585L, 587L, 588L, 590L, 594L, 595L, 596L,
600L, 603L, 604L, 605L, 606L, 607L, 608L, 609L, 616L, 618L, 620L,
622L, 626L, 628L, 631L, 632L, 635L, 636L, 638L, 639L, 641L, 646L,
647L, 651L, 652L, 653L, 654L, 655L, 656L, 658L, 659L, 660L, 661L,
663L, 666L, 667L, 668L, 669L, 670L, 673L, 675L, 676L, 678L, 679L,
680L, 681L, 682L, 684L, 685L, 686L, 687L, 688L, 689L, 690L))
I have run binomial glmer models from the lme4 package to test whether the presence of disease/damage signs in bumble bee colonies is affected by the insecticide.
damage.prev <- glmer(diseased ~ treatment + sex + stage
+ (1|pair/field/box.nested/hive.nested)
,data=df.cocoons.white,
family=binomial)
I have been trying to get estimates and confidence intervals. Thanks to #Benjamin
I got a little closer to the solution, but the estimates sill seem too high.
That's how I tried to get a data.frame of CIs and estimates:
fixed <- fixef(damage.prev)
wald <-confint(damage.prev,method="Wald")
estCloth.damage.ratio <- exp(fixed[1])
estCont.damage.ratio <- exp(fixed[1] + fixed[2])
lwrCloth.damage.ratio <- exp(wald[1,1])
lwrCont.damage.ratio <- exp(wald[1,1] + wald[2,1])
uprCloth.damage.ratio <- exp(wald[1,2])
uprCont.damage.ratio <- exp(wald[1,2] + wald[2,2])
estCloth.damage <- estCloth.damage.ratio/ (1+estCloth.damage.ratio)
estCont.damage <- estCont.damage.ratio / (1+ estCont.damage.ratio)
lwrCloth.damage <- lwrCloth.damage.ratio/ (1+ lwrCloth.damage.ratio)
lwrCont.damage <- lwrCont.damage.ratio /(1+ lwrCont.damage.ratio)
uprCloth.damage <- uprCloth.damage.ratio /(1+uprCloth.damage.ratio)
uprCont.damage <- uprCont.damage.ratio /(1+uprCont.damage.ratio )
treat.damage <- data.frame(Treatment,Estimate,lwr,upr)
What still confuses me are the high estimates of beyond 94%, yet
sum(df.cocoons.white$diseased)/length(df.cocoons.white$diseased)
gives me less than 70%. Doesn't seem realistic. Any idea what might be wrong?
Your model is using a logit transformation.
The way I look at generalized linear models is that they really aren't any different than simple linear regression. In simple linear regression, your response variable is continuous on (theoretically) the entire real number line (-Inf, Inf).
In logistic regression, your response is a proportion, which is continuous on the interval [0, 1]. The odds calculates (p / (1-p)) which is continuous over the interval of [0, inf). The log odds log(p / (1-p)) is continuous over the interval (-Inf, Inf).
This complete transformation (log(p / (1-p))) is referred to as the logit transformation and is pretty standard in logistic regression.
The results of your glmer model, which is a random effects version of logistic regression, uses the same transformation and so the estimated coefficients are on the scale of (-Inf, Inf). If you want odds ratios, you can exponentiate the coefficients, which will give you the odds measured on a scale of (0, Inf), with 1.0 being the null value.
Related
I am trying to use the effects package to create plots of effects in a linear mixed model. I specify the model
fit1 <- lmer(Values ~ stimuli + timeperiod + scale(poly(distance.code,3,raw=FALSE))*habitat + wind.speed + (1|location.code), data=ex.df, REML=FALSE)
For this model I can generate results for analysis as I expect using summary or anova but when I try to look at specific effects:
allEffects(fit1)
#or
plot(allEffects(fit1))
#or
emmeans(fit1, pairwise ~ stimuli)
An error is returned:
Error in poly(distance.code, 3, raw = FALSE) :
'degree' must be less than number of unique points
(with the plot function the error is different but is probably arising from the error with allEffects)
I understand, based on the responses to this question and this question, that "numerical overflow" can be an issue with poly terms. However, I am not clear on what this means or how to overcome the issue.
I also saw in this post and in another post about lme4 that I can no longer find, that I might need to update packages so I have updated 'effects' and 'lme4' in an attempt to remedy this but to no avail.
So if this error is happening because of "numerical overflow" how can I remedy the problem? or if it is not numerical overflow what is happening and how can I work around this?
a subset of my data using dput is:
structure(list(location.code = structure(c(1L, 1L, 1L, 1L, 2L,
2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 4L, 4L,
4L, 4L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 3L,
3L, 3L, 3L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
4L, 4L, 4L, 4L, 3L, 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 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("before",
"during", "after"), class = "factor"), timeperiod = c(6L, 6L,
6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L), distance.code = c(0L, 30L, 60L,
120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L,
60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L,
30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L,
0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L,
60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L,
30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L,
0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L,
120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 60L, 120L, 0L, 30L,
60L, 120L, 0L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L,
30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L,
60L, 120L, 0L, 30L, 60L, 120L, 0L, 60L, 120L, 0L, 30L, 60L, 120L,
0L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L,
120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L,
0L, 30L, 60L, 120L, 0L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 60L,
120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L,
30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L,
60L, 120L, 0L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 60L, 120L,
0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L,
60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L,
120L, 0L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 60L, 120L, 0L, 30L,
60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L,
0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 120L, 0L,
60L, 120L, 0L, 30L, 60L, 120L, 0L, 60L, 120L, 0L, 30L, 60L),
Values = c(910.721895276374, 922.652711611841, 926.219785713456,
918.776924477918, 1030.28919690464, 1121.98321368732, 992.741416151102,
910.878353926705, 920.201901019659, 922.134996121665, 917.610324052986,
992.059286431433, 1042.05240231832, 1018.99804250179, 911.976009884021,
918.215389274037, 931.037495260958, 913.49701806948, 981.032280455129,
983.700699744073, 989.716307418049, 911.476759038955, 918.554393750162,
920.391856289719, 911.795802370903, 994.583211567691, 1006.58290843226,
1005.52479816571, 908.665064025178, 917.940176257067, 922.746174825048,
921.752449434568, 986.419049170517, 1042.41789735969, 1082.89658057517,
916.02310296116, 918.254868924698, 931.01648294424, 924.221021573334,
982.154409713674, 1008.54477137219, 996.577798511801, 912.914857937818,
916.937508116615, 920.933077377339, 917.443294381608, 997.669828575817,
1007.44452218386, 1151.25894192961, 909.463528658898, 915.293665875472,
921.917039784441, 912.073280663674, 983.866984633392, 1002.04551764872,
986.791628665069, 907.695668282537, 917.845214744473, 932.330755620455,
917.500330773026, 972.609449456089, 1155.55960936774, 1083.40557091613,
909.903267624225, 914.846316952797, 921.279328283221, 914.498616645498,
1000.3672969178, 1021.78461788922, 1011.40975353271, 915.037273600535,
914.099859036178, 924.116937361394, 913.523739017819, 994.428182266452,
1123.09745015276, 1004.1485272116, 914.431649376896, 915.27037594587,
929.411251949862, 910.549315840806, 974.273124973661, 1145.99211507205,
1013.58184367388, 913.467056616881, 920.213007520924, 919.794369158301,
912.333012054637, 983.816025282468, 1103.11322201674, 974.792027063404,
910.532609655114, 917.616832229923, 923.462599912213, 913.432298686233,
1015.24811721269, 1070.61183211249, 1016.57332551186, 910.196695694198,
923.403802532832, 905.400995326023, 934.612035397761, 1036.98011238981,
963.147077473505, 953.792949959199, 916.899569521736, 931.240844862156,
919.11781354823, 938.028220926723, 995.408916523572, 960.825305234446,
993.019295484939, 1026.22960551445, 1000.13773127026, 962.347584090332,
1074.31979099791, 904.090295814044, 908.836747102913, 928.867625382891,
918.100799763641, 906.282906701285, 913.146312873635, 921.224088728859,
977.094140033575, 972.599778534534, 964.658406857446, 1197.35130424458,
921.91272768213, 910.507770576621, 942.269786765654, 922.718235872787,
1014.34022271036, 1128.29327664605, 1043.1365958913, 1238.18704569961,
919.185972424773, 925.486310755197, 908.769520270226, 919.644447501213,
1030.20866627018, 956.104935565803, 955.159231718685, 922.01947330213,
934.451182538208, 928.626906337293, 941.089746683706, 986.326936258622,
1003.40797963907, 1007.57786522109, 1021.91264348048, 995.68658929192,
993.102343807935, 1114.80420865448, 901.633626404701, 908.255562868123,
922.840049924103, 917.012733437446, 907.541530752433, 915.050696506642,
925.95358291661, 983.542956895186, 972.236377246083, 965.082329354352,
1205.36753472358, 918.337944633569, 910.137012141557, 952.89462134025,
923.334999242316, 977.420371016686, 1154.17994731565, 1022.82998099991,
1186.66254220951, 927.061613377597, 926.745527716988, 908.284054932259,
921.213190559531, 966.157586219165, 974.986841619676, 959.421220417498,
916.559494755925, 935.817296050643, 918.835719171662, 912.457217113586,
1023.62078549133, 1009.23121097376, 978.938675917385, 1005.81651905991,
981.715747809821, 953.127134375762, 1088.16577366048, 902.809201411559,
907.462229880533, 921.595454423298, 919.198277947855, 904.969515265664,
913.438353334218, 918.91715550342, 974.889830301362, 970.58615968713,
963.029605541189, 1182.94093491074, 915.889893279581, 908.147726780027,
942.742415528349, 928.20319656241, 979.939535179807, 1153.51966568673,
1020.93502990084, 1154.799618481, 916.246150801212, 936.016759720656,
914.4488779132, 918.823772018551, 962.397352323664, 986.957848140285,
972.131488585193, 985.364195731404, 932.548910038465, 917.363220594089,
919.124801182577, 1085.89850605988, 1031.66330597084, 974.763804119707,
1005.64983154588, 991.988118229379, 975.384741587994, 1064.14809010237,
902.60240793926, 907.989086075871, 923.287310593779, 912.878571722023,
904.107623756648, 905.563259817979, 917.423553921906, 991.530368160932,
975.190212414434, 965.951810135591, 1192.3330908297, 915.334621878897,
910.857441830446, 936.093336975328, 932.960789822422, 972.074491630181,
1106.77459226532, 993.45400883741, 1138.94109332484, 951.911391767329,
927.688604859773, 915.194279622847, 920.98264624041, 971.414103170297,
956.138106650696, 969.385400747507, 965.458656222347, 944.097918792458,
947.157460200658, 915.929397317864, 1029.14870726558, 992.151638322899,
964.680220137879, 954.129642526236, 981.48182339388, 968.10870393618,
1097.48462256339, 906.941701681267, 917.956716926981, 923.05649603805,
934.459432014683, 922.801034508827, 920.724850575215, 935.811146196027,
981.478432929603, 1012.67364507927, 966.471299899978, 1192.4066704659,
912.640460101352, 906.34455384334, 923.738349342148, 916.883929696437,
970.987788560016, 1210.42940542072, 975.753397539076, 1138.97675920151,
911.747488522664, 928.34872697947, 910.852487444859, 916.227875349016,
982.304620375747, 1028.52794775628, 999.236663664046, 913.408967803895,
934.334726415048, 916.354017093653, 918.660674732388, 1036.08727658415,
974.408618327141, 1006.21629092128, 1004.71633485176, 995.142763465394,
987.00017276687), wind.speed = c(0.8, 0.8, 0.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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0.9,
0.9, 0.9, 65, 65, 65, 65, 65, 65, 65, 55, 55, 55, 55, 50,
50, 50, 0, 0, 0)), row.names = c(85L, 86L, 87L, 88L, 89L,
90L, 91L, 99L, 100L, 101L, 102L, 103L, 104L, 105L, 113L, 114L,
115L, 116L, 117L, 118L, 119L, 127L, 128L, 129L, 130L, 131L, 132L,
133L, 141L, 142L, 143L, 144L, 145L, 146L, 147L, 155L, 156L, 157L,
158L, 159L, 160L, 161L, 169L, 170L, 171L, 172L, 173L, 174L, 175L,
183L, 184L, 185L, 186L, 187L, 188L, 189L, 197L, 198L, 199L, 200L,
201L, 202L, 203L, 211L, 212L, 213L, 214L, 215L, 216L, 217L, 225L,
226L, 227L, 228L, 229L, 230L, 231L, 239L, 240L, 241L, 242L, 243L,
244L, 245L, 253L, 254L, 255L, 256L, 257L, 258L, 259L, 267L, 268L,
269L, 270L, 271L, 272L, 273L, 615L, 616L, 617L, 618L, 619L, 620L,
621L, 622L, 623L, 624L, 625L, 626L, 627L, 628L, 629L, 630L, 631L,
632L, 640L, 641L, 642L, 643L, 644L, 645L, 646L, 647L, 648L, 649L,
650L, 651L, 652L, 653L, 654L, 655L, 656L, 657L, 658L, 659L, 660L,
661L, 662L, 663L, 664L, 665L, 666L, 667L, 668L, 669L, 670L, 671L,
672L, 673L, 674L, 675L, 676L, 684L, 685L, 686L, 687L, 688L, 689L,
690L, 691L, 692L, 693L, 694L, 695L, 696L, 697L, 698L, 699L, 700L,
701L, 702L, 703L, 704L, 705L, 706L, 707L, 708L, 709L, 710L, 711L,
712L, 713L, 714L, 715L, 716L, 717L, 718L, 719L, 720L, 728L, 729L,
730L, 731L, 732L, 733L, 734L, 735L, 736L, 737L, 738L, 739L, 740L,
741L, 742L, 743L, 744L, 745L, 746L, 747L, 748L, 749L, 750L, 751L,
752L, 753L, 754L, 755L, 756L, 757L, 758L, 759L, 760L, 761L, 762L,
763L, 764L, 772L, 773L, 774L, 775L, 776L, 777L, 778L, 779L, 780L,
781L, 782L, 783L, 784L, 785L, 786L, 787L, 788L, 789L, 790L, 791L,
792L, 793L, 794L, 795L, 796L, 797L, 798L, 799L, 800L, 801L, 802L,
803L, 804L, 805L, 806L, 807L, 808L, 816L, 817L, 818L, 819L, 820L,
821L, 822L, 823L, 824L, 825L, 826L, 827L, 828L, 829L, 830L, 831L,
832L, 833L, 834L, 835L, 836L, 837L, 838L, 839L, 840L, 841L, 842L,
843L, 844L, 845L, 846L, 847L, 848L, 849L, 850L, 851L), class = "data.frame")
> ex.df <- head(ex.df, 100)
> dput(ex.df)
structure(list(location.code = structure(c(1L, 1L, 1L, 1L, 2L,
2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L), .Label = c("BSF1",
"BSG1", "RLF3", "RLG3", "CCBSF1", "CCBSG1", "CPF1", "CPF2", "CPG1",
"CPG2", "OSG1", "OSG2", "RLF4", "RLF5", "RLF1", "RLF2", "RLG1",
"RLG2", "BNPF1", "BNPG1", "OSG3", "OSF1", "CMG3", "CMF1", "BSG2",
"BSG3", "WSF1", "WSF2", "HPG1", "HPG2"), class = "factor"), stimuli = structure(c(3L,
3L, 3L, 3L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 2L, 2L, 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 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
1L, 1L), .Label = c("before", "during", "after"), class = "factor"),
timeperiod = c(6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
6L, 6L), distance.code = c(0L, 30L, 60L, 120L, 0L, 30L, 60L,
0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L,
30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L,
120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L,
30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L,
60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L,
0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L,
60L, 120L, 0L, 30L, 60L, 0L, 30L, 60L, 120L, 0L, 30L, 60L,
0L, 30L, 60L, 120L, 0L, 30L, 60L, 0L, 30L), Values = c(910.721895276374,
922.652711611841, 926.219785713456, 918.776924477918, 1030.28919690464,
1121.98321368732, 992.741416151102, 910.878353926705, 920.201901019659,
922.134996121665, 917.610324052986, 992.059286431433, 1042.05240231832,
1018.99804250179, 911.976009884021, 918.215389274037, 931.037495260958,
913.49701806948, 981.032280455129, 983.700699744073, 989.716307418049,
911.476759038955, 918.554393750162, 920.391856289719, 911.795802370903,
994.583211567691, 1006.58290843226, 1005.52479816571, 908.665064025178,
917.940176257067, 922.746174825048, 921.752449434568, 986.419049170517,
1042.41789735969, 1082.89658057517, 916.02310296116, 918.254868924698,
931.01648294424, 924.221021573334, 982.154409713674, 1008.54477137219,
996.577798511801, 912.914857937818, 916.937508116615, 920.933077377339,
917.443294381608, 997.669828575817, 1007.44452218386, 1151.25894192961,
909.463528658898, 915.293665875472, 921.917039784441, 912.073280663674,
983.866984633392, 1002.04551764872, 986.791628665069, 907.695668282537,
917.845214744473, 932.330755620455, 917.500330773026, 972.609449456089,
1155.55960936774, 1083.40557091613, 909.903267624225, 914.846316952797,
921.279328283221, 914.498616645498, 1000.3672969178, 1021.78461788922,
1011.40975353271, 915.037273600535, 914.099859036178, 924.116937361394,
913.523739017819, 994.428182266452, 1123.09745015276, 1004.1485272116,
914.431649376896, 915.27037594587, 929.411251949862, 910.549315840806,
974.273124973661, 1145.99211507205, 1013.58184367388, 913.467056616881,
920.213007520924, 919.794369158301, 912.333012054637, 983.816025282468,
1103.11322201674, 974.792027063404, 910.532609655114, 917.616832229923,
923.462599912213, 913.432298686233, 1015.24811721269, 1070.61183211249,
1016.57332551186, 910.196695694198, 923.403802532832), wind.speed = c(0.8,
0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2,
0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8,
0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8,
0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2,
0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2,
0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8,
0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8,
0.8, 0.8, 0.8, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8, 0.2, 0.2,
0.2, 65, 65)), row.names = c(85L, 86L, 87L, 88L, 89L, 90L,
91L, 99L, 100L, 101L, 102L, 103L, 104L, 105L, 113L, 114L, 115L,
116L, 117L, 118L, 119L, 127L, 128L, 129L, 130L, 131L, 132L, 133L,
141L, 142L, 143L, 144L, 145L, 146L, 147L, 155L, 156L, 157L, 158L,
159L, 160L, 161L, 169L, 170L, 171L, 172L, 173L, 174L, 175L, 183L,
184L, 185L, 186L, 187L, 188L, 189L, 197L, 198L, 199L, 200L, 201L,
202L, 203L, 211L, 212L, 213L, 214L, 215L, 216L, 217L, 225L, 226L,
227L, 228L, 229L, 230L, 231L, 239L, 240L, 241L, 242L, 243L, 244L,
245L, 253L, 254L, 255L, 256L, 257L, 258L, 259L, 267L, 268L, 269L,
270L, 271L, 272L, 273L, 615L, 616L), class = "data.frame")
Thanks for any help!
EDIT!!
I ran terms(fit1) as suggested in the comments, the results were as follows:
terms(fit1)
Values ~ stimuli + timeperiod + scale(poly(distance.code, 3,
raw = FALSE)) * habitat + wind.speed
attr(,"variables")
list(Values, stimuli, timeperiod, scale(poly(distance.code, 3,
raw = FALSE)), habitat, wind.speed)
attr(,"factors")
stimuli timeperiod scale(poly(distance.code, 3, raw = FALSE)) habitat wind.speed
Values 0 0 0 0 0
stimuli 1 0 0 0 0
timeperiod 0 1 0 0 0
scale(poly(distance.code, 3, raw = FALSE)) 0 0 1 0 0
habitat 0 0 0 1 0
wind.speed 0 0 0 0 1
scale(poly(distance.code, 3, raw = FALSE)):habitat
Values 0
stimuli 0
timeperiod 0
scale(poly(distance.code, 3, raw = FALSE)) 1
habitat 1
wind.speed 0
attr(,"term.labels")
[1] "stimuli" "timeperiod"
[3] "scale(poly(distance.code, 3, raw = FALSE))" "habitat"
[5] "wind.speed" "scale(poly(distance.code, 3, raw = FALSE)):habitat"
attr(,"order")
[1] 1 1 1 1 1 2
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
attr(,"predvars")
list(Values, stimuli, timeperiod, scale(poly(distance.code, 3,
raw = FALSE)), habitat, wind.speed)
Here is a simple parallel example illustrating that wrapping poly() in scale() is the culprit:
> library(emmeans)
> mod1 = lm(mpg ~ am + poly(disp, 3), data = mtcars)
> ref_grid(mod1)
'emmGrid' object with variables:
am = 0, 1
disp = 230.72
> mod2 = lm(mpg ~ am + scale(poly(disp, 3)), data = mtcars)
> ref_grid(mod2)
Error in poly(disp, 3) :
'degree' must be less than number of unique points
Specifically, the call to scale() messes up the predvars attribute in the model's terms component:
> attr(terms(mod1), "predvars")
list(mpg, am, poly(disp, 3, coefs = list(alpha = c(230.721875,
279.549822668452, 298.198735227759), norm2 = c(1, 32, 476184.7946875,
5315202742.2241, 64139299346388.8))))
This provides the coefficients needed to construct the orthogonal polynomial basis; whereas...
> attr(terms(mod2), "predvars")
list(mpg, am, scale(poly(disp, 3)))
That information is excluded.
Note that the scale() call is completely unnecessary anyway, as poly() generates an orthonormal matrix of predictors.
I have the following data-frame:
structure(list(inst = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("A8",
"b7", "X1"), class = "factor"), steps = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("5",
"10", "20"), class = "factor"), family = structure(c(6L,
1L, 4L, 5L, 7L, 2L, 3L, 6L, 7L, 5L, 4L, 1L, 2L, 3L, 3L, 6L, 4L,
1L, 2L, 7L, 5L, 6L, 5L, 4L, 1L, 7L, 2L, 3L, 6L, 5L, 4L, 7L, 1L,
2L, 3L, 6L, 1L, 3L, 5L, 4L, 2L, 7L, 6L, 4L, 1L, 5L, 7L, 2L, 3L,
6L, 4L, 1L, 5L, 7L, 2L, 3L, 6L, 3L, 5L, 4L, 7L, 1L, 2L), .Label = c("Bay",
"Grad", "none", "Upp", "base", "new", "tuna"
), class = "factor"), mean_error = c(5.930259, 6.0611, 6.241703,
6.270109, 6.277435, 6.587473, 6.865757, 5.936106, 6.084044, 6.140153,
6.142072, 6.146425, 6.364658, 6.621481, 6.759502, 7.02175, 7.16422,
7.19518, 7.36932, 7.395606, 7.44191, 5.113961, 5.123312, 5.289946,
5.292267, 5.455671, 5.768393, 5.840368, 5.140513, 5.346728, 5.371491,
5.463127, 5.475944, 5.602034, 5.995647, 5.784786, 6.00454, 6.121524,
6.22509, 6.24901, 6.37396, 6.41903, 4.0439, 4.223119, 4.260518,
4.31062, 4.500065, 4.822419, 5.107085, 4.221596, 4.371242, 4.505292,
4.524415, 4.681877, 4.703846, 5.14499, 4.944005, 5.007325, 5.0561975,
5.1926225, 5.3353825, 5.34204, 5.63557)), row.names = c(64L,
3L, 38L, 55L, 73L, 12L, 21L, 67L, 76L, 58L, 41L, 6L, 15L, 24L,
27L, 70L, 44L, 9L, 18L, 79L, 61L, 63L, 54L, 37L, 2L, 72L, 11L,
20L, 66L, 57L, 40L, 75L, 5L, 14L, 23L, 69L, 8L, 26L, 60L, 43L,
17L, 78L, 62L, 36L, 1L, 53L, 71L, 10L, 19L, 65L, 39L, 4L, 56L,
74L, 13L, 22L, 68L, 25L, 59L, 42L, 77L, 7L, 16L), class = "data.frame")
I am trying to create groups of three steps per inst in the x-axis and fit everything in one plot. The outcome should resemble this
So far I tried:
df_bri %>% select(steps, inst, family, mean_error) %>%
ggplot(aes(x = steps, y = mean_error, fill = mean_error)) +
geom_boxplot()
and I get this:
I don't know how to separate the groups into 3 steps per inst.
fill=steps is what you need:
ggplot(df, aes(x = inst, y = mean_error, fill = steps)) +
geom_boxplot()
I managed to create a faceted boxplot with my 2 quantitative variables;
I know how to run a kruskal-wallis followed by a Wilcoxon test and show the significant differences with letters in the boxplot but only in a simple boxplot, with one variable and without facet. How can I do ?
(If possible, I would like to put the siginificant differences with letters, I wish I would be able to post the pictures of what I already done but apparently I'm not allowed)
Also, I have another question; Which test does the function stat_function_mean execute ? I tried to use this function, but I don't know how to use it... Here is my code without the test, only the facetted boxplot with my two variables :
Code for my facet boxplot with 2 measured variables ( FF and FM)
dat.m2 <- melt(pheno,id.vars=c("fusion","Genotype","Hormone"),
measure.vars=c('FF','MF'))
dat.m2$fusion<-factor(dat.m2$fusion, levels=c("Control", "CK 20 mg/L", "CK 100 mg/L", "CK 500 mg/L", "GA 20 mg/L", "GA 100 mg/L", "GA 500 mg/L"))
levels(dat.m2$fusion)
ggplot(dat.m2) +
geom_boxplot(aes(x=fusion, y=value, colour=variable))+
facet_wrap(~Genotype)+
xlab(" ")+
ylab("Days after sowing")
Code to add significant differences on the graph, with letters, but with only 1 measured variable (FF), without facet
mymat <-tri.to.squ(pp$p.value)
mymat
myletters <- multcompLetters(mymat,compare="<=",threshold=0.05,Letters=letters)
myletters
myletters_df <- data.frame(fusion=names(myletters$Letters),letter = myletters$Letters )
myletters_df
ggplot(pheno, aes(x=fusion, y=FF, colour=fusion))+
geom_boxplot()+
geom_text(data = myletters_df, aes(label = letter, y = 30 ), colour="black", size=5)+
ylab("Days after sowing")+
xlab("")+
labs(title="Days to female flower production")+
theme(plot.title = element_text(hjust = 0.5))+
> dput(pheno)
structure(list(Genotype = structure(c(2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L,
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L,
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("F1045",
"FF", "M1585", "M1610"), class = "factor"), X = structure(c(1L,
105L, 116L, 127L, 138L, 149L, 160L, 171L, 182L, 2L, 13L, 24L,
35L, 46L, 57L, 68L, 79L, 90L, 101L, 106L, 107L, 108L, 109L, 110L,
111L, 112L, 113L, 114L, 115L, 117L, 118L, 119L, 120L, 121L, 122L,
123L, 124L, 125L, 126L, 128L, 129L, 130L, 131L, 132L, 133L, 134L,
135L, 136L, 137L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L,
147L, 148L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L,
159L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L,
172L, 173L, 174L, 175L, 176L, 177L, 178L, 179L, 180L, 181L, 183L,
184L, 185L, 186L, 187L, 188L, 189L, 190L, 191L, 192L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 47L, 48L,
49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 58L, 59L, 60L, 61L, 62L,
63L, 64L, 65L, 66L, 67L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L,
77L, 78L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 91L,
92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 102L, 103L, 104L
), .Label = c("H1", "H10", "H100", "H101", "H102", "H103", "H104",
"H105", "H106", "H107", "H108", "H109", "H11", "H110", "H111",
"H112", "H113", "H114", "H115", "H116", "H117", "H118", "H119",
"H12", "H120", "H121", "H122", "H123", "H124", "H125", "H126",
"H127", "H128", "H129", "H13", "H130", "H131", "H132", "H133",
"H134", "H135", "H136", "H137", "H138", "H139", "H14", "H140",
"H141", "H142", "H143", "H144", "H145", "H146", "H147", "H148",
"H149", "H15", "H150", "H151", "H152", "H153", "H154", "H155",
"H156", "H157", "H158", "H159", "H16", "H160", "H161", "H162",
"H163", "H164", "H165", "H166", "H167", "H168", "H169", "H17",
"H170", "H171", "H172", "H173", "H174", "H175", "H176", "H177",
"H178", "H179", "H18", "H180", "H181", "H182", "H183", "H184",
"H185", "H186", "H187", "H188", "H189", "H19", "H190", "H191",
"H192", "H2", "H20", "H21", "H22", "H23", "H24", "H25", "H26",
"H27", "H28", "H29", "H3", "H30", "H31", "H32", "H33", "H34",
"H35", "H36", "H37", "H38", "H39", "H4", "H40", "H41", "H42",
"H43", "H44", "H45", "H46", "H47", "H48", "H49", "H5", "H50",
"H51", "H52", "H53", "H54", "H55", "H56", "H57", "H58", "H59",
"H6", "H60", "H61", "H62", "H63", "H64", "H65", "H66", "H67",
"H68", "H69", "H7", "H70", "H71", "H72", "H73", "H74", "H75",
"H76", "H77", "H78", "H79", "H8", "H80", "H81", "H82", "H83",
"H84", "H85", "H86", "H87", "H88", "H89", "H9", "H90", "H91",
"H92", "H93", "H94", "H95", "H96", "H97", "H98", "H99"), class = "factor"),
Hormone = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L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 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L), .Label = c("100", "20", "500", "Control"
), class = "factor"), fusion = structure(c(4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("CK 100 mg/L",
"CK 20 mg/L", "CK 500 mg/L", "Control", "GA 100 mg/L", "GA 20 mg/L",
"GA 500 mg/L"), class = "factor"), Sowing.date = structure(c(1L,
1L, 1L, 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, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 6L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 8L, 4L, 6L, 6L, 6L, 4L, 3L, 4L, 4L, 3L,
4L, 3L, 3L, 3L, 3L, 6L, 6L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 4L, 3L, 4L, 3L, 3L, 3L, 4L, 3L, 6L, 6L, 8L, 6L, 4L, 4L,
4L, 8L, 4L, 4L, 2L, 3L, 3L, 3L, 3L, 6L, 3L, 5L, 4L, 5L, 5L,
4L, 3L), .Label = c("16-apr", "17-apr", "18-apr", "19-apr",
"21-mei", "23-apr", "26-apr", "30-apr"), class = "factor"),
ff = structure(c(14L, 20L, 4L, 10L, 20L, 3L, 1L, 14L, 9L,
11L, 20L, 11L, 9L, 9L, 9L, 11L, 12L, 12L, 6L, 12L, 12L, 16L,
12L, 12L, 17L, 17L, 12L, 16L, 17L, 18L, 12L, 6L, 20L, 20L,
15L, 15L, 15L, 20L, 20L, 11L, 11L, 11L, 9L, 9L, 9L, 9L, 20L,
20L, 20L, 4L, 1L, 4L, 4L, 4L, 8L, 20L, 4L, 20L, 12L, 4L,
14L, 14L, 11L, 11L, 15L, 15L, 11L, 11L, 9L, 15L, 9L, 9L,
11L, 11L, 14L, 1L, 5L, 4L, 4L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 15L, 15L, 14L, 13L, 15L, 15L, 11L, 9L, 9L,
11L, 9L, 11L, 1L, 20L, 1L, 20L, 20L, 20L, 20L, 1L, 1L, 4L,
20L, 20L, 20L, 15L, 15L, 14L, 15L, 1L, 15L, 15L, 20L, 11L,
11L, 11L, 11L, 15L, 10L, 10L, 16L, 10L, 12L, 10L, 17L, 8L,
16L, 12L, 8L, 4L, 4L, 8L, 20L, 10L, 1L, 20L, NA, 12L, 10L,
20L, 20L, 20L, 1L, 20L, 1L, 20L, 12L, 16L, 12L, 2L, 8L, 4L,
10L, 4L, 4L, 4L, 10L, 8L, 4L, 8L, 20L, 20L, 20L, NA, 20L,
1L, 20L, 1L, 8L, 20L, 1L, 1L, 7L, 17L, 19L, 19L, 12L, 10L,
12L, 19L, 10L, 10L, 10L, 17L), .Label = c("10-mei", "13-jun",
"14-apr", "14-mei", "17-mei", "18-jun", "21-jun", "21-mei",
"23-apr", "24-mei", "26-apr", "28-mei", "3-apr", "3-mei",
"30-apr", "31-mei", "4-jun", "5-jul", "7-jun", "7-mei"), class = "factor"),
FH = c(3.5, 6, 9, 16, 5.5, 12, 11.5, 4, 4.5, 6, 8, 5, 4.5,
3.5, 4, 5, 20, 42, 14, 40, 27, 42, 27, 26, 16, 18, 35, 17,
20, 28, 15, 20, 33, 32, 14.5, 14.5, 14.5, 35, 32, 12.5, 13.5,
12, 14.5, 12, 15, 14.5, 18, 18, 18.5, 35, 23, 25, 30, 37,
53, 27.5, 37, 25.5, 35, 47, 8.5, 20.5, 13, 14.5, 13.5, 18.5,
10.5, 10, 14.3, 18.5, 15.3, 11.7, 16, 15, 13.5, 26, 36, 30,
43, 23.5, 23.5, 31.5, 29, 30.5, 30, 29, 30, 24.5, 19, 23,
21.5, 26.5, 18.5, 20, 15, 12.3, 17, 12, 15, 13, 43614, 25,
27, 22.5, 35, 23.5, 30, 42, 42, 55, 32.5, 26, 26, 9.5, 4.5,
5.5, 5, 15.5, 10, 4.5, 8.5, 6, 5, 5.5, 5, 4.5, 30, 20, 16,
16, 20, 22, 30, 22, 25, 11, 13.5, 11, 11, 14, 6, NA, 5.5,
7, NA, 12, 14, 7, 9.5, 6.5, 9, 8.5, 12.5, 8, 27, 33, 35,
32, 17, 14, 22, 11, 17, 12, 25, 22, 15, 10, 5, 3, 4, NA,
5, 8, 4.5, 6, 7, 5, 5.5, 7, 42, 23, 23, 21, 14, 21, 17, 22,
19, 18, 17, 17), SRDT = structure(c(2L, 7L, 14L, NA, 7L,
8L, 7L, NA, NA, NA, 3L, NA, 18L, 15L, 17L, 17L, 18L, 18L,
NA, 18L, 15L, 17L, 15L, 20L, 2L, NA, 11L, 17L, 18L, 2L, 2L,
2L, 14L, 12L, 17L, 15L, 12L, 9L, 9L, 6L, 6L, 15L, 15L, 15L,
15L, NA, 17L, 15L, 10L, 11L, 11L, 10L, 11L, 17L, 5L, 21L,
6L, NA, 20L, 5L, 12L, 7L, NA, 17L, 17L, 15L, 15L, 10L, 10L,
6L, 10L, 10L, 21L, NA, 15L, 15L, 5L, 15L, 15L, 11L, 10L,
21L, 1L, 21L, 21L, 21L, 1L, 5L, 18L, 2L, 9L, 9L, NA, 12L,
10L, NA, 16L, 6L, 6L, 15L, 6L, 10L, 10L, 10L, 1L, 10L, 1L,
21L, 21L, 1L, 21L, 5L, 18L, 2L, 17L, 20L, 9L, 14L, 5L, 9L,
9L, 11L, NA, 18L, 10L, 18L, 20L, 4L, 9L, 7L, 2L, 2L, 7L,
5L, 17L, 17L, 11L, 10L, 12L, 2L, 14L, 19L, 19L, 19L, NA,
NA, 2L, 11L, 17L, 14L, 17L, 9L, 10L, 10L, 2L, 7L, 17L, 14L,
2L, 11L, 20L, 2L, 15L, 15L, 11L, 5L, NA, 10L, NA, 2L, 8L,
NA, NA, 14L, 5L, 15L, 15L, NA, 22L, NA, 9L, 9L, 19L, 9L,
9L, 22L, 20L, 13L, 7L, 20L, 15L, 20L), .Label = c("10-mei",
"11-jun", "13-jun", "13-mei", "14-mei", "17-mei", "18-jun",
"2-jul", "21-jun", "21-mei", "24-mei", "25-jun", "26-jun",
"28-jun", "28-mei", "3-mei", "31-mei", "4-jun", "5-jul",
"7-jun", "7-mei", "9-jul"), class = "factor"), MH = c(26,
50, 58, NA, 46, 58, 61, NA, NA, NA, 40, NA, 68, 48, 47, 42,
26, 50, NA, 48, 27, 42, 27, 48, 25, NA, 25, 17, 20, 18, 32,
19, 75, 75, 65, 70, 73, 73, 71, 65, 70, 60, 80, 70, 70, NA,
54, 45, 45, 45, 45, 40, 49, 53, 45, 27.5, 44, NA, NA, 47,
47, 62, NA, 75, 60, 75, 70, 65, 80, 67, 80, 75, 52, NA, 67,
68, 26, 55, 60, 60, 60, 31.5, 39, 30.5, 30, 29, 39, 39, 86,
74, 80, 76, NA, 69, 80, NA, 44, 70, 70, 65, 43, 60, 57, 57,
45, 60, 39, 35, 32.5, 27, 32.5, 43, 70, 75, 60, 66, 58, 48,
41, NA, 44, 42, NA, 44, 39, 40, 48, 53, 50, 50, 45, 45, 50,
13, 25, 11, 21, 20.5, 46, 44, 54, 25, 20, 25, NA, NA, 28,
33, 36, 40, 21, 36, 23.5, 21, 44, 60, 37, 37, 55, 24, 45,
45, 35, 30, 25, 12, 27, 10, NA, 53, 35, NA, NA, 43, 11, 13,
7, NA, 22, NA, 42, 46, NA, 41, 43, 40, 26, 45, 35, 29, 17,
22), SEEDT = structure(c(2L, 4L, 9L, NA, 4L, 5L, 4L, NA,
NA, NA, 4L, NA, 12L, 11L, 11L, 11L, 4L, 3L, NA, 4L, 15L,
4L, 8L, 5L, 7L, NA, 2L, 2L, 8L, 13L, 8L, NA, 13L, 8L, 15L,
15L, 8L, 7L, 7L, 10L, 10L, 11L, 6L, 10L, 10L, NA, 3L, 11L,
12L, 12L, 12L, 12L, 4L, 4L, 12L, 12L, 12L, NA, 9L, 12L, NA,
4L, NA, 2L, 15L, 2L, 15L, 14L, 10L, 12L, 12L, 11L, 11L, NA,
2L, 12L, 8L, 3L, 15L, 11L, 11L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 2L, 2L, 7L, 7L, NA, 8L, 10L, NA, 10L, 10L, 10L,
15L, 10L, 12L, 12L, 10L, 11L, 11L, 10L, 10L, 10L, 11L, 10L,
11L, 12L, 2L, 12L, 4L, 7L, 9L, 10L, 7L, 7L, 10L, NA, 12L,
10L, 15L, 2L, 4L, 8L, 8L, 4L, 4L, 13L, 12L, NA, NA, 4L, 7L,
NA, 7L, 13L, 13L, 13L, NA, NA, NA, 2L, 2L, NA, NA, NA, 8L,
NA, NA, 4L, 4L, 2L, NA, 4L, 2L, 7L, 7L, 7L, 2L, 2L, 15L,
1L, 15L, NA, 2L, 5L, NA, NA, 5L, 13L, NA, NA, NA, NA, NA,
16L, 16L, 13L, 16L, 7L, 1L, 7L, 16L, 7L, 7L, 7L, NA), .Label = c("11-jul",
"11-jun", "13-jun", "18-jun", "2-jul", "20-mei", "21-jun",
"25-jun", "28-jun", "28-mei", "31-mei", "4-jun", "5-jul",
"6-apr", "7-jun", "9-jul"), class = "factor"), FERMK = c(7L,
8L, 8L, 7L, 8L, 8L, 8L, 4L, NA, NA, 5L, 7L, 7L, 6L, 7L, 6L,
4L, 6L, NA, 4L, 3L, 4L, 4L, 4L, 2L, NA, 2L, 2L, 2L, 1L, 2L,
2L, 8L, 6L, 6L, 6L, 7L, 7L, 7L, 6L, 6L, 7L, 7L, 6L, 4L, 6L,
6L, 5L, 6L, 5L, 5L, 6L, 5L, 4L, 2L, 5L, NA, NA, 4L, 2L, 5L,
5L, NA, 7L, 7L, 8L, 6L, 6L, 7L, NA, 7L, 7L, 6L, 5L, 5L, 5L,
4L, 4L, 6L, 7L, 6L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 8L, 7L, 7L,
7L, 7L, 7L, 7L, NA, 7L, 7L, 7L, 7L, 5L, 5L, 4L, 5L, 6L, 4L,
6L, 2L, 2L, 2L, 5L, 4L, 7L, 6L, 8L, 7L, 6L, 6L, 8L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 5L, 5L, 4L, 4L, 4L, 4L, 2L, 2L, NA,
3L, 2L, NA, 3L, 6L, 5L, 5L, 6L, NA,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 64L, 64L, 71L,
71L, 64L, 67L, 71L, 102L, 64L, 85L, 43L, 43L, 36L, 36L, 36L,
43L, 43L, 32L, 32L, 32L, 29L, 29L, 29L, 29L, 43L, 43L, 43L,
50L, 46L, 50L, 50L, 50L, 57L, 43L, 50L, 43L, 64L, 50L, 39L,
39L, 32L, 32L, 36L, 36L, 32L, 32L, 29L, 36L, 29L, 29L, 32L,
32L, 39L, 46L, 53L, 50L, 50L, 43L, 43L, 43L, 43L, 43L, 43L,
43L, 43L, 43L, 36L, 36L, 39L, 9L, 36L, 36L, 32L, 29L, 29L,
32L, 29L, 32L, 46L, 43L, 46L, 43L, 43L, 43L, 43L, 46L, 46L,
50L, 43L, 43L, 43L, 36L, 36L, 39L, 36L, 46L, 36L, 36L, 43L,
32L, 32L, 32L, 32L, 36L, 60L, 60L, 67L, 60L, 64L, 60L, 71L,
57L, 67L, 64L, 57L, 50L, 50L, 57L, 43L, 60L, 46L, 43L, NA,
64L, 60L, 43L, 43L, 43L, 46L, 43L, 46L, 43L, 64L, 67L, 64L,
80L, 57L, 50L, 60L, 50L, 50L, 50L, 60L, 57L, 50L, 57L, 43L,
43L, 43L, NA, 43L, 46L, 43L, 46L, 57L, 43L, 46L, 46L, 88L,
71L, 74L, 74L, 64L, 60L, 64L, 74L, 60L, 60L, 60L, 71L), MF = c(78L,
85L, 95L, NA, 85L, 99L, 85L, NA, NA, NA, 80L, NA, 71L, 64L,
67L, 67L, 71L, 71L, NA, 71L, 64L, 67L, 64L, 74L, 78L, NA,
60L, 67L, 71L, 78L, 78L, 78L, 95L, 92L, 67L, 64L, 92L, 88L,
88L, 53L, 53L, 64L, 64L, 64L, 64L, NA, 67L, 64L, 57L, 60L,
60L, 57L, 60L, 67L, 50L, 43L, 53L, NA, 74L, 50L, 92L, 85L,
NA, 67L, 67L, 64L, 64L, 57L, 57L, 53L, 57L, 57L, 43L, NA,
64L, 64L, 50L, 64L, 64L, 60L, 57L, 43L, 46L, 43L, 43L, 43L,
46L, 50L, 71L, 78L, 88L, 88L, NA, 92L, 57L, NA, 39L, 53L,
53L, 64L, 53L, 57L, 57L, 57L, 46L, 57L, 46L, 43L, 43L, 46L,
43L, 50L, 71L, 78L, 67L, 74L, 88L, 95L, 50L, 88L, 88L, 60L,
NA, 71L, 57L, 71L, 74L, 49L, 88L, 85L, 78L, 78L, 85L, 50L,
67L, 67L, 60L, 57L, 92L, 78L, 95L, 102L, 102L, 102L, NA,
NA, 78L, 60L, 67L, 95L, 67L, 88L, 57L, 57L, 78L, 85L, 67L,
95L, 78L, 60L, 74L, 78L, 64L, 64L, 60L, 50L, NA, 57L, NA,
78L, 99L, NA, NA, 95L, 50L, 64L, 64L, NA, 106L, NA, 88L,
88L, 102L, 88L, 88L, 106L, 74L, 93L, 85L, 74L, 64L, 74L),
speed = c(0.08974359, 0.139534884, 0.18, 0.266666667, 0.127906977,
0.6, 0.25, 0.102564103, 0.155172414, 0.1875, 0.186046512,
0.15625, 0.155172414, 0.120689655, 0.137931034, 0.15625,
0.3125, 0.65625, 0.164705882, 0.625, 0.421875, 0.626865672,
0.421875, 0.40625, 0.225352113, 0.253521127, 0.546875, 0.253731343,
0.281690141, 0.274509804, 0.234375, 0.235294118, 0.76744186,
0.744186047, 0.402777778, 0.402777778, 0.402777778, 0.813953488,
0.744186047, 0.390625, 0.421875, 0.375, 0.5, 0.413793103,
0.517241379, 0.5, 0.418604651, 0.418604651, 0.430232558,
0.7, 0.5, 0.5, 0.6, 0.74, 0.929824561, 0.639534884, 0.74,
0.593023256, 0.546875, 0.94, 0.217948718, 0.525641026, 0.40625,
0.453125, 0.375, 0.513888889, 0.328125, 0.3125, 0.493103448,
0.513888889, 0.527586207, 0.403448276, 0.5, 0.46875, 0.346153846,
0.565217391, 0.679245283, 0.6, 0.86, 0.546511628, 0.546511628,
0.73255814, 0.674418605, 0.709302326, 0.697674419, 0.674418605,
0.697674419, 0.569767442, 0.527777778, 0.638888889, 0.551282051,
2.944444444, 0.513888889, 0.555555556, 0.46875, 0.424137931,
0.586206897, 0.375, 0.517241379, 0.40625, 948.1304348, 0.581395349,
0.586956522, 0.523255814, 0.813953488, 0.546511628, 0.697674419,
0.913043478, 0.913043478, 1.1, 0.755813953, 0.604651163,
0.604651163, 0.263888889, 0.125, 0.141025641, 0.138888889,
0.336956522, 0.277777778, 0.125, 0.197674419, 0.1875, 0.15625,
0.171875, 0.15625, 0.125, 0.5, 0.333333333, 0.23880597, 0.266666667,
0.3125, 0.366666667, 0.422535211, 0.385964912, 0.373134328,
0.171875, 0.236842105, 0.22, 0.22, 0.245614035, 0.139534884,
NA, 0.119565217, 0.162790698, NA, 0.1875, 0.233333333, 0.162790698,
0.220930233, 0.151162791, 0.195652174, 0.197674419, 0.27173913,
0.186046512, 0.421875, 0.492537313, 0.546875, 0.4, 0.298245614,
0.28, 0.366666667, 0.22, 0.34, 0.24, 0.416666667, 0.385964912,
0.3, 0.175438596, 0.11627907, 0.069767442, 0.093023256, NA,
0.11627907, 0.173913043, 0.104651163, 0.130434783, 0.122807018,
0.11627907, 0.119565217, 0.152173913, 0.477272727, 0.323943662,
0.310810811, 0.283783784, 0.21875, 0.35, 0.265625, 0.297297297,
0.316666667, 0.3, 0.283333333, 0.23943662), ratiofm = c(7,
4, 8, 7, 8, 8, 8, NA, NA, NA, 5, 3.5, NA, NA, NA, NA, 4,
6, NA, 4, 3, 2, 4, 4, 0.5, NA, 0.4, 0.4, 0.5, 0.2, 0.666666667,
0.5, 8, 6, 6, 6, 7, 7, 7, 3, 3, 3.5, 3.5, 6, 4, NA, 3, 2.5,
3, 5, 2.5, 3, 5, 4, 0.5, 1, NA, NA, 0.8, 0.333333333, 5,
5, NA, 7, 7, NA, 6, 6, 7, NA, 3.5, 7, 3, NA, 2.5, NA, 1,
1.333333333, 3, 3.5, 6, 1, 0.4, 0.4, 0.5, 0.4, 0.285714286,
0.333333333, 8, 7, 7, 7, NA, 7, 3.5, NA, 7, 7, 7, 7, 1.666666667,
1.666666667, 4, 1.25, 1.2, 2, 1.5, 0.285714286, 0.4, 0.25,
1, 2, NA, 6, 8, 7, 0.857142857, 6, NA, 7, 7, NA, NA, NA,
NA, NA, 3.5, 1.666666667, 5, 4, 2, 4, 2, 0.333333333, 0.333333333,
NA, 0.75, 0.5, NA, 1.5, 3, 5, 5, 6, NA, 6, 4, 2, 5, 5, 5,
5, NA, NA, 4, 4, 3, 2.5, 3, 2.5, 2.333333333, 3.5, 3.5, 0.6,
0.4, 0.75, 3, 1, NA, 2.5, 5, NA, NA, 2.5, 1.5, NA, NA, NA,
4, NA, 1.25, 2, 5, 2.5, 6, 2, 1, 3, 1.5, 1, 1.666666667,
NA)), class = "data.frame", row.names = c(NA, -192L))
It would be more clear with pictures of my graphs, but apparently I'm not allowed yet to include pictures in my posts, sorry
Thanks in advance for your help
you can try
library(tidyverse)
df %>%
as_tibble() %>%
ggplot(aes(x=fusion, y=FF)) +
geom_boxplot(aes(colour=fusion))+
ggsignif::geom_signif(comparisons = combn(levels(df$fusion), 2, simplify = F), step_increase = 0.3) +
ggpubr::stat_compare_means() +
facet_wrap(~Genotype)+
xlab(" ")+
ylab("Days after sowing")
I am till having trouble with this, so I have edited my question (below) to include my data.
I would like to add two different labels (the respective sample sizes) to each of the sections of the grid.
I know I need to use geom_text, but I just can't seem to get it to work. Everything I have tried has returned errors. Here is the code I used to make my graph so far:
ggplot(data = Q, mapping = aes(y = Rating, x = week, group= StudentFactor, colour=StudentFactor))+
geom_point()+
geom_line()+
facet_grid(Type ~.)+
geom_smooth(method = 'lm', formula = y ~ poly(x), colour= "black", aes(group=1), se= FALSE)+
theme(legend.position="none") +
labs (x= "Week", y="Rating of Q: Seniors Supportive vs. Supporting First Years")
Someone mentioned that it might be helpful if I included the following:
> dput(Q)
structure(list(StudentFactor = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L,
6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L,
9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L,
23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 25L, 26L,
26L, 26L, 26L, 26L, 27L, 27L, 27L, 28L, 28L, 29L, 29L, 29L, 29L,
29L, 29L, 29L, 29L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 31L, 31L, 31L, 32L, 32L, 32L, 32L, 32L, 32L, 33L, 33L, 33L,
33L, 33L, 33L, 33L, 33L, 34L, 34L, 34L, 34L, 35L, 35L, 35L, 35L,
35L, 35L, 35L, 35L, 35L, 35L, 36L, 36L, 36L), .Label = c("789331",
"796882", "805933", "826523", "827911", "830271", "831487", "832929",
"834598", "836364", "838607", "839802", "841903", "843618", "852125",
"855524", "873527", "876406", "879972", "885409", "885650", "888712",
"894218", "903303", "928026", "952797", "955389", "956952", "957206",
"957759", "959200", "962490", "965873", "967416", "968728", "969005"
), class = "factor"), Question = structure(c(1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1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,
0, 0, -1, 1, 0, 0, 0, -1, 0, 1, -1, 0, 0, 0, 1, -1, 1, -1,
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 1, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 1, -1, 1, 0, 0, 1, 0, 0, 0, 0, -2, 2, 0, 0, 0,
0, 0, 1, 0, 1, -1, 0, 1, -1, 0, 1, 2, -1, 0, 1, 0, 1, -1,
1, 0, -1, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 1, -1, 1, -1,
1, -1, -3, 3, 0, 0, -1, 0, -1, 0, 1, 1, 0, 0, 1, 0, 0, 1,
-1, 1, -1, 0, -2, 2, -1, -1, 1, 0, 0)), class = "data.frame", row.names = c(NA,
-231L), .Names = c("StudentFactor", "Question", "Type", "week",
"Rating"))
Earlier Question:
I have used the following code to make this graph:
ggplot(data = Q, mapping = aes(y = Rating, x = week, group= StudentFactor, colour=StudentFactor))+
geom_point()+
geom_line()+
facet_grid(Q$Type ~.)+
geom_smooth(method = "lm", se=FALSE, color="black", aes(group=1))+
theme(legend.position="none") +
labs (x= "Week", y="Rating of Q: Seniors Supportive vs. Supporting First Years")
However, as soon as I try to add an annotation to include the sample size for each cohort, I get the following error:
Error in `$<-.data.frame`(`*tmp*`, "PANEL", value = c(2L, 2L, 2L, 2L, :
replacement has 231 rows, data has 1
This is the code I am trying to use:
ggplot(data = Q, mapping = aes(y = Rating, x = week, group= StudentFactor, colour=StudentFactor))+
geom_point()+
geom_line()+
facet_grid(Q$Type ~.)+
geom_smooth(method = "lm", se=FALSE, color="black", aes(group=1))+
theme(legend.position="none") +
labs (x= "Week", y="Rating of Q: Seniors Supportive vs. Supporting First Years")+
annotate("text", x = 1, y=4, label = "N=")
I am a complete beginner at R. Any help would be appreciated! Thank you in advance!
I guess, you would like to label each panel with the respective sample size, or to add the total sample size just in one place. In that case annotate will be of no use (see for example this question), but you can use geom_text instead:
You would create a separate data.frame for your labels, which you then use inside of geom_text:
library(ggplot2)
labels <- tibble::tribble(~mpg, ~hp, ~cyl, ~label,
15, 200, 4, "label 1",
15, 150, 6, "label 2")
ggplot(mtcars, aes(mpg, hp)) +
geom_point() +
facet_wrap(~cyl) +
geom_text(data = labels, aes(label = label))
(Since you didn't provide data which would make it possible to reproduce your graphs, I simply used mtcars to illustrate the problem.)
Edit:
Using your data I adapted the code. First you create a data.frame for your label(s):
labels <- data.frame(
x = 2.5,
y = 3,
Type = "FYS",
label = "mylabel"
)
Then you simply add the following line to your code:
... +
geom_text(data = labels, aes(x = x, y = y, label = label), inherit.aes = FALSE)
This approach is slightly different than what I showed above: Either you supply the coordinates according to your variables, which you use in the rest of the plot, or you give them new names, use inherit.aes = FALSE and set the new variables with aes as demonstrated with your data.
Full code:
labels <- data.frame(
x = 2.5,
y = 3,
Type = "FYS",
label = "mylabel"
)
ggplot(data = Q, mapping = aes(y = Rating, x = week, group= StudentFactor, colour=StudentFactor))+
geom_point()+
geom_line()+
facet_grid(Type ~ .)+
geom_smooth(method = 'lm', formula = y ~ poly(x), colour= "black", aes(group=1), se= FALSE)+
theme(legend.position="none") +
labs (x= "Week", y="Rating of Q: Seniors Supportive vs. Supporting First Years") +
geom_text(data = labels, aes(x = x, y = y, label = label), inherit.aes = FALSE)
Your error is due to using facet_grid incorrectly. Replace your line with facet_grid(Type ~.)+ instead of Q$Type. For example:
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point() +
facet_grid(iris$Species ~ .) +
annotate("text", x = 7, y = 4, label = "foo")
Error in '$<-.data.frame'('*tmp*', "PANEL", value = c(1L, 1L, 1L, 1L, :
replacement has 150 rows, data has 1
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point() +
facet_grid(Species ~ .) +
annotate("text", x = 7, y = 4, label = "foo")
No error:
I am trying to plot a number of lmer models for a paper. I had to simplify the random effect structure by dropping the correlation between the random slopes and intercept (Barr et al., 2013). However, when I try to plot using the sjp.lmer funtion, I get the following error:
Error in array(NA, c(J, K)) : 'dims' cannot be of length 0
In addition: Warning message:
In ranef.merMod(object, condVar = TRUE) :
conditional variances not currently available via ranef when there are multiple terms per factor
Is there a potential work-around for this? Any help would be greatly appreciated.
Hi Ben,
Here is some of the data I am working with:
> dput(df)
structure(list(Subject = c(1L, 2L, 3L, 5L, 6L, 6L, 6L, 7L, 7L,
7L, 8L, 8L, 8L, 9L, 9L, 9L, 10L, 10L, 11L, 11L, 11L, 12L, 12L,
13L, 13L, 14L, 14L, 15L, 15L, 16L, 16L, 16L, 17L, 17L, 17L, 18L,
18L, 18L, 19L, 19L, 20L, 20L, 21L, 21L, 22L, 22L, 23L, 23L, 23L,
24L, 24L, 25L, 25L, 25L, 26L, 26L, 26L, 27L, 27L, 28L, 28L, 29L,
29L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L,
41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L,
54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L,
67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L,
80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L,
93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L, 104L,
105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L, 115L,
116L), A = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1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= "factor"), C = c(9.58,
9.75, 15, 10.75, 13.3, 14.42, 15.5, 9.25, 10.33, 11.33, 9.55,
11, 11.92, 14.25, 15.5, 16.42, 14.92, 16.17, 10.83, 11.92, 12.92,
7.5, 8.5, 10.33, 11.25, 13.08, 13.83, 14.92, 15.92, 9.58, 14.83,
11.92, 8.33, 9.5, 10.5, 6.8, 7.92, 9, 13.5, 10.92, 10, 11, 13,
15.58, 12.92, 11.8, 5.75, 6.75, 7.83, 11.12, 12.25, 12.08, 13.08,
14.58, 8.08, 9.17, 10.67, 10.6, 12.67, 7.83, 8.83, 9.67, 10.58,
11.75, 7, 17.17, 11.25, 13.75, 11.83, 16.92, 8.83, 7.07, 7.83,
15.08, 15.83, 16.67, 18.87, 11.92, 12.83, 7.83, 12.33, 10, 11.08,
12.08, 15.67, 11.75, 15, 14.308, 15.9064, 16.161, 16.9578, 8.90197,
16.2897, 9.05805, 10.5969, 5.15334, 9.1046, 14.1019, 18.9736,
10.9447, 14.5455, 16.172, 6.65389, 11.3171, 12.2864, 17.9929,
10.5778, 16.9195, 7.6, 7.8, 7.2, 16.7, 17, 16.5, 17, 15.1, 16,
16.4, 13.8, 13.8, 14.5, 16.1, 15.8, 15, 14.1, 15, 14.7, 15, 14.5,
10.8, 11.4, 11.3, 10.9, 11.2, 9.3, 10.8, 9.7, 8, 8.2, 8.2, 17.5,
12.6, 11.6, 10.8, 11.8, 12.3, 16.3, 17.1, 9.626283368, 14.6,
13.7), D = structure(c(2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L,
2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L,
1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("1",
"2"), class = "factor"), Frontal_FA = c(0.4186705, 0.4151535,
0.4349945, 0.4003705, 0.403488, 0.407451, 0.3997135, 0.38826,
0.3742275, 0.3851655, 0.3730715, 0.3825115, 0.3698805, 0.395406,
0.39831, 0.4462415, 0.413532, 0.419088, 0.4373975, 0.4633915,
0.4411375, 0.3545255, 0.389322, 0.349402, 0.352029, 0.367792,
0.365298, 0.3790775, 0.379298, 0.36231, 0.3632755, 0.357868,
0.3764865, 0.3726645, 0.351422, 0.3353255, 0.334196, 0.3462365,
0.367369, 0.3745925, 0.3610755, 0.360576, 0.357035, 0.3554905,
0.3745615, 0.38828, 0.3293275, 0.3246945, 0.3555345, 0.375563,
0.38116, 0.387508, 0.357707, 0.413193, 0.3658075, 0.3776355,
0.362678, 0.3824945, 0.3771, 0.375347, 0.362468, 0.367618, 0.3630925,
0.3763995, 0.359458, 0.3982755, 0.3834765, 0.386135, 0.3691575,
0.388099, 0.350435, 0.3629045, 0.3456775, 0.4404815, 0.4554165,
0.425763, 0.4491515, 0.461206, 0.453745, 0.4501255, 0.4451875,
0.4369835, 0.456838, 0.437759, 0.4377635, 0.44434, 0.4436615,
0.437532, 0.4335325, 0.4407995, 0.470447, 0.4458525, 0.440322,
0.4570775, 0.4410335, 0.436045, 0.4721345, 0.4734515, 0.4373905,
0.4139465, 0.440213, 0.440281, 0.425746, 0.454377, 0.4457435,
0.488561, 0.4393565, 0.4610565, 0.3562055, 0.381041, 0.353253,
0.4265975, 0.4069595, 0.40092, 0.4261365, 0.429605, 0.425479,
0.4331755, 0.3981285, 0.4206245, 0.3798475, 0.3704155, 0.395192,
0.404436, 0.4148915, 0.416144, 0.384652, 0.3916045, 0.41005,
0.3940605, 0.3926085, 0.383909, 0.391792, 0.372398, 0.3531025,
0.414441, 0.404335, 0.3682095, 0.359976, 0.376681, 0.4173705,
0.3492685, 0.397057, 0.3940605, 0.398825, 0.3707115, 0.400228,
0.3946595, 0.4278775, 0.384037, 0.43577)), .Names = c("Subject",
"A", "B", "C", "D", "Frontal_FA"), class = "data.frame", row.names = c(NA,
-151L))
Here is the code that I am running
lmer fit
FA <- lmer(Frontal_FA ~ poly(C) + A + B + D + (poly(C)||Subject), data = df)
plot lmer fit
sjp.lmer(FA)
Thanks for your help.
sjp.lmer, by default, plots the random effects of a model. However, it plots random effects (BLUPs) with confidence intervals, using the arm:se.ranef function. This function causes the first error message you get:
arm::se.ranef(FA)
> Error in array(NA, c(J, K)) : 'dims' cannot be of length 0
Then, the se.ranef functions calls the lme4::ranef function with argument condVar = TRUE, which is not yet implemented for specific conditions (like yours) in lme4. Hence you get the additional warning
In ranef.merMod(object, condVar = TRUE) :
conditional variances not currently available via ranef when there are multiple terms per factor
If you are especially interested in plotting the random effects, you could use the lme4-implemented dotplot-function:
lattice::dotplot(ranef(FA))
If you are interested in any other plot type (fixed effects, marginal effects, predictions, ...), see ?sjp.lmer or some examples at his page.
Edit
If you don't mind installing from GitHub (devtools::install_github("sjPlot/devel"), I have committed a small update, so you can use show.ci = FALSE to avoid computing confidence intervals for random effects:
sjp.lmer(FA, type = "re", show.ci = F, sort.est = "(Intercept)")