## fit sitar model
m1 <- sitar(x = age, y = height, id = id, data = heights, df = 4)
## draw fitted distance and velocity curves
## with distance in red and velocity in blue
## marking age at peak velocity (apv)
plot(m1, col = c('red', 'blue'), apv = TRUE)
## bootstrap standard errors for apv and pv
if (FALSE) {
res <- apv_se(m1, nboot = 20, plot = TRUE)
}
## draw individually coloured growth curves adjusted for random effects
## using same x-axis limits as for previous plot
plot(m1, opt = 'a', col = id, xlim = xaxsd())
## add mean curve in red
lines(m1, opt = 'd', col = 'red', lwd = 2)
## add curve for an individual with random effects a, b and c = -1 SD
lines(m1, opt = 'd', lwd = 2, abc = -sqrt(diag(getVarCov(m1))))
## compare curves for early versus late menarche
heights <- within(sitar::heights, {
men <- abs(men)
late <- factor(men > median(men))
})
## fit model where size and timing differ by early vs late menarche
m2 <- sitar(log(age), height, id, heights, 5,
a.formula = ~late, b.formula = ~late)
## plot distance and velocity curves for the two groups
plot(m2, opt = 'dv', lwd = 2, col = late)
legend('bottom', paste(c('early', 'late'), 'menarche'),
lwd = 2, col = 1:2, inset = 0.04)
## alternatively plot early and late groups separately
## early
lines(m2, opt = 'dv', subset = late == FALSE, col = 'white')
## late
lines(m2, opt = 'dv', subset = late == TRUE, col = 'white')
## draw fitted height distance curves coloured by subject, using ggplot
if (FALSE) {
require(ggplot2)
ggplot(plot_D(m1), aes(age, height, colour = .id)) +
geom_line(show.legend = FALSE)
}
Run the code above in your browser using DataLab