从程序包'绘制50%分位数和可信区间;mcp&x27;以R为单位的输出

从程序包'绘制50%分位数和可信区间;mcp&x27;以R为单位的输出,r,ggplot2,bayesian,confidence-interval,credible-interval,R,Ggplot2,Bayesian,Confidence Interval,Credible Interval,我试图使用R中“mcp”包的输出在同一图表上绘制95%可信区间和50%中位数的直线。我使用mcp包为三个已知断点的线段(2013年和2017年)建模不同的残差标度(即准模拟)。然而,我似乎无法使用模型中的q_拟合来拟合同一地块上50%中位数的CI和直线。我在下面包含了一些示例代码。我的最终目标是用一条分段线表示模型中50%的分位数,并带有上下CI。我在下面包含了一些示例数据和代码,以及我想合并的单独绘图 year <-c(2003,2004,2005,2006,2007,2008,2009

我试图使用R中“mcp”包的输出在同一图表上绘制95%可信区间和50%中位数的直线。我使用mcp包为三个已知断点的线段(2013年和2017年)建模不同的残差标度(即准模拟)。然而,我似乎无法使用模型中的q_拟合来拟合同一地块上50%中位数的CI和直线。我在下面包含了一些示例代码。我的最终目标是用一条分段线表示模型中50%的分位数,并带有上下CI。我在下面包含了一些示例数据和代码,以及我想合并的单独绘图

year <-c(2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020)
counts <-c(40,50,200,50,20,30,15,12,10,12,12,200,1000,4000,6000,4500,5000,6000)

df <- data.frame(year,counts)


model = list(
  counts ~ 1 + year,        #segmented 1: Intercept and Slope
  ~ 0 + year + sigma (1),   #Segement 2: Joined slope (no intercept change)
  ~ 0 + year + sigma (1)    #Segment 3: Joined slope (no intercept change)
)

fit = mcp(model, df, prior = list(cp_1 = 2013, cp_2 = 2017))

plot(fit, q_fit = TRUE, cp_dens = FALSE, lines=50) #plot 95% CI


plot(fit, q_fit = c(0.5), cp_dens = FALSE, lines=50) #plot 50% quantile

年份