I ran an lmer model. I was able to produce normal trellis plots for each individual like this:
xyplot(asiatot~time|ID, data=S8_earlyNA)
Now I wanted to see the fitted values from my model (L4_edit) for each individuals overtop of these plots. Note: in my original model I did not include "na.action=na.exclude", but when I tried to save the fitted values I would receive the error "replacement has 4048 rows, data has 4557" (I assumed because of some missing data points)
L4_edit <- lmer(asiatot ~ time+ ASIMPC01_A+ SPLVL1_A+ NaStatus3+
NaStatus3*time+ F+ (time|ID), S8, na.action=na.exclude)
S8$fittedL4edit <- fitted(L4_edit)
S8_edit <- subset(S8, S8$Sodiumblockers.early==1)
ggplot(S8_edit)+aes(x=S8_edit$time, y=S8_edit$asiatot) +
geom_line(aes(y=S8_edit$fittedL4edit), size=0.5) +
geom_point() + facet_wrap("ID")
This produced what I wanted, except for one problem: understandably, some of the fitted lines for these individuals are broken... but other times I don't understand why the line is missing so much, or why it didn't create 2 lines. There seems to be a lot of lines missing, given the data. Please see the image link below (e.g. ID #378, or 380) 1.
Thank you!