Select top row melted data after sorting by value - r

I have the following melted data:
dat.melt <- structure(list(CellTypes = structure(c(62L, 35L, 73L, 45L, 14L,
22L, 46L, 13L, 68L, 21L, 1L, 10L, 64L, 24L, 72L, 58L, 51L, 9L,
60L, 37L, 34L, 49L, 33L, 2L, 50L, 32L, 11L, 52L, 44L, 66L, 8L,
5L, 47L, 59L, 53L, 7L, 6L, 77L, 75L, 17L, 27L, 61L, 20L, 18L,
19L, 16L, 54L, 15L, 41L, 3L, 63L, 48L, 57L, 43L, 70L, 40L, 12L,
76L, 74L, 29L, 28L, 25L, 30L, 42L, 39L, 56L, 4L, 67L, 71L, 31L,
36L, 23L, 38L, 69L, 55L, 26L, 65L, 62L, 35L, 73L, 45L, 14L, 22L,
46L, 13L, 68L, 21L, 1L, 10L, 64L, 24L, 72L, 58L, 51L, 9L, 60L,
37L, 34L, 49L, 33L, 2L, 50L, 32L, 11L, 52L, 44L, 66L, 8L, 5L,
47L, 59L, 53L, 7L, 6L, 77L, 75L, 17L, 27L, 61L, 20L, 18L, 19L,
16L, 54L, 15L, 41L, 3L, 63L, 48L, 57L, 43L, 70L, 40L, 12L, 76L,
74L, 29L, 28L, 25L, 30L, 42L, 39L, 56L, 4L, 67L, 71L, 31L, 36L,
23L, 38L, 69L, 55L, 26L, 65L), .Label = c("3T3-L1", "Adipose Brown",
"Adipose White", "Adrenal Gland", "B Cells (GL7 neg; Alum)",
"B Cells (GL7 neg; KLH)", "B Cells (GL7 pos; Alum)", "B Cells (GL7 pos; KLH)",
"B Cells Marginal Zone", "B220+ Dend. Cells", "BA/F3", "Bladder",
"Bone", "Bone Marrow", "C2C12", "CD4+ SP Thymoctyes", "CD4+ T cells",
"CD4+/CD8+ DP Thymocytes", "CD8+ SP Thymocytes", "CD8+ T cells",
"CD8a+ Dend. Cells Lymphoid", "CD8a+ Dend. Cells Myeloid", "Ciliary Bodies",
"Common Myeloid Progenitor", "Cornea", "Dorsal Root Ganglia",
"Embryonic Fibroblasts", "Embryonic Stem Line Bruce4 P13", "Embryonic Stem Line V26 2 P16",
"Epidermis", "Eyecup", "Follicular B Cells", "Foxp3+ Tcells",
"Granulo Monoprogenitor", "Granulocytes", "Heart", "Hematopoietic Stem Cells",
"Iris", "Kidney", "Lacrimal Gland", "Large Intestine", "Lens",
"Liver", "Lung", "Lymph Nodes", "Macrophage Peri ", "Mammary Gland",
"Mammary Gland Non-Lactating", "Mast Cells", "Mast Cells IgE",
"Mast Cells IgE 1hr", "Mast Cells IgE 6hr", "Megaerythrocyte Progenitor",
"mIMCD-3 Cells", "MIN6 cells", "Neuro2a Neuroblastoma Cells",
"NIH 3T3", "NK Cells", "Osteoblast Day14", "Osteoblast Day21",
"Osteoblast Day5", "Osteoclasts", "Ovary", "Pancreas", "Pituitary",
"Placenta", "Prostate", "RAW 264.7 Cells", "Retinal Pigment Epithelium",
"Salivary Gland", "Skeletal Muscle", "Small Intestine", "Spleen",
"Stem Cells C3H/10T1/2", "Stomach", "Umbilical Cord", "Uterus"
), class = "factor"), variable = 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, 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, 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, 2L, 2L, 2L), .Label = c("LPS_IV_SP", "MPL_IV_SP"), class = "factor"),
value = c(3.647, 33.629, 17.838, 33.917, 29.66, 31.694, 32.603,
24.152, 19.969, 24.012, 40.101, 12.682, 0.323, 12.846, 5.087,
11.707, 16.682, 7.71, 22.472, 10.21, 10.109, 12.643, 12.623,
1.48, 13.075, 5.042, 12.19, 11.691, 15.24, 17.073, 5.854,
5.188, 11.983, 18.679, 6.406, 4.474, 5.445, 8.144, 0.739,
3.652, 14.232, 17.1, 2.603, 1.762, 1.993, 3.475, 10.305,
7.457, 1.189, 2.895, 4.181, 3.06, 5.885, 3.063, 2.532, 1.662,
3.86, 5.094, 5.916, 4.553, 3.703, 2.546, 0.764, 0.597, 1.39,
2.933, 0.665, 0.121, 0.257, 0.764, 0.196, 0.208, 0.232, 0.001,
0.004, 0.035, 0.036, 56.156, 53.485, 48.206, 45.975, 41.067,
40.581, 38.155, 33.009, 29.468, 29.219, 27.945, 19.165, 15.985,
15.682, 15.077, 14.72, 13.856, 13.576, 12.914, 12.77, 12.577,
12.526, 11.05, 10.532, 10.008, 9.942, 9.238, 8.67, 8.237,
7.938, 7.819, 7.55, 7.349, 7.217, 7.146, 6.158, 5.852, 5.368,
5.328, 5.126, 4.887, 4.767, 4.24, 3.858, 3.816, 3.676, 3.318,
3.118, 2.459, 2.269, 2.266, 2.201, 1.467, 1.418, 1.368, 1.267,
1.077, 1.022, 0.835, 0.667, 0.655, 0.609, 0.53, 0.452, 0.24,
0.239, 0.211, 0.124, 0.084, 0.05, 0.028, 0.024, 0.016, 0.007,
0.006, 0.003, 0.002)), row.names = c(NA, -154L), .Names = c("CellTypes",
"variable", "value"), class = "data.frame")
It looks like this:
> tail(dat.melt,n=5L)
CellTypes variable value
150 Iris MPL_IV_SP 0.016
151 Retinal Pigment Epithelium MPL_IV_SP 0.007
152 MIN6 cells MPL_IV_SP 0.006
153 Dorsal Root Ganglia MPL_IV_SP 0.003
154 Pituitary MPL_IV_SP 0.002
> head(dat.melt,n=5L)
CellTypes variable value
1 Osteoclasts LPS_IV_SP 3.647
2 Granulocytes LPS_IV_SP 33.629
3 Spleen LPS_IV_SP 17.838
4 Lymph Nodes LPS_IV_SP 33.917
5 Bone Marrow LPS_IV_SP 29.660
>
For each variable MPL_IV_SP and LPS_IV_SP I would like to select top-5 rows ('cell type') sorted descending by values. How can I do that?

You can do using data.table package as well. Below is the code:
library(data.table)
dat.melt <- data.table(dat.melt)
dat.melt[, .SD[1:5], by=variable]
The advantage of data.table is that it is faster than data.frame.

We can use top_n
library(dplyr)
dat.melt %>%
group_by(variable) %>%
top_n(5, value)
NOTE: In the other answer, there is no sorting done. But, I can understand the biased voting.

Related

Multi-level Model in R missing one predictor [duplicate]

I am using the lme4 package and running a linear mixed model but I am confused but the output and expect that I am encountering an error even though I do not get an error message.
The basic issue is when I fit a model like lmer(Values ~ stimuli + timeperiod + scale(poly(distance.code,3,raw=FALSE))*habitat + wind.speed + (1|location.code), data=df, REML=FALSE)
and then look at the results using something like summary I see all the model fixed (and random) effects as I would expect however the habitat effect is always displayed as habitatForest. Like this:
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 996.63179 8.16633 31.22730 122.042 < 2e-16 ***
stimuliBHCO -3.57541 1.28877 8750.89273 -2.774 0.005544 **
stimuliCOHA -10.17037 1.29546 8754.17156 -7.851 4.62e-15 ***
timeperiod 0.19900 0.05516 8744.95307 3.608 0.000310 ***
scale(poly(distance.code, 3, raw = FALSE))1 -3.87613 0.71431 8745.70773 -5.426 5.90e-08 ***
scale(poly(distance.code, 3, raw = FALSE))2 2.65854 0.71463 8745.19353 3.720 0.000200 ***
scale(poly(distance.code, 3, raw = FALSE))3 4.66340 0.72262 8745.67948 6.453 1.15e-10 ***
habitatForest -68.82430 11.83009 29.95226 -5.818 2.34e-06 ***
wind.speed -0.35853 0.07631 8403.15191 -4.698 2.66e-06 ***
scale(poly(distance.code, 3, raw = FALSE))1:habitatForest 2.89860 1.03891 8745.46534 2.790 0.005282 **
scale(poly(distance.code, 3, raw = FALSE))2:habitatForest -3.49758 1.03829 8745.11371 -3.369 0.000759 ***
scale(poly(distance.code, 3, raw = FALSE))3:habitatForest -4.67300 1.03913 8745.30579 -4.497 6.98e-06 ***
---
This is happening even though there are two levels of habitat (Forest and Grassland)
at first, I thought this might be because my model had an interaction term but it happens when I try a simpler model like lmer(Values ~ stimuli + timeperiod + distance.code + habitat + wind.speed + (1|location.code), data=ex.df, REML=FALSE)
Why would it say "habitatForest" and not just "habitat" or if it were going to include a factor by name why not say "habitatForest" and "habitatGrassland"?
A quick look at the expected output from this function here: https://rpubs.com/palday/mixed-interactions or here: https://ase.tufts.edu/bugs/guide/assets/mixed_model_guide.html (among others)
shows that the out put that I am getting is not what is expected or normal.
Other output I have seen simply have factors with two levels, like mine, as a single line (eg habitat).
Here is a portion of the data I am using. I used dput and subseting to produce this. I couldn't figure out how to make the data set smaller and still reproduce the error so I apologize if this is too large. The data set that it comes from is MUCH bigger! (also please let me know if I have used dput incorrectly.(Still new to R and stackoverflow)
structure(list(location.code = structure(c(1L, 1L, 1L, 2L, 2L,
2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L,
2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L,
2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L,
2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2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, 1L, 1L, 1L, 2L,
2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L,
1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L,
1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L,
2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L), .Label = c("Grassland",
"Forest"), class = "factor"), distance.code = c(0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L,
30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L,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0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9, 65,
65, 65, 65, 65, 55, 55, 55, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9, 65, 65, 65, 65, 65, 55, 55,
55, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9,
0.9, 0.9, 65, 65, 65, 65, 65, 55, 55, 55, 50, 50, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9, 65, 65, 65, 65,
65, 55, 55, 55, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0.9, 0.9, 0.9, 65, 65, 65, 65, 65, 55, 55, 55, 50, 50,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9, 65,
65, 65, 65, 65, 55, 55, 55, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9, 65, 65, 65, 65, 65, 55, 55,
55, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9,
0.9, 0.9, 65, 65, 65, 65, 65, 55, 55, 55, 50, 50, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9, 65, 65, 65, 65,
65, 55, 55, 55, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0.9, 0.9, 0.9, 65, 65, 65, 65, 65, 55, 55, 55, 50, 50,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9, 65,
65, 65, 65, 65, 55, 55, 55, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9), timeperiod = c(6L, 6L, 6L,
6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 9L,
9L, 9L, 9L, 9L, 9L, 11L, 11L, 11L, 11L, 11L, 11L, 13L, 13L, 13L,
13L, 13L, 13L, 15L, 15L, 15L, 15L, 15L, 15L, 17L, 17L, 17L, 17L,
17L, 17L, 19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L,
20L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L,
23L, 23L, 23L, 23L, 23L, 23L, 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, 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, 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, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 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, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 24L), Values = c(910.721895276374, 922.652711611841,
926.219785713456, 1030.28919690464, 1121.98321368732, 992.741416151102,
910.878353926705, 920.201901019659, 922.134996121665, 992.059286431433,
1042.05240231832, 1018.99804250179, 911.976009884021, 918.215389274037,
931.037495260958, 981.032280455129, 983.700699744073, 989.716307418049,
911.476759038955, 918.554393750162, 920.391856289719, 994.583211567691,
1006.58290843226, 1005.52479816571, 908.665064025178, 917.940176257067,
922.746174825048, 986.419049170517, 1042.41789735969, 1082.89658057517,
916.02310296116, 918.254868924698, 931.01648294424, 982.154409713674,
1008.54477137219, 996.577798511801, 912.914857937818, 916.937508116615,
920.933077377339, 997.669828575817, 1007.44452218386, 1151.25894192961,
909.463528658898, 915.293665875472, 921.917039784441, 983.866984633392,
1002.04551764872, 986.791628665069, 907.695668282537, 917.845214744473,
932.330755620455, 972.609449456089, 1155.55960936774, 1083.40557091613,
909.903267624225, 914.846316952797, 921.279328283221, 1000.3672969178,
1021.78461788922, 1011.40975353271, 915.037273600535, 914.099859036178,
924.116937361394, 994.428182266452, 1123.09745015276, 1004.1485272116,
914.431649376896, 915.27037594587, 929.411251949862, 974.273124973661,
1145.99211507205, 1013.58184367388, 913.467056616881, 920.213007520924,
919.794369158301, 983.816025282468, 1103.11322201674, 974.792027063404,
910.532609655114, 917.616832229923, 923.462599912213, 1015.24811721269,
1070.61183211249, 1016.57332551186, 910.196695694198, 923.403802532832,
905.400995326023, 1036.98011238981, 963.147077473505, 916.899569521736,
931.240844862156, 919.11781354823, 995.408916523572, 960.825305234446,
1026.22960551445, 1000.13773127026, 962.347584090332, 904.090295814044,
908.836747102913, 928.867625382891, 918.100799763641, 906.282906701285,
913.146312873635, 977.094140033575, 972.599778534534, 964.658406857446,
921.91272768213, 910.507770576621, 942.269786765654, 1014.34022271036,
1128.29327664605, 1043.1365958913, 919.185972424773, 925.486310755197,
908.769520270226, 1030.20866627018, 956.104935565803, 922.01947330213,
934.451182538208, 928.626906337293, 986.326936258622, 1003.40797963907,
1021.91264348048, 995.68658929192, 993.102343807935, 901.633626404701,
908.255562868123, 922.840049924103, 917.012733437446, 907.541530752433,
915.050696506642, 983.542956895186, 972.236377246083, 965.082329354352,
918.337944633569, 910.137012141557, 952.89462134025, 977.420371016686,
1154.17994731565, 1022.82998099991, 927.061613377597, 926.745527716988,
908.284054932259, 966.157586219165, 974.986841619676, 916.559494755925,
935.817296050643, 918.835719171662, 1023.62078549133, 1009.23121097376,
1005.81651905991, 981.715747809821, 953.127134375762, 902.809201411559,
907.462229880533, 921.595454423298, 919.198277947855, 904.969515265664,
913.438353334218, 974.889830301362, 970.58615968713, 963.029605541189,
915.889893279581, 908.147726780027, 942.742415528349, 979.939535179807,
1153.51966568673, 1020.93502990084, 916.246150801212, 936.016759720656,
914.4488779132, 962.397352323664, 986.957848140285, 985.364195731404,
932.548910038465, 917.363220594089, 1085.89850605988, 1031.66330597084,
1005.64983154588, 991.988118229379, 975.384741587994, 902.60240793926,
907.989086075871, 923.287310593779, 912.878571722023, 904.107623756648,
905.563259817979, 991.530368160932, 975.190212414434, 965.951810135591,
915.334621878897, 910.857441830446, 936.093336975328, 972.074491630181,
1106.77459226532, 993.45400883741, 951.911391767329, 927.688604859773,
915.194279622847, 971.414103170297, 956.138106650696, 965.458656222347,
944.097918792458, 947.157460200658, 1029.14870726558, 992.151638322899,
954.129642526236, 981.48182339388, 968.10870393618, 906.941701681267,
917.956716926981, 923.05649603805, 934.459432014683, 922.801034508827,
920.724850575215, 981.478432929603, 1012.67364507927, 966.471299899978,
912.640460101352, 906.34455384334, 923.738349342148, 970.987788560016,
1210.42940542072, 975.753397539076, 911.747488522664, 928.34872697947,
910.852487444859, 982.304620375747, 1028.52794775628, 913.408967803895,
934.334726415048, 916.354017093653, 1036.08727658415, 974.408618327141,
1004.71633485176, 995.142763465394, 987.00017276687, 906.86826042139,
915.355833226192, 930.395950341189, 911.742114273539, 905.725754800821,
912.194776217353, 979.488696998854, 998.766511802223, 968.436523426865,
916.299279627464, 907.645161223541, 925.30056793674, 978.067851389738,
1142.91274685359, 1001.53234105611, 916.842758017232, 924.907983103717,
922.470305986631, 992.855613565408, 955.757560902304, 929.20232030375,
943.535934437766, 923.58180450271, 1035.68330820385, 962.09501965608,
1035.71434011945, 999.021624049638, 1037.74929152155, 904.65540329816,
907.898446182233, 915.586965865012, 912.540978342886, 904.648950841522,
910.146698786639, 970.655222414677, 969.045225438776, 961.588678057607,
922.252864714149, 904.866433981365, 921.496292021655, 971.871605044557,
1075.02261709497, 1018.63215987506, 925.837889075039, 937.313874872585,
919.393974179406, 984.865480173384, 998.38173566307, 923.591922218561,
935.764591123357, 914.144404904734, 1064.07484543951, 1009.55385037395,
1003.07982307794, 1019.96770677478, 1023.43370663799, 1075.23648079772,
918.40638740207, 930.381596850856, 911.431923384541, 908.158538518039,
913.917742396318, 972.975539521988, 969.261073622988, 966.900828461146,
912.922987528198, 906.204515258546, 917.349668426986, 965.167090686302,
1033.80724280751, 1019.96323854891, 923.466492256566, 923.247012056591,
911.896005256495, 983.55323734271, 987.195939413696, 948.013535459932,
946.283282150572, 946.996017019961, 1018.55920835599, 983.790383328001,
1044.1241515621, 1025.44806232873, 1013.07125415424, 936.438305947314,
914.845558304809, 919.627558974215, 912.08306092659, 905.506361055768,
925.863591354922, 980.84672626416, 1034.50509678374, 999.432501149952,
914.013428128551, 903.385280147577, 914.982720974316, 987.521728519027,
1026.27371444455, 1003.6659923071, 936.860089156893, 922.376363123921,
909.301601087255, 949.125313633903, 983.891808931205, 928.514242776379,
931.528375870523, 934.663002673557, 983.163630767407, 958.520107194186,
1028.60002280789, 1027.26325499148, 1026.49504978946, 904.375575893285,
912.523756638651, 919.179127414697, 913.641605762865, 905.043751380124,
918.017612913947, 966.955539088111, 1083.03489991906, 982.779995986195,
913.039005945342, 901.569366267589, 924.344189118069, 986.456388413752,
1053.70140237407, 1012.4655295529, 918.216939699045, 924.376017342816,
912.32335834515, 962.020663167786, 968.751653626515, 923.781426521514,
934.702280304594, 945.072040784087, 972.171048113648, 980.160384144599,
1029.12422797868, 1045.60159108586, 1069.71097019503, 904.989955563463,
911.137606736246, 913.282276988181, 911.62618760385, 904.022814213797,
917.471586361699, 969.239603596626, 1092.64417075988, 995.598256664543,
911.352468377778, 903.930535551161, 934.598647851096, 968.529282541217,
1014.22774561852, 992.123001836286, 955.008951781314, 928.638327604534,
930.057703919378, 979.117036821698, 961.435436233545, 927.430280788518,
933.188144311621, 938.849731346915, 975.793676023678, 984.576641002029,
953.148108722352, 1025.14511979605, 987.536969976085, 904.469118373204,
919.724696002539, 921.494112907094, 933.99081130992, 910.883621211755,
919.830805764804, 973.217375644616, 1097.82345512272, 955.321702833728,
914.950887550846, 907.869650845588, 930.21996042144, 988.365255219924,
1072.82537699421, 941.505101156388, 912.978755227237, 924.00211814663,
926.073413421038, 975.963524978988, 966.347030574186, 927.813889117707,
938.87057229942, 937.20592642584, 1049.77079831674, 993.369595475566,
941.988672609005, 1036.52896057029, 1025.79874961742, 909.778142305324,
926.05520033663, 930.593948095488, 927.731349235947, 909.012240248148,
918.177023640935, 965.119279536339, 1100.04708794994, 950.187396378294,
913.95540287581, 908.285198789598, 928.585928045517, 1009.11449170465,
1048.43494462072, 1070.81842375631, 919.615682872958, 927.180388372158,
911.229890874478, 979.675336133848, 975.987038362197, 936.015685237366,
944.935422587313, 934.084922337254, 1065.1158215132, 960.558846324124,
954.324007605299, 1036.19891812821, 1000.52619841385, 904.622130948163,
911.66456482634, 952.40730926852, 925.617846758624, 907.103270618455,
921.775155162068, 962.660086144894, 1089.5423829539, 976.343009650736,
917.002530477079, 905.207509685187, 920.30422426818, 985.37894037379,
1032.27384329955, 974.803996932782)), class = "data.frame", row.names = c(85L,
86L, 87L, 89L, 90L, 91L, 99L, 100L, 101L, 103L, 104L, 105L, 113L,
114L, 115L, 117L, 118L, 119L, 127L, 128L, 129L, 131L, 132L, 133L,
141L, 142L, 143L, 145L, 146L, 147L, 155L, 156L, 157L, 159L, 160L,
161L, 169L, 170L, 171L, 173L, 174L, 175L, 183L, 184L, 185L, 187L,
188L, 189L, 197L, 198L, 199L, 201L, 202L, 203L, 211L, 212L, 213L,
215L, 216L, 217L, 225L, 226L, 227L, 229L, 230L, 231L, 239L, 240L,
241L, 243L, 244L, 245L, 253L, 254L, 255L, 257L, 258L, 259L, 267L,
268L, 269L, 271L, 272L, 273L, 615L, 616L, 617L, 619L, 620L, 622L,
623L, 624L, 626L, 627L, 629L, 630L, 631L, 640L, 641L, 642L, 643L,
644L, 645L, 647L, 648L, 649L, 651L, 652L, 653L, 655L, 656L, 657L,
659L, 660L, 661L, 663L, 664L, 666L, 667L, 668L, 670L, 671L, 673L,
674L, 675L, 684L, 685L, 686L, 687L, 688L, 689L, 691L, 692L, 693L,
695L, 696L, 697L, 699L, 700L, 701L, 703L, 704L, 705L, 707L, 708L,
710L, 711L, 712L, 714L, 715L, 717L, 718L, 719L, 728L, 729L, 730L,
731L, 732L, 733L, 735L, 736L, 737L, 739L, 740L, 741L, 743L, 744L,
745L, 747L, 748L, 749L, 751L, 752L, 754L, 755L, 756L, 758L, 759L,
761L, 762L, 763L, 772L, 773L, 774L, 775L, 776L, 777L, 779L, 780L,
781L, 783L, 784L, 785L, 787L, 788L, 789L, 791L, 792L, 793L, 795L,
796L, 798L, 799L, 800L, 802L, 803L, 805L, 806L, 807L, 816L, 817L,
818L, 819L, 820L, 821L, 823L, 824L, 825L, 827L, 828L, 829L, 831L,
832L, 833L, 835L, 836L, 837L, 839L, 840L, 842L, 843L, 844L, 846L,
847L, 849L, 850L, 851L, 860L, 861L, 862L, 863L, 864L, 865L, 867L,
868L, 869L, 871L, 872L, 873L, 875L, 876L, 877L, 879L, 880L, 881L,
883L, 884L, 886L, 887L, 888L, 890L, 891L, 893L, 894L, 895L, 904L,
905L, 906L, 907L, 908L, 909L, 911L, 912L, 913L, 915L, 916L, 917L,
919L, 920L, 921L, 923L, 924L, 925L, 927L, 928L, 930L, 931L, 932L,
934L, 935L, 937L, 938L, 939L, 948L, 949L, 950L, 951L, 952L, 953L,
955L, 956L, 957L, 959L, 960L, 961L, 963L, 964L, 965L, 967L, 968L,
969L, 971L, 972L, 974L, 975L, 976L, 978L, 979L, 981L, 982L, 983L,
992L, 993L, 994L, 995L, 996L, 997L, 999L, 1000L, 1001L, 1003L,
1004L, 1005L, 1007L, 1008L, 1009L, 1011L, 1012L, 1013L, 1015L,
1016L, 1018L, 1019L, 1020L, 1022L, 1023L, 1025L, 1026L, 1027L,
1036L, 1037L, 1038L, 1039L, 1040L, 1041L, 1043L, 1044L, 1045L,
1047L, 1048L, 1049L, 1051L, 1052L, 1053L, 1055L, 1056L, 1057L,
1059L, 1060L, 1062L, 1063L, 1064L, 1066L, 1067L, 1069L, 1070L,
1071L, 1080L, 1081L, 1082L, 1083L, 1084L, 1085L, 1087L, 1088L,
1089L, 1091L, 1092L, 1093L, 1095L, 1096L, 1097L, 1099L, 1100L,
1101L, 1103L, 1104L, 1106L, 1107L, 1108L, 1110L, 1111L, 1113L,
1114L, 1115L, 1124L, 1125L, 1126L, 1127L, 1128L, 1129L, 1131L,
1132L, 1133L, 1135L, 1136L, 1137L, 1139L, 1140L, 1141L, 1143L,
1144L, 1145L, 1147L, 1148L, 1150L, 1151L, 1152L, 1154L, 1155L,
1157L, 1158L, 1159L, 1168L, 1169L, 1170L, 1171L, 1172L, 1173L,
1175L, 1176L, 1177L, 1179L, 1180L, 1181L, 1183L, 1184L, 1185L,
1187L, 1188L, 1189L, 1191L, 1192L, 1194L, 1195L, 1196L, 1198L,
1199L, 1201L, 1202L, 1203L, 1212L, 1213L, 1214L, 1215L, 1216L,
1217L, 1219L, 1220L, 1221L, 1223L, 1224L, 1225L, 1227L, 1228L,
1229L))
Here is the code (I think) that would be needed to fit the model and see the summary after the above data is loaded:
library(lme4)
library(lmerTest)
fit1 <- lmer(Values ~ stimuli + timeperiod + scale(poly(distance.code,3,raw=FALSE))*habitat + wind.speed + (1|location.code), data=df, REML=FALSE)
fit2 <- lmer(Values ~ stimuli + timeperiod + distance.code + habitat + wind.speed + (1|location.code), data=ex.df, REML=FALSE)
summary(fit1)
#or
summary(fit2)
I think this has to do with my data structure and the programming but if it is actually something to do with the stats I am happy to take this post down and re-post over at the stats stackexchange.
Thanks for any help!
note: although your question is about the lmer() function, this answer also applies to lm() and other R functions that fit linear models.
The way that coefficient estimates from linear models in R are presented can be confusing. To understand what's going on, you need to understand how R fits linear models when the predictor is a factor variable.
Coefficients on factor variables in R linear models
Before we look at factor variables, let's look at the more straightforward situation where the predictor is continuous. In your example dataset, one of the predictors is wind speed (continuous variable). The estimated coefficient is about -0.35. It's easy to interpret this: averaged across the other predictors, for every increase of 1 km/h in wind speed, your response value is predicted to decrease by 0.35.
But what about if the predictor is a factor? A categorical variable cannot increase or decrease by 1. Instead it can take several discrete values. So what the lmer() or lm() function does by default is automatically code your factor variable as a set of so-called "dummy variables." Dummy variables are binary (they can take values of 0 or 1). If the factor variable has n levels, you need n-1 dummy variables to encode it. The reference level or control group acts like an intercept.
In the case of your habitat variable, there are only 2 levels so you have only 1 dummy variable which will be 0 if habitat is not Forest and 1 if it is Forest. Now we can interpret the coefficient estimate of -68.8: the average value of your response is expected to be 68.8 less in forest habitat relative to the reference level of grassland habitat. You don't need a second dummy variable for grassland because you only need to estimate the one coefficient to compare the two habitats.
If you had a third habitat, let's say wetland, there would be a second dummy variable that would be 0 if not wetland and 1 if wetland. The coefficient estimate there would be the expected difference between the value of the response variable in wetland habitat compared to grassland habitat. Grassland will be the reference level for all the coefficients.
Default setting of reference level
Now to directly address your question of why habitatForest is the coefficient name.
Because by default no reference level or control group is specified, the first one in the factor level ordering becomes the reference level to which all other levels are compared. Then the coefficients are named by appending the variable's name to the name of the level being compared to the reference level. Your factor is ordered with grassland first and forest second. So the coefficient is the effect of the habitat being forest habitat, compared to the reference level, which is grassland in this case. If you switched the habitat factor level ordering, Forest would be the reference level and you would get habitatGrassland as the coefficient instead. (Note that default factor level ordering is alphabetical, so without specifically ordering the factor levels as you seem to have done, Forest would be the reference level by default).
Incidentally, the two links you give in your question (guides to mixed models from Phillip Alday and Tufts) do in fact have the same kind of output as you are getting. For example in Alday's tutorial, the factor recipe has 3 levels: A, B, and C. There are two coefficients in the fixed effects summary, recipeB and recipeC, just as you would expect from dummy coding using A as reference level. You may be confusing the fixed effects summary with the ANOVA table presented elsewhere in his post. The ANOVA table does only have a single line for recipe which gives you the ratio of variance due to recipe (across all its levels) and the total variance. So that would only be one ratio regardless of how many levels recipe has.
Further reading
This is not the place for a full discussion of contrast coding in linear models in R. The dummy coding (which you may also see called one-hot encoding) I described here is just one way to do it. These resources may be helpful:
Documentation for the base R function contrasts()
description of different types of categorical variable coding in R from UCLA IDRE Stats
Marissa Barlaz' tutorial on R contrast coding

Why does the output of of a linear mixed model using lme4 show one level of a factor but not another?

I am using the lme4 package and running a linear mixed model but I am confused but the output and expect that I am encountering an error even though I do not get an error message.
The basic issue is when I fit a model like lmer(Values ~ stimuli + timeperiod + scale(poly(distance.code,3,raw=FALSE))*habitat + wind.speed + (1|location.code), data=df, REML=FALSE)
and then look at the results using something like summary I see all the model fixed (and random) effects as I would expect however the habitat effect is always displayed as habitatForest. Like this:
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 996.63179 8.16633 31.22730 122.042 < 2e-16 ***
stimuliBHCO -3.57541 1.28877 8750.89273 -2.774 0.005544 **
stimuliCOHA -10.17037 1.29546 8754.17156 -7.851 4.62e-15 ***
timeperiod 0.19900 0.05516 8744.95307 3.608 0.000310 ***
scale(poly(distance.code, 3, raw = FALSE))1 -3.87613 0.71431 8745.70773 -5.426 5.90e-08 ***
scale(poly(distance.code, 3, raw = FALSE))2 2.65854 0.71463 8745.19353 3.720 0.000200 ***
scale(poly(distance.code, 3, raw = FALSE))3 4.66340 0.72262 8745.67948 6.453 1.15e-10 ***
habitatForest -68.82430 11.83009 29.95226 -5.818 2.34e-06 ***
wind.speed -0.35853 0.07631 8403.15191 -4.698 2.66e-06 ***
scale(poly(distance.code, 3, raw = FALSE))1:habitatForest 2.89860 1.03891 8745.46534 2.790 0.005282 **
scale(poly(distance.code, 3, raw = FALSE))2:habitatForest -3.49758 1.03829 8745.11371 -3.369 0.000759 ***
scale(poly(distance.code, 3, raw = FALSE))3:habitatForest -4.67300 1.03913 8745.30579 -4.497 6.98e-06 ***
---
This is happening even though there are two levels of habitat (Forest and Grassland)
at first, I thought this might be because my model had an interaction term but it happens when I try a simpler model like lmer(Values ~ stimuli + timeperiod + distance.code + habitat + wind.speed + (1|location.code), data=ex.df, REML=FALSE)
Why would it say "habitatForest" and not just "habitat" or if it were going to include a factor by name why not say "habitatForest" and "habitatGrassland"?
A quick look at the expected output from this function here: https://rpubs.com/palday/mixed-interactions or here: https://ase.tufts.edu/bugs/guide/assets/mixed_model_guide.html (among others)
shows that the out put that I am getting is not what is expected or normal.
Other output I have seen simply have factors with two levels, like mine, as a single line (eg habitat).
Here is a portion of the data I am using. I used dput and subseting to produce this. I couldn't figure out how to make the data set smaller and still reproduce the error so I apologize if this is too large. The data set that it comes from is MUCH bigger! (also please let me know if I have used dput incorrectly.(Still new to R and stackoverflow)
structure(list(location.code = structure(c(1L, 1L, 1L, 2L, 2L,
2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L,
2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L,
2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L,
2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 4L, 4L, 4L, 3L, 3L, 3L, 3L,
3L, 3L, 4L, 4L, 4L, 3L, 3L, 3L, 4L, 4L, 4L, 1L, 1L, 1L, 2L, 2L,
1L, 1L, 1L, 2L, 2L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L,
4L, 3L, 3L, 3L, 4L, 4L, 4L, 1L, 1L, 1L, 2L, 2L, 1L, 1L,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2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L,
1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L,
2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L), .Label = c("Grassland",
"Forest"), class = "factor"), distance.code = c(0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L,
30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L,
60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L, 0L, 60L, 0L, 30L, 60L,
0L, 30L, 60L, 0L, 30L, 60L, 0L, 30L, 60L, 0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9, 0.9, 65, 65, 65, 65, 65, 55, 55, 55, 50, 50, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9, 65, 65, 65, 65,
65, 55, 55, 55, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0.9, 0.9, 0.9, 65, 65, 65, 65, 65, 55, 55, 55, 50, 50,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9, 65,
65, 65, 65, 65, 55, 55, 55, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9, 65, 65, 65, 65, 65, 55, 55,
55, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9,
0.9, 0.9, 65, 65, 65, 65, 65, 55, 55, 55, 50, 50, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9, 65, 65, 65, 65,
65, 55, 55, 55, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0.9, 0.9, 0.9, 65, 65, 65, 65, 65, 55, 55, 55, 50, 50,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9, 65,
65, 65, 65, 65, 55, 55, 55, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0.9, 0.9, 0.9), timeperiod = c(6L, 6L, 6L,
6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 9L,
9L, 9L, 9L, 9L, 9L, 11L, 11L, 11L, 11L, 11L, 11L, 13L, 13L, 13L,
13L, 13L, 13L, 15L, 15L, 15L, 15L, 15L, 15L, 17L, 17L, 17L, 17L,
17L, 17L, 19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L,
20L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L,
23L, 23L, 23L, 23L, 23L, 23L, 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, 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, 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, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 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, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 24L), Values = c(910.721895276374, 922.652711611841,
926.219785713456, 1030.28919690464, 1121.98321368732, 992.741416151102,
910.878353926705, 920.201901019659, 922.134996121665, 992.059286431433,
1042.05240231832, 1018.99804250179, 911.976009884021, 918.215389274037,
931.037495260958, 981.032280455129, 983.700699744073, 989.716307418049,
911.476759038955, 918.554393750162, 920.391856289719, 994.583211567691,
1006.58290843226, 1005.52479816571, 908.665064025178, 917.940176257067,
922.746174825048, 986.419049170517, 1042.41789735969, 1082.89658057517,
916.02310296116, 918.254868924698, 931.01648294424, 982.154409713674,
1008.54477137219, 996.577798511801, 912.914857937818, 916.937508116615,
920.933077377339, 997.669828575817, 1007.44452218386, 1151.25894192961,
909.463528658898, 915.293665875472, 921.917039784441, 983.866984633392,
1002.04551764872, 986.791628665069, 907.695668282537, 917.845214744473,
932.330755620455, 972.609449456089, 1155.55960936774, 1083.40557091613,
909.903267624225, 914.846316952797, 921.279328283221, 1000.3672969178,
1021.78461788922, 1011.40975353271, 915.037273600535, 914.099859036178,
924.116937361394, 994.428182266452, 1123.09745015276, 1004.1485272116,
914.431649376896, 915.27037594587, 929.411251949862, 974.273124973661,
1145.99211507205, 1013.58184367388, 913.467056616881, 920.213007520924,
919.794369158301, 983.816025282468, 1103.11322201674, 974.792027063404,
910.532609655114, 917.616832229923, 923.462599912213, 1015.24811721269,
1070.61183211249, 1016.57332551186, 910.196695694198, 923.403802532832,
905.400995326023, 1036.98011238981, 963.147077473505, 916.899569521736,
931.240844862156, 919.11781354823, 995.408916523572, 960.825305234446,
1026.22960551445, 1000.13773127026, 962.347584090332, 904.090295814044,
908.836747102913, 928.867625382891, 918.100799763641, 906.282906701285,
913.146312873635, 977.094140033575, 972.599778534534, 964.658406857446,
921.91272768213, 910.507770576621, 942.269786765654, 1014.34022271036,
1128.29327664605, 1043.1365958913, 919.185972424773, 925.486310755197,
908.769520270226, 1030.20866627018, 956.104935565803, 922.01947330213,
934.451182538208, 928.626906337293, 986.326936258622, 1003.40797963907,
1021.91264348048, 995.68658929192, 993.102343807935, 901.633626404701,
908.255562868123, 922.840049924103, 917.012733437446, 907.541530752433,
915.050696506642, 983.542956895186, 972.236377246083, 965.082329354352,
918.337944633569, 910.137012141557, 952.89462134025, 977.420371016686,
1154.17994731565, 1022.82998099991, 927.061613377597, 926.745527716988,
908.284054932259, 966.157586219165, 974.986841619676, 916.559494755925,
935.817296050643, 918.835719171662, 1023.62078549133, 1009.23121097376,
1005.81651905991, 981.715747809821, 953.127134375762, 902.809201411559,
907.462229880533, 921.595454423298, 919.198277947855, 904.969515265664,
913.438353334218, 974.889830301362, 970.58615968713, 963.029605541189,
915.889893279581, 908.147726780027, 942.742415528349, 979.939535179807,
1153.51966568673, 1020.93502990084, 916.246150801212, 936.016759720656,
914.4488779132, 962.397352323664, 986.957848140285, 985.364195731404,
932.548910038465, 917.363220594089, 1085.89850605988, 1031.66330597084,
1005.64983154588, 991.988118229379, 975.384741587994, 902.60240793926,
907.989086075871, 923.287310593779, 912.878571722023, 904.107623756648,
905.563259817979, 991.530368160932, 975.190212414434, 965.951810135591,
915.334621878897, 910.857441830446, 936.093336975328, 972.074491630181,
1106.77459226532, 993.45400883741, 951.911391767329, 927.688604859773,
915.194279622847, 971.414103170297, 956.138106650696, 965.458656222347,
944.097918792458, 947.157460200658, 1029.14870726558, 992.151638322899,
954.129642526236, 981.48182339388, 968.10870393618, 906.941701681267,
917.956716926981, 923.05649603805, 934.459432014683, 922.801034508827,
920.724850575215, 981.478432929603, 1012.67364507927, 966.471299899978,
912.640460101352, 906.34455384334, 923.738349342148, 970.987788560016,
1210.42940542072, 975.753397539076, 911.747488522664, 928.34872697947,
910.852487444859, 982.304620375747, 1028.52794775628, 913.408967803895,
934.334726415048, 916.354017093653, 1036.08727658415, 974.408618327141,
1004.71633485176, 995.142763465394, 987.00017276687, 906.86826042139,
915.355833226192, 930.395950341189, 911.742114273539, 905.725754800821,
912.194776217353, 979.488696998854, 998.766511802223, 968.436523426865,
916.299279627464, 907.645161223541, 925.30056793674, 978.067851389738,
1142.91274685359, 1001.53234105611, 916.842758017232, 924.907983103717,
922.470305986631, 992.855613565408, 955.757560902304, 929.20232030375,
943.535934437766, 923.58180450271, 1035.68330820385, 962.09501965608,
1035.71434011945, 999.021624049638, 1037.74929152155, 904.65540329816,
907.898446182233, 915.586965865012, 912.540978342886, 904.648950841522,
910.146698786639, 970.655222414677, 969.045225438776, 961.588678057607,
922.252864714149, 904.866433981365, 921.496292021655, 971.871605044557,
1075.02261709497, 1018.63215987506, 925.837889075039, 937.313874872585,
919.393974179406, 984.865480173384, 998.38173566307, 923.591922218561,
935.764591123357, 914.144404904734, 1064.07484543951, 1009.55385037395,
1003.07982307794, 1019.96770677478, 1023.43370663799, 1075.23648079772,
918.40638740207, 930.381596850856, 911.431923384541, 908.158538518039,
913.917742396318, 972.975539521988, 969.261073622988, 966.900828461146,
912.922987528198, 906.204515258546, 917.349668426986, 965.167090686302,
1033.80724280751, 1019.96323854891, 923.466492256566, 923.247012056591,
911.896005256495, 983.55323734271, 987.195939413696, 948.013535459932,
946.283282150572, 946.996017019961, 1018.55920835599, 983.790383328001,
1044.1241515621, 1025.44806232873, 1013.07125415424, 936.438305947314,
914.845558304809, 919.627558974215, 912.08306092659, 905.506361055768,
925.863591354922, 980.84672626416, 1034.50509678374, 999.432501149952,
914.013428128551, 903.385280147577, 914.982720974316, 987.521728519027,
1026.27371444455, 1003.6659923071, 936.860089156893, 922.376363123921,
909.301601087255, 949.125313633903, 983.891808931205, 928.514242776379,
931.528375870523, 934.663002673557, 983.163630767407, 958.520107194186,
1028.60002280789, 1027.26325499148, 1026.49504978946, 904.375575893285,
912.523756638651, 919.179127414697, 913.641605762865, 905.043751380124,
918.017612913947, 966.955539088111, 1083.03489991906, 982.779995986195,
913.039005945342, 901.569366267589, 924.344189118069, 986.456388413752,
1053.70140237407, 1012.4655295529, 918.216939699045, 924.376017342816,
912.32335834515, 962.020663167786, 968.751653626515, 923.781426521514,
934.702280304594, 945.072040784087, 972.171048113648, 980.160384144599,
1029.12422797868, 1045.60159108586, 1069.71097019503, 904.989955563463,
911.137606736246, 913.282276988181, 911.62618760385, 904.022814213797,
917.471586361699, 969.239603596626, 1092.64417075988, 995.598256664543,
911.352468377778, 903.930535551161, 934.598647851096, 968.529282541217,
1014.22774561852, 992.123001836286, 955.008951781314, 928.638327604534,
930.057703919378, 979.117036821698, 961.435436233545, 927.430280788518,
933.188144311621, 938.849731346915, 975.793676023678, 984.576641002029,
953.148108722352, 1025.14511979605, 987.536969976085, 904.469118373204,
919.724696002539, 921.494112907094, 933.99081130992, 910.883621211755,
919.830805764804, 973.217375644616, 1097.82345512272, 955.321702833728,
914.950887550846, 907.869650845588, 930.21996042144, 988.365255219924,
1072.82537699421, 941.505101156388, 912.978755227237, 924.00211814663,
926.073413421038, 975.963524978988, 966.347030574186, 927.813889117707,
938.87057229942, 937.20592642584, 1049.77079831674, 993.369595475566,
941.988672609005, 1036.52896057029, 1025.79874961742, 909.778142305324,
926.05520033663, 930.593948095488, 927.731349235947, 909.012240248148,
918.177023640935, 965.119279536339, 1100.04708794994, 950.187396378294,
913.95540287581, 908.285198789598, 928.585928045517, 1009.11449170465,
1048.43494462072, 1070.81842375631, 919.615682872958, 927.180388372158,
911.229890874478, 979.675336133848, 975.987038362197, 936.015685237366,
944.935422587313, 934.084922337254, 1065.1158215132, 960.558846324124,
954.324007605299, 1036.19891812821, 1000.52619841385, 904.622130948163,
911.66456482634, 952.40730926852, 925.617846758624, 907.103270618455,
921.775155162068, 962.660086144894, 1089.5423829539, 976.343009650736,
917.002530477079, 905.207509685187, 920.30422426818, 985.37894037379,
1032.27384329955, 974.803996932782)), class = "data.frame", row.names = c(85L,
86L, 87L, 89L, 90L, 91L, 99L, 100L, 101L, 103L, 104L, 105L, 113L,
114L, 115L, 117L, 118L, 119L, 127L, 128L, 129L, 131L, 132L, 133L,
141L, 142L, 143L, 145L, 146L, 147L, 155L, 156L, 157L, 159L, 160L,
161L, 169L, 170L, 171L, 173L, 174L, 175L, 183L, 184L, 185L, 187L,
188L, 189L, 197L, 198L, 199L, 201L, 202L, 203L, 211L, 212L, 213L,
215L, 216L, 217L, 225L, 226L, 227L, 229L, 230L, 231L, 239L, 240L,
241L, 243L, 244L, 245L, 253L, 254L, 255L, 257L, 258L, 259L, 267L,
268L, 269L, 271L, 272L, 273L, 615L, 616L, 617L, 619L, 620L, 622L,
623L, 624L, 626L, 627L, 629L, 630L, 631L, 640L, 641L, 642L, 643L,
644L, 645L, 647L, 648L, 649L, 651L, 652L, 653L, 655L, 656L, 657L,
659L, 660L, 661L, 663L, 664L, 666L, 667L, 668L, 670L, 671L, 673L,
674L, 675L, 684L, 685L, 686L, 687L, 688L, 689L, 691L, 692L, 693L,
695L, 696L, 697L, 699L, 700L, 701L, 703L, 704L, 705L, 707L, 708L,
710L, 711L, 712L, 714L, 715L, 717L, 718L, 719L, 728L, 729L, 730L,
731L, 732L, 733L, 735L, 736L, 737L, 739L, 740L, 741L, 743L, 744L,
745L, 747L, 748L, 749L, 751L, 752L, 754L, 755L, 756L, 758L, 759L,
761L, 762L, 763L, 772L, 773L, 774L, 775L, 776L, 777L, 779L, 780L,
781L, 783L, 784L, 785L, 787L, 788L, 789L, 791L, 792L, 793L, 795L,
796L, 798L, 799L, 800L, 802L, 803L, 805L, 806L, 807L, 816L, 817L,
818L, 819L, 820L, 821L, 823L, 824L, 825L, 827L, 828L, 829L, 831L,
832L, 833L, 835L, 836L, 837L, 839L, 840L, 842L, 843L, 844L, 846L,
847L, 849L, 850L, 851L, 860L, 861L, 862L, 863L, 864L, 865L, 867L,
868L, 869L, 871L, 872L, 873L, 875L, 876L, 877L, 879L, 880L, 881L,
883L, 884L, 886L, 887L, 888L, 890L, 891L, 893L, 894L, 895L, 904L,
905L, 906L, 907L, 908L, 909L, 911L, 912L, 913L, 915L, 916L, 917L,
919L, 920L, 921L, 923L, 924L, 925L, 927L, 928L, 930L, 931L, 932L,
934L, 935L, 937L, 938L, 939L, 948L, 949L, 950L, 951L, 952L, 953L,
955L, 956L, 957L, 959L, 960L, 961L, 963L, 964L, 965L, 967L, 968L,
969L, 971L, 972L, 974L, 975L, 976L, 978L, 979L, 981L, 982L, 983L,
992L, 993L, 994L, 995L, 996L, 997L, 999L, 1000L, 1001L, 1003L,
1004L, 1005L, 1007L, 1008L, 1009L, 1011L, 1012L, 1013L, 1015L,
1016L, 1018L, 1019L, 1020L, 1022L, 1023L, 1025L, 1026L, 1027L,
1036L, 1037L, 1038L, 1039L, 1040L, 1041L, 1043L, 1044L, 1045L,
1047L, 1048L, 1049L, 1051L, 1052L, 1053L, 1055L, 1056L, 1057L,
1059L, 1060L, 1062L, 1063L, 1064L, 1066L, 1067L, 1069L, 1070L,
1071L, 1080L, 1081L, 1082L, 1083L, 1084L, 1085L, 1087L, 1088L,
1089L, 1091L, 1092L, 1093L, 1095L, 1096L, 1097L, 1099L, 1100L,
1101L, 1103L, 1104L, 1106L, 1107L, 1108L, 1110L, 1111L, 1113L,
1114L, 1115L, 1124L, 1125L, 1126L, 1127L, 1128L, 1129L, 1131L,
1132L, 1133L, 1135L, 1136L, 1137L, 1139L, 1140L, 1141L, 1143L,
1144L, 1145L, 1147L, 1148L, 1150L, 1151L, 1152L, 1154L, 1155L,
1157L, 1158L, 1159L, 1168L, 1169L, 1170L, 1171L, 1172L, 1173L,
1175L, 1176L, 1177L, 1179L, 1180L, 1181L, 1183L, 1184L, 1185L,
1187L, 1188L, 1189L, 1191L, 1192L, 1194L, 1195L, 1196L, 1198L,
1199L, 1201L, 1202L, 1203L, 1212L, 1213L, 1214L, 1215L, 1216L,
1217L, 1219L, 1220L, 1221L, 1223L, 1224L, 1225L, 1227L, 1228L,
1229L))
Here is the code (I think) that would be needed to fit the model and see the summary after the above data is loaded:
library(lme4)
library(lmerTest)
fit1 <- lmer(Values ~ stimuli + timeperiod + scale(poly(distance.code,3,raw=FALSE))*habitat + wind.speed + (1|location.code), data=df, REML=FALSE)
fit2 <- lmer(Values ~ stimuli + timeperiod + distance.code + habitat + wind.speed + (1|location.code), data=ex.df, REML=FALSE)
summary(fit1)
#or
summary(fit2)
I think this has to do with my data structure and the programming but if it is actually something to do with the stats I am happy to take this post down and re-post over at the stats stackexchange.
Thanks for any help!
note: although your question is about the lmer() function, this answer also applies to lm() and other R functions that fit linear models.
The way that coefficient estimates from linear models in R are presented can be confusing. To understand what's going on, you need to understand how R fits linear models when the predictor is a factor variable.
Coefficients on factor variables in R linear models
Before we look at factor variables, let's look at the more straightforward situation where the predictor is continuous. In your example dataset, one of the predictors is wind speed (continuous variable). The estimated coefficient is about -0.35. It's easy to interpret this: averaged across the other predictors, for every increase of 1 km/h in wind speed, your response value is predicted to decrease by 0.35.
But what about if the predictor is a factor? A categorical variable cannot increase or decrease by 1. Instead it can take several discrete values. So what the lmer() or lm() function does by default is automatically code your factor variable as a set of so-called "dummy variables." Dummy variables are binary (they can take values of 0 or 1). If the factor variable has n levels, you need n-1 dummy variables to encode it. The reference level or control group acts like an intercept.
In the case of your habitat variable, there are only 2 levels so you have only 1 dummy variable which will be 0 if habitat is not Forest and 1 if it is Forest. Now we can interpret the coefficient estimate of -68.8: the average value of your response is expected to be 68.8 less in forest habitat relative to the reference level of grassland habitat. You don't need a second dummy variable for grassland because you only need to estimate the one coefficient to compare the two habitats.
If you had a third habitat, let's say wetland, there would be a second dummy variable that would be 0 if not wetland and 1 if wetland. The coefficient estimate there would be the expected difference between the value of the response variable in wetland habitat compared to grassland habitat. Grassland will be the reference level for all the coefficients.
Default setting of reference level
Now to directly address your question of why habitatForest is the coefficient name.
Because by default no reference level or control group is specified, the first one in the factor level ordering becomes the reference level to which all other levels are compared. Then the coefficients are named by appending the variable's name to the name of the level being compared to the reference level. Your factor is ordered with grassland first and forest second. So the coefficient is the effect of the habitat being forest habitat, compared to the reference level, which is grassland in this case. If you switched the habitat factor level ordering, Forest would be the reference level and you would get habitatGrassland as the coefficient instead. (Note that default factor level ordering is alphabetical, so without specifically ordering the factor levels as you seem to have done, Forest would be the reference level by default).
Incidentally, the two links you give in your question (guides to mixed models from Phillip Alday and Tufts) do in fact have the same kind of output as you are getting. For example in Alday's tutorial, the factor recipe has 3 levels: A, B, and C. There are two coefficients in the fixed effects summary, recipeB and recipeC, just as you would expect from dummy coding using A as reference level. You may be confusing the fixed effects summary with the ANOVA table presented elsewhere in his post. The ANOVA table does only have a single line for recipe which gives you the ratio of variance due to recipe (across all its levels) and the total variance. So that would only be one ratio regardless of how many levels recipe has.
Further reading
This is not the place for a full discussion of contrast coding in linear models in R. The dummy coding (which you may also see called one-hot encoding) I described here is just one way to do it. These resources may be helpful:
Documentation for the base R function contrasts()
description of different types of categorical variable coding in R from UCLA IDRE Stats
Marissa Barlaz' tutorial on R contrast coding

Gtsummary output with mgcv gam

I have the following data set:
structure(list(Age = c(83L, 26L, 26L, 20L, 20L, 77L, 32L, 21L,
15L, 75L, 27L, 81L, 81L, 15L, 24L, 16L, 35L, 27L, 30L, 31L, 24L,
24L, 31L, 79L, 30L, 19L, 20L, 42L, 62L, 83L, 79L, 18L, 26L, 66L,
23L, 83L, 77L, 80L, 57L, 42L, 32L, 76L, 85L, 29L, 65L, 79L, 9L,
34L, 20L, 16L, 34L, 22L, 19L, 23L, 25L, 14L, 53L, 28L, 79L, 22L,
22L, 21L, 82L, 81L, 16L, 19L, 77L, 15L, 18L, 15L, 78L, 24L, 16L,
14L, 29L, 18L, 50L, 17L, 43L, 8L, 14L, 85L, 31L, 20L, 30L, 23L,
78L, 29L, 6L, 61L, 14L, 22L, 10L, 83L, 15L, 13L, 15L, 15L, 29L,
8L, 9L, 15L, 8L, 9L, 15L, 9L, 34L, 8L, 9L, 9L, 16L, 8L, 25L,
21L, 23L, 13L, 56L, 10L, 7L, 27L, 8L, 8L, 8L, 8L, 80L, 80L, 6L,
15L, 42L, 25L, 23L, 21L, 8L, 11L, 43L, 69L, 34L, 34L, 14L, 12L,
10L, 22L, 78L, 16L, 76L, 12L, 10L, 16L, 6L, 13L, 66L, 11L, 26L,
12L, 16L, 13L, 24L, 76L, 10L, 65L, 20L, 13L, 25L, 14L, 12L, 15L,
43L, 51L, 27L, 15L, 24L, 34L, 63L, 17L, 15L, 9L, 12L, 17L, 82L,
75L, 24L, 44L, 69L, 11L, 10L, 12L, 10L, 10L, 70L, 54L, 45L, 42L,
84L, 54L, 23L, 23L, 14L, 81L, 17L, 42L, 44L, 16L, 15L, 43L, 45L,
50L, 53L, 23L, 53L, 49L, 13L, 69L, 14L, 65L, 14L, 13L, 22L, 67L,
59L, 52L, 54L, 44L, 78L, 62L, 69L, 10L, 63L, 57L, 22L, 12L, 62L,
9L, 82L, 53L, 54L, 66L, 49L, 63L, 51L, 9L, 45L, 49L, 77L, 49L,
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2L, 2L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L,
2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L,
2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L,
2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L,
2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 1L,
1L, 2L, 2L), .Label = c("Male", "Female"), class = "factor"),
mean_AD_scaled = c(3.15891332561581, -0.0551328105526693,
0.582747640515478, 1.94179165777054, 1.7064645993306, 2.37250948563045,
1.015775832203, 1.36189033704266, -1.05640048650493, 0.184814975542474,
-0.143366705302007, 1.81560178585347, 2.06325078470728, -0.473088628698217,
0.414641167726219, 0.199887349084444, -0.60620959209809,
-0.17879228399189, -1.03483709078065, -1.43497010225613,
-0.958595084469815, 1.0203965598582, -1.44731404613503, -1.17191867788498,
-2.02547709312595, -1.22395687266857, -1.09952727795348,
-1.0830246791849, 1.21072653232248, 1.69997357714829, 1.53648783201423,
0.208688735094353, 0.0862394522314924, 1.08662698958276,
-0.731299290763917, 2.29307697689102, -0.660008064083659,
-1.21425334459264, 1.10191939777498, -2.0957781638801, -1.14947514355972,
0.248845058764562, 2.6526135953958, 0.197907037232212, -0.222469162066061,
1.92880961340592, 1.23328008397287, -1.17288683034607, -0.308282675662673,
-1.02603570477074, -1.32647101621898, -1.58316343919798,
-0.0440210607151585, -0.388375288352846, -0.935491446193807,
-0.63789458173376, 0.454577456746182, -1.77391147749773,
0.709267564407921, 0.125735671950958, -0.821073428064989,
-0.126534054558056, 0.519597695894384, 0.188005477971066,
0.212319306823438, -1.45807374053215, 1.5856655763446, -1.25641198358011,
-0.910847565366061, -1.1191763722206, 0.25300371365424, -0.750772357310844,
0.37932560636146, -0.871791414947088, -1.92771569802088,
-1.1752191976387, 0.210449012296334, -0.347778895382139,
-0.132254955464496, 0.953616043508016, -0.0862677135627232,
0.838977990728951, -1.8993092246739, -0.0254281327692267,
0.298022803094927, -1.21559555595915, 0.0134079829994995,
-0.763094297724715, 0.334768589686298, -1.12568939786794,
-2.11786964276497, -0.0434709740895377, 0.388237009696492,
1.30050066962355, -0.260645173884043, -0.60620959209809,
1.05945271027717, -0.275717547426008, -0.0238878902174922,
0.496604074943496, 0.534009965485611, -0.692903244295693,
-0.566933407028871, 0.125625654625835, -0.518305749324122,
1.79381835547894, -0.790708646330802, -0.227860010997131,
0.347420582075538, 0.784189362817269, -0.660118081408782,
1.29962053102256, -0.561652575422924, -0.710395998990384,
-1.29315777017148, -0.457356151205503, -1.01756437073621,
0.146528946399368, -1.07136284272178, -1.42968927065019,
0.798601632408495, -0.799730066990963, -0.431348055546223,
0.569545561500617, 2.32168148142323, 0.472070211440872, 1.65145593676866,
-0.814142336582189, -0.544489872703603, -0.315433801795725,
0.382626126115175, -0.623812364117908, 0.216279930527897,
-0.606099574772967, -0.367207954999011, 0.719829227619811,
-0.749122097433987, 0.934693063586709, -0.79026857703031,
-0.371872689584264, 0.0769979969210905, -0.793899148759394,
1.50414273842782, 0.730280873506577, -0.290569886317732,
0.303743704001367, 0.390877425499463, -1.00359217044547,
-0.534918365417827, 0.325967203676389, 0.129036191704673,
0.34434009697207, -0.141386393449775, -0.363401355549725,
-0.395416397160769, -0.0235578382421178, -1.13583299524436,
1.16781977552417, -1.31890182425046, 0.139377820266317, 0.0160483988024708,
0.481311666751279, -1.05475022662807, 0.839858129329941,
0.652498624644007, -0.350199276534864, -0.262075399110649,
0.178543988010412, -1.13198238886502, -0.05117218684821,
-1.29678834190056, 0.429603523943066, 1.05098137624263, -0.956504755292464,
0.502765045150433, -0.81678275238516, -1.50263075720731,
-0.826684311646306, 2.40100397283753, 2.06633126981075, -0.470558230220369,
0.484942238480364, 0.822035322659877, 0.143888530596397,
0.384056351341786, -0.63580425255641, 0.358422314587926,
-0.372422776209885, 0.0607154328027556, -0.113221958218067,
1.02710761669075, -0.349649189909243, 2.27195365046724, -0.507634068787109,
-0.326105482332738, -1.0396778530861, 1.06484355920824, 1.32151397872221,
-0.185173288849074, -0.651888785489516, -0.171311105883464,
-0.104200537557911, -0.693673365571561, -1.26609350819101,
0.411230630647381, -0.929770545287362, -0.481009876107135,
0.386146680519137, 0.0482834750637615, -0.198265350538812,
0.790020281048832, 0.926001694901924, -1.08918564939184,
0.50298507980068, -0.0694350628187722, 1.04966116834114,
0.00878725534429612, 1.48742010500899, 0.750194009353997,
0.423772605711498, -0.596418050162068, -0.652636903300361,
-0.308942779613417, 0.314437388003408, 0.679562886624478,
-1.24312189070515, -0.432712270377761, 0.00427654501421597,
-0.197935298563442, 0.228821905592019, 1.06957430418856,
-1.61612462980509, 1.9499329398297, -0.263285589687014, 0.156430505660519,
-0.322254875953402, -0.451085163673446, -0.35526007349056,
0.10780284795577, 0.408700232169533, -0.957604928543701,
-1.05662052115517, 1.00345389178912, -0.238751726184391,
0.300003114947154, -0.397946795638617, -0.0802167606809086,
0.943714484246865, 1.10973062785877, 1.76279346979401, 1.62087112038423,
0.25533608094687, 0.226841593739787, 0.869672824438507, -1.44960240649761,
-0.450315042397579, -0.199629565370345, 0.29813282042005,
0.760425620590513, 1.87391096816911, -0.454275666102039,
-0.0559029318285365, -0.343048150401812, -1.01371376435687,
0.68880434193488, -0.29222014619459, 1.16132875334186, -1.95715633422403,
-0.534368278792206, -0.560112332871189, 1.84508642898666,
-1.19150176175703, -0.772203732244971, -0.3443683583033,
-1.45684154649076, -0.633823940704178, -1.77454957798344,
0.279539892474118, -0.875532004001301, 1.26001429397797,
-0.536590628759707, 2.1869102581465, 0.211109116247078, 0.130246382281038,
-0.355810160116181, -0.898085555651692, -0.429741802599415,
1.13360438741065, 1.61338994227581, 0.588688576072169, 0.454137387445685,
0.747113524250528, 0.460848444278238, -0.38177424884541,
-0.169990897981981, -0.747361820232001, -0.760123829946369,
0.208028631143609, -1.28748087619509, 2.33950428809329, -0.973029357526068,
-1.06091119683501, 0.917530360867389, -0.35041931118511,
-1.90613029883158, -1.15057531681095, 0.65348878057012, 0.43147381847017
)), row.names = c(NA, -308L), class = c("tbl_df", "tbl",
"data.frame"))
I am using this gam model:
m1 <- gam(mean_AD_scaled ~ s(Age, bs = 'ad', k = -1) + Sex + ti(Age, by = Sex, bs ='fs'),
data = DF,
method = 'REML',
family = gaussian)
Output:
Family: gaussian
Link function: identity
Formula:
mean_AD_scaled ~ s(Age, bs = "ad", k = -1) + Sex + ti(Age,
by = Sex, bs = "fs")
Parametric coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.04691 0.06976 0.672 0.502
SexFemale -0.12950 0.09428 -1.374 0.171
Approximate significance of smooth terms:
edf Ref.df F p-value
s(Age) 2.980 3.959 8.72 2.24e-06 ***
ti(Age):SexMale 2.391 2.873 23.47 < 2e-16 ***
ti(Age):SexFemale 1.000 1.000 43.40 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Rank: 48/49
R-sq.(adj) = 0.34 Deviance explained = 35.6%
-REML = 375.4 Scale est. = 0.63867 n = 308
But when I use gtsummary, I get a repeated value for each gender 'interaction':
tbl_regression(m1, tidy_fun = tidy_gam)
I see the following in a publication, which I am trying to replicate with gender and age:
I am not sure how to fix this. My goal is to print a table for a manuscript so any other gam-related information that can be added like edf and R^2.
I think you've found a bug in the handling of these types of interactions. While we work on a fix to the bug, this code should get you what you need. Thanks
library(gtsummary)
#> #BlackLivesMatter
library(mgcv)
packageVersion("gtsummary")
#> [1] ‘1.5.2’
m1 <- gam(marker ~ s(age, bs = 'ad', k = -1) + grade + ti(age, by = grade, bs ='fs'),
data = gtsummary::trial,
method = 'REML',
family = gaussian)
tbl_regression(m1, tidy_fun = gtsummary::tidy_gam) %>%
modify_table_body(
~ .x %>%
dplyr::select(-n_obs) %>%
dplyr::distinct()
) %>%
as_kable() # convert to kable to display on SO
Characteristic
Beta
95% CI
p-value
Grade
I
—
—
II
-0.39
-0.70, -0.08
0.014
III
-0.13
-0.43, 0.18
0.4
s(age)
>0.9
ti(age):gradeI
0.6
ti(age):gradeII
>0.9
ti(age):gradeIII
0.6
Created on 2022-02-21 by the reprex package (v2.0.1)

Nonlinear model convergence

I have a time series data set and each time series has datapoint of 30-year from different/same species. I am developing a forecasting model using the first 23 years of data from each time series data point and I am using the rest 7 years as test set to know the predictive ability of model but the nonlinear model (Model 6 and Model 7) don't give succinct result?
Data:
DD <- structure(list(Plot = 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, 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, 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,
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 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), .Label = c("BD", "BG"), class = "factor"), Year = c(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, 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, 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, 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, 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, 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, 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), Count = c(81L, 45L, 96L, 44L, 24L, 8L, 28L, 32L, 39L, 29L,
40L, 17L, 4L, 12L, 18L, 11L, 63L, 98L, 78L, 76L, 67L, 36L, 56L,
43L, 81L, 8L, 14L, 20L, 25L, 19L, 135L, 91L, 171L, 88L, 59L,
1L, 1L, 1L, 2L, 1L, 11L, 9L, 34L, 15L, 32L, 21L, 33L, 43L, 39L,
20L, 6L, 3L, 9L, 9L, 28L, 16L, 15L, 2L, 1L, 1L, 34L, 16L, 19L,
35L, 32L, 7L, 2L, 30L, 29L, 25L, 28L, 11L, 31L, 31L, 28L, 27L,
34L, 110L, 87L, 103L, 72L, 19L, 46L, 43L, 107L, 32L, 26L, 31L,
12L, 29L, 23L, 40L, 50L, 23L, 34L, 11L, 9L, 4L, 24L, 55L, 14L,
16L, 51L, 43L, 2L, 13L, 8L, 96L, 52L, 118L, 32L, 1L, 8L, 17L,
34L, 29L, 38L, 15L, 4L, 38L, 2L, 1L, 1L, 1L, 1L, 1L, 3L, 3L,
4L, 6L, 4L, 4L, 10L, 6L, 7L, 9L, 15L, 30L, 25L, 36L, 13L, 17L,
43L, 36L, 60L, 50L, 26L, 13L, 13L, 27L, 18L, 56L, 96L, 16L, 54L,
2L, 2L, 9L, 5L, 5L, 6L, 2L, 6L, 2L, 3L, 4L, 3L, 136L, 71L, 116L,
28L, 23L, 76L, 64L, 98L, 58L, 26L, 13L, 13L, 13L, 18L, 19L, 24L,
18L, 17L, 3L, 23L, 19L, 9L, 11L, 13L, 20L, 29L, 29L, 17L, 20L,
26L, 71L, 63L, 53L, 54L, 20L, 22L, 18L, 93L, 50L, 18L, 12L, 12L,
31L), LogCount = c(1.908385019, 1.653212514, 1.982271233, 1.643462676,
1.380211242, 0.903089987, 1.447158031, 1.505109978, 1.591064607,
1.462397998, 1.602059991, 1.230448921, 0.602059991, 1.079181206,
1.255272505, 1.041392685, 1.799340549, 1.991226076, 1.892094603,
1.880813592, 1.826074803, 1.556302501, 1.748188027, 1.633468456,
1.908485019, 0.903089987, 1.146128035, 1.301029996, 1.397940009,
1.278753601, 2.130333768, 1.95904139, 2.2329961, 1.94448267,
1.770852012, 0, 0, 0, 0.30102999, 0, 1.0411392685, 0.954242509,
1.531478917, 1.176031259, 1.505149978, 1.322219295, 1.51851394,
1.6334684456, 1.591064607, 1.301029996, 0.77815125, 0.477121255,
0.954242509, 0.954242509, 1.447158031, 1.204119983, 1.176091259,
0.301029996, 0, 0, 1.531478917, 1.204119983, 1.278753501, 1.544068044,
1.505149978, 0.084509804, 0.301029996, 1.477121255, 1.462397998,
1.397940009, 1.447158031, 1.041392685, 1.491361694, 1.491361694,
1.447158031, 1.431363754, 1.531478917, 2.041392685, 1.939519253,
2.012837225, 1.857332495, 1.278753601, 1.662757382, 1.633468456,
2.029383778, 1.505149978, 1.414973348, 1.491361594, 1.079181245,
1.462397998, 1.361727835, 1.602059991, 1.698970004, 1.361727836,
1.531478917, 1.041392685, 0.954242509, 0.602059991, 1.380211242,
1.740362689, 1.146128036, 1.204119983, 1.707570176, 1.633468456,
0.301029996, 1.113943352, 0.903089987, 1.982271233, 1.716003344,
2.071882007, 1.50514997, 0, 0.903089987, 1.230448921, 1.53147891,
1.2397998, 1.57978359, 1.176091259, 0.602059991, 1.57978359,
0.301029996, 0, 0, 0, 0, 0, 0.477121255, 0.477121255, 0.602059991,
0.77815125, 0.602059991, 0.602059991, 1, 0.77815125, 0.84509804,
0.95424509, 1.176091259, 1.477121255, 1.39790009, 1.555302501,
1.113943352, 1.230448921, 1.633468456, 1.555302501, 1.77815125,
1.698970004, 1.414973348, 1.113943352, 1.113943352, 1.431353754,
1.255272505, 1.748188027, 1.982271233, 1.204119983, 1.73239376,
1.431363754, 1.361727835, 0.954242509, 0.698970004, 0.698970004,
0.77815125, 0.301029996, 0.77815125, 0.301029996, 0.477121255,
0.602059991, 0.477121255, 2.133538908, 1.851258349, 2.064457989,
1.447158031, 1.361727836, 1.880813592, 1.806179974, 1.991226076,
1.763427994, 1.414973348, 1.113943352, 1.113943352, 1.113943352,
1.255272505, 1.278753601, 1.380211242, 1.255272505, 1.230446921,
0.477121255, 1.361727835, 1.278753601, 0.954242509, 1.0411392685,
1.113943352, 1.301029996, 1.462397998, 1.462397998, 1.230448921,
1.301029995, 1.414973348, 1.851258349, 1.799340549, 1.72427587,
1.73239376, 1.301029996, 1.342422681, 1.255272505, 1.968482949,
1.698970004, 1.255272505, 1.079181246, 1.079181246, 1.491361694
), Diff = c(-0.255272505, 0.329058719, -0.338818557, -0.263241434,
-0.077121255, 0.544068044, 0.057991947, 0.085910629, -0.128666609,
0.139661993, -0.37161107, -0.62838893, 0.477121255, 0.176091259,
-0.21387982, 0.757947864, 0.191885527, -0.099131473, -0.011281011,
-0.054738789, -0.269772302, 0.191885526, -0.114719571, 0.275016563,
-1.005395032, 0.243038049, 0.15490196, 0.096910013, -0.119186408,
NA, -0.171292376, 0.273954718, -0.288513438, -0.17363066, -1.770852012,
0, 0, 0.301029996, -0.301029996, 1.041392685, -0.087150176, 0.577235408,
-0.355387658, 0.329058719, -0.182930683, 0.196294545, 0.110954516,
-0.042403849, -0.290034611, -0.522878746, -0.301029995, 0.477121254,
0, 0.492915522, -0.243038048, -0.028028724, -0.875061263, -0.301029996,
0, 1.531078917, -0.32735893, 0.070633618, 0.265310043, -0.038918066,
-0.660051938, -0.544068044, 1.176091259, -0.014723257, -0.064457989,
0.049218022, -0.405765346, 0.449969009, 0, -0.044203663, -0.015794267,
0.100115153, 0.509913768, -0.101873432, 0.073317972, -0.155504729,
-0.578578895, 0.384054231, -0.029289376, 0.395915322, -0.5202338,
-0.09017663, 0.076388346, -0.412180448, 0.383216752, -0.100670162,
0.240332155, 0.096910013, -0.337242168, 0.169751081, -0.490086232,
-0.087150176, -0.352182518, 0.778151251, 0.360151447, -0.594234653,
0.057991947, 0.503450193, -0.07410172, -1.33243846, 0.812913356,
-0.210853365, 1.079181246, -0.266267889, 0.355878663, -0.566732029,
-1.505149978, 0.903089987, 0.327358934, 0.301029996, -0.069080919,
0.117385599, -0.403692338, -0.574031268, 0.977723606, -1.278753601,
-0.301029996, 0, 0, 0, 0, 0.477121255, 0, 0.124938736, 0.176091259,
-0.176091259, 0, 0.397490009, -0.2218485, 0.06690679, 0.10914469,
0.22184875, 0.301029996, -0.079181206, 0.158362092, -0.442359149,
0.116505569, 0.403019535, -0.077165955, 0.221848749, -0.079181206,
-0.283996656, -0.301029996, 0, 0.317420412, -0.176091259, 0.492915522,
0.23483206, -0.77815125, 0.528273777, -0.301029996, -0.069635928,
-0.407485327, -0.255272505, 0, 0.079181246, -0.477121254, 0.477121254,
-0.477121254, 0.176091259, 0.124938736, -0.124938736, 1.656417653,
-0.282280559, 0.21319964, -0.617299958, -0.085430195, 0.5191085756,
-0.074533518, 0.185045102, -0.227798082, -0.348454546, -0.301029996,
0, 0, 0.141329153, 0.023481096, 0.101457641, -0.124938737, -0.024823584,
-0.753327666, 0.884606581, -0.082974235, -0.324511092, 0.087150176,
0.072550667, 0.187086644, 0.161368002, 0, -0.231949077, 0.070581075,
0.113903352, 0.436285001, -0.00519178, -0.075054679, 0.00811789,
-0.431363764, 0.041392685, -0.087150176, 0.713210444, -0.269512945,
-0.443697499, -0.176091259, 0, 0.412180448, -0.148939013)), class = "data.frame", row.names = c(NA,
-210L))
Code:
for(f in 1:11){
for(b in 1:5){
for (c in 1:5){
#To select test sets 1,2,3,4, and 5 years beyond the training set:
#Calculate the mean of abundance for the training set years.
Model1<-lm(mean~1, data=DD1)
#
Output2:
2 3 0.676209994477288 1.9365051784348e-09 4.44089209850063e-16
3 53 11.9236453578109 2.06371097988267e-09 1.13686837721616e-13
4 31 1.94583877614293 1.11022302462516e-15 1.99840144432528e-15
5 4 8.06660449042397 1.48071350736245e-08 3.19744231092045e-14
6 5 10.5321102149558 9.31706267692789e-10 1.4210854715202e-14
..
First, please see the time series graph of counts for different species and plots below.
library(ggplot2)
ggplot(DD, aes(Year, Count)) +
geom_point() +
geom_line() +
facet_grid(Plot ~ Species) +
scale_y_log10()
It is seen that there is no obvious trend which can be fitted by power or log-power function using nls.
Second, as I understand you are trying to use nls to predict outside the training data set. Usually it is not quite an effective to use least square models because of auto-correlated nature of time-series.
Third, the simplest prediction algorithm is Holt-Winters (see "dirty" implementation below). You can use as well a ton of other algorithms like ARIMA, exponential smoothing state space etc.
x <- ts(DD[DD$Species == "BG" & DD$Plot == "elq1a3", ]$LogCount)
m <- HoltWinters(x, gamma = FALSE)
library(forecast)
f <- forecast(m, 2)
plot(f, main = "elq1a3 at BG")
Fourth, about your algorithm in question, it throws
Error in qr.solve(QR.B, cc) : singular matrix 'a' in solve.
The reason is that in the first step of for-loop (at f = b = c = 1 DD2 data frame contains just one row. And executing
Model6<-nls(Diff~1+Count^T,start=list(T=1),trace=TRUE,algorithm ="plinear",data=DD2)
means that you are trying to fit a curve using only one data point, which is impossible.
However if you change f value in for-loop from 1:11 to 2:11 another error thrown:
Error in nls(Diff ~ 1 + Count^T, start = list(T = 1), trace = TRUE,
algorithm = "plinear", : step factor 0.000488281 reduced below
minFactor 0.000976562.
In this case you cannot use "naive" approach used by plinear algorithm with self-starting inital value and, e.g. nls.control(min.factor = 1e-5). You must feed all initial coefficients explicitely with default Gauss-Newton algorithm. Quite exausting, please try yourself :)

dplyr n_distinct() in filter takes forever where as base length(unique()) works like charm

I have a data frame such as this:
structure(list(x = c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L,
6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L, 11L, 11L, 12L, 12L,
13L, 13L, 14L, 14L, 15L, 15L, 16L, 16L, 17L, 17L, 18L, 18L, 19L,
19L, 20L, 20L, 21L, 21L, 22L, 22L, 23L, 23L, 24L, 24L, 25L, 25L,
26L, 26L, 27L, 27L, 28L, 28L, 29L, 29L, 30L, 30L, 31L, 31L, 32L,
32L, 33L, 33L, 34L, 34L, 35L, 35L, 36L, 36L, 37L, 37L, 38L, 38L,
39L, 39L, 40L, 40L, 41L, 41L, 42L, 42L, 43L, 43L, 44L, 44L, 45L,
45L, 46L, 46L, 47L, 47L, 48L, 48L, 49L, 49L, 50L, 50L, 51L, 51L,
52L, 52L, 53L, 53L, 54L, 54L, 55L, 55L, 56L, 56L, 57L, 57L, 58L,
58L, 59L, 59L, 60L, 60L, 61L, 61L, 62L, 62L, 63L, 63L, 64L, 64L,
65L, 65L, 66L, 66L, 67L, 67L, 68L, 68L, 69L, 69L, 70L, 70L, 71L,
71L, 72L, 72L, 73L, 73L, 74L, 74L, 75L, 75L, 76L, 76L, 77L, 77L,
78L, 78L, 79L, 79L, 80L, 80L, 81L, 81L, 82L, 82L, 83L, 83L, 84L,
84L, 85L, 85L, 86L, 86L, 87L, 87L, 88L, 88L, 89L, 89L, 90L, 90L,
91L, 91L, 92L, 92L, 93L, 93L, 94L, 94L, 95L, 95L, 96L, 96L, 97L,
97L, 98L, 98L, 99L, 99L, 100L, 100L), y = structure(c(1L, 2L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L,
2L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L,
2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L,
1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L,
1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L,
1L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 1L, 1L, 2L), .Label = c("one", "two"), class = "factor")), class = "data.frame", row.names = c(NA,
-200L), .Names = c("x", "y"))
I am trying to filter groups of x that have two distinct y values using:
library(dplyr)
df %>% group_by(x) %>% filter(n_distinct(y) > 1)
On a large data set, this almost never finishes.
Changing to this works reasonably fast for the full data set:
library(dplyr)
df %>% group_by(x) %>% filter(length(unique(y)) > 1)
Any idea why n_distinct() is super slow to never finishing?

Resources