data(heights)
library(dplyr)
library(ggplot2)
theme_set(theme_bw())
# fit sitar model
model <- sitar(x = log(age), y = height, id = id, data = heights, df = 5)
(dv <- getDV(model))
(id_missing <- dv %>%
filter(missing) %>%
pull(id))
# plot individual velocity curves
ggplot(plot_V(model), aes(age, height, group = id, colour = id)) +
theme(legend.position = 'inside',
legend.position.inside = c(0.9, 0.6)) +
geom_line() +
# add individual peak velocities
geom_point(aes(y = velocity), data = dv) +
# highlight subjects 2, 7 and 12 with dashed lines
# despite incomplete curves their peak velocities are estimated
geom_line(data = . %>% filter(id %in% id_missing), linetype = 2, colour = 'white') +
geom_point(aes(y = velocity), data = dv %>%
filter(id %in% id_missing), shape = 1, size = 3)
Run the code above in your browser using DataLab