0

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!

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
fwarner
  • 55
  • 6
  • It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data that we can run and test ourselves. But generally you should should not be using `$` in `aes()` calls. – MrFlick Sep 25 '17 at 20:53
  • Also, your first call to `aes` should be inside the call to `ggplot`, i.e., `ggplot(S8_edit, aes(x=time, y=asiatot))`. – eipi10 Sep 25 '17 at 21:25

0 Answers0