
i
i
“K23166” — 2015/1/28 — 9:35 — page 111 — #137
i
i
i
i
i
i
7.10. EXAMPLES 111
> plot(gamreg, terms=c("lo(pcs)"), se=2, lwd=3)
> abline(h=0)
20 30 40 50 60 70
−50 51015
pcs
lo(pcs)
Figure 7.1: Scatterplots of smoothed association of physical component score (PCS) with
CESD
While more complicated in this example (because of the need to keep the baseline values as
non-time-varying variables), the dplyr and tidyr packages can also be used to accomplish
the same task.
> library(dplyr); library(tidyr); library(stringr)
> long = gather(ds, measurement, value, cesd1, cesd2, cesd3, cesd4,
pcs1, pcs2, pcs3, pcs4, mcs1, mcs2, mcs3, mcs4,
i11, i12, i13, i14, g1b1, g1b2, g1b3, ...