簡體   English   中英

從 R 中的包“mcp”輸出中繪制 50% 分位數和可信區間

[英]Plotting both 50% quantile and credible interval from package 'mcp' output in R

我正在嘗試使用 R 中“mcp”包的輸出在同一圖表上繪制 95% 可信區間和 50% 中位數的線。我使用 mcp 包來模擬不同的殘差尺度(即准模擬) 用於具有已知斷點的三個細分市場(2013 年和 2017 年)。 但是,我似乎無法使用模型中的 q_fit 在同一圖上同時擬合 CI 和 50% 中位數的線。 我在下面包含了一些示例代碼。 我的最終目標是用一條分割線代表模型中具有上下 CI 的 50% 分位數。 我在下面包含了一些示例數據和代碼,以及我想合並的單獨圖。

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

具有 95% CI 的第一個圖

50% 分位數線

如果將它們作為向量提供給q_fit則可以繪制任意數量的分位數:

plot(fit, q_fit = c(0.025, 0.5, 0.975), cp_dens = FALSE, lines=50)

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM