I'm trying to fit a random intercept random slope model to my data. In this data, I have different patients, all with three implanted electrodes (LAN/SAN/PAN), and I'm looking at the effect of StimRate on the response 'result'. Using lmer I'm fitting this model, but the individual coefficients per subject/electrode combination do not seem to be correct.
dataset
df<-structure(list(subject = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L), .Label = c("1", "2", "3", "5", "6", "8", "9"), class = "factor"), Electrode = c("LAN", "LAN", "LAN", "SAN", "SAN", "SAN", "PAN", "PAN", "PAN", "LAN", "LAN", "LAN", "SAN", "SAN", "SAN", "PAN", "PAN", "PAN", "LAN", "LAN", "LAN", "SAN", "SAN", "SAN", "PAN", "PAN", "PAN", "LAN", "LAN", "LAN", "SAN", "SAN", "SAN", "PAN", "PAN", "PAN", "LAN", "LAN", "LAN", "SAN", "SAN", "SAN", "PAN", "PAN", "PAN", "LAN", "LAN", "LAN", "SAN", "SAN", "SAN", "PAN", "PAN", "PAN", "LAN", "LAN", "LAN", "SAN", "SAN", "SAN", "PAN", "PAN", "PAN"), StimRate = c(170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350, 170, 255, 350), result = c(6.52102722288664, 9.22019774432065, 26.5655048141819, 14.5, 20, 24.25, 1.9142135623731, 2.92080962648189, 4.30277563773199, 63.9763476887368, 88.9562197097544, 140.606864480896, 60.4829340051411, 64.0882999323977, 89.6212532523402, 9, 15.0118980208143, 25.8648808045487, 66.4275, 67.2522222222222, 111.332727272727, 90.972, 117.55, 141.881666666667, 20.255, 30.91125, 57.06, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.513333333182, 1.46499999986639, 1.60045618855114, 2.32320260275458, 2.50266082562552, 2.21762809295402, 1.92141610251248, 1.62939845265917, 2.45633949992756, 32.8, 48.51, 66.19625, 26.655, 36.3875, 39.335, 9.2425, 14.5775, 26.85125, 73.92, 58.73, 86.8066666666667, 94.4475, 100.1125, 81.7683333333333, 15.3075, 44.595, 47.395)), row.names = c(7L, 8L, 9L, 16L, 17L, 18L, 25L, 26L, 27L, 34L, 35L, 36L, 43L, 44L, 45L, 52L, 53L, 54L, 61L, 62L, 63L, 70L, 71L, 72L, 79L, 80L, 81L, 88L, 89L, 90L, 97L, 98L, 99L, 106L, 107L, 108L, 115L, 116L, 117L, 124L, 125L, 126L, 133L, 134L, 135L, 142L, 143L, 144L, 151L, 152L, 153L, 160L, 161L, 162L, 169L, 170L, 171L, 178L, 179L, 180L, 187L, 188L, 189L), class = "data.frame")
model
RISM = lmer(result ~ StimRate + (1 + StimRate | subject/Electrode), data = df) summary(RISM) cf<-coef(RISM)
when plotting the regression (intercept/slope), is does not fit well, for example for LAN/subject 2. When applying a linear regression on only this data it fits well however. What is going wrong with the random intercept random slope model?
df_subset<- df[which(df$subject==2 & df$Electrode=="LAN"),] lm(results~StimRate, data = df_subset)