首页 > 解决方案 > 将 95% 置信区间添加到 SITAR 平均增长曲线

问题描述

我正在使用该sitar软件包将 SITAR(模拟生长生物学的生长曲线分析形式)拟合到高度数据。我使用该模型绘制了显示平均生长曲线、平均速度曲线和峰值身高速度时的平均年龄的图。

library(sitar)

data <- na.omit(berkeley[berkeley$sex == 2 & berkeley$age >= 8 & 
berkeley$age <= 18, c('id', 'age', 'height')])

sitar_model <- sitar(x = age, y = height, id = id, data = data, df = 5)


#PLOT
par(mar = c(4,4,1,1) + 0.1, cex = 0.8)
plot(sitar_model, opt = 'd', las = 1, apv = TRUE)
plot(sitar_model, opt = 'v', las = 1, apv = TRUE, lty = 2)

我希望这些图包括围绕平均线的上下 95% 置信区间的线。

标签: rggplot2plot

解决方案


library(sitar)

data <- na.omit(berkeley[berkeley$sex == 2 & berkeley$age >= 8 & berkeley$age <= 18, 
                   c('id', 'age', 'height')])
sitar_model <- sitar(x = age, y = height, id = id, data = data, df = 5)

plot(sitar_model, opt = c('d',  'v'), las = 1, apv = F, 
 legend = NULL, ylim = c(100,200),  
 vlab="", ylab="", xlab="",
 y2par=list(lwd=2), vlim = c(0,12), lwd=2,
 main="Mean and 95 CI growth curves")
lines(sitar_model, 
  opt=c('d',  'v'), y2par=list(col='light blue', lwd=1.5, ylim = c(0,12)), 
  apv = F, lwd=1.5, lty=1, col='light blue', abc= 
(sqrt(diag(getVarCov(sitar_model)))*1.96), vlim = c(0,10), ylim = c(100,200))
lines(sitar_model, 
  opt=c('d',  'v'), y2par=list(col='light gray', lwd=1.5, ylim = c(0,12)), apv = F, lwd=1.5, 
  col='light gray', lty=1, abc=(sqrt(diag(getVarCov(sitar_model)))*1.96), vlim = c(0,10), ylim = c(100,200))
abline(v = 11.720, lwd=2, lty=3)
abline(v = 9.214, lwd=1.5, lty=3, col="light blue")
abline(v = 14.110, lwd=1.5, lty=3, col="light gray")
mtext("Age - years", side = 1, line = 3)
mtext("Height - cm", side = 2, line = 3.5)
mtext("Height velocity - cm / year", side = 4, line = 3)
legend("topleft", c( "Mean growth curve", "Lower 95% CI", "Upper 95% CI"),
   col = c("black", "light blue", "light gray"), lty = c(1, 1, 1))

在此处输入图像描述


推荐阅读