[英]plotting threshold/piecewise/change point models with 95% confidence intervals in R
[英]R plotting multiple locfit models with confidence intervals
我試圖在一個圖中繪制兩個locfit模型,但是無法獲得第二個locfit模型來繪制置信區間。 我創建了兩個locfit模型:
1_fit = locfit(Y~Time,data=data_1)
2_fit = locfit(Y~Time,data=data_2)
每個人都可以使用下面的方法使用置信區間獨立繪制它們:
plot(1_fit,band="local",type = "l", xlab = "Time", ylab = "Y-Axis",ylim=c(0,22),
col = "red",lwd = 5,font=3,main="Local Poly Fit 1",cex.lab=1.5, cex.axis=1.5,
cex.main=1.5, cex.sub=1.5)
但是,當我嘗試使用以下方法在圖上繪制其他locfit模型時:
lines(2_fit,col="blue")
我只能添加locfit線,而不能添加置信區間。 我試圖做:
lines(2_fit,band="local",col="blue")
但是我收到此消息,並且沒有置信區間:
Warning message: In plot.xy(xy.coords(x, y), type = type, ...) : "band" is not a graphical parameter
我也研究過使用lines.locfit ,但是運氣不好,因為R只是說它找不到功能lines.locfit。
我有一種解決方法,可以使用以下方法將兩個圖放在同一窗口中:
par(mfrow=c(2,1))
但是要避免這種情況,因為如果它們在同一圖中,則會使這些圖更具可比性。
理查德·特爾福德(Richard Telford)在評論中提供了答案。 以下代碼能夠完成我所需要的:
plot(1_fit,band="local",type = "l", xlab = "Time", ylab = "Y-Axis",ylim=c(0,22), xlim=c(0,12), col = "red",lwd = 5,font=3,main="Local Poly Fit 1",cex.lab=1.5, cex.axis=1.5, cex.main=1.5, cex.sub=1.5)`
par(new = TRUE)
plot(2_fit,band="local",type = "l", xlab = "Time", ylab = "Y-Axis",ylim=c(0,22), xlim=c(0,12),col = "blue",lwd = 5,font=3,main="Local Poly Fit 1",cex.lab=1.5, cex.axis=1.5, cex.main=1.5, cex.sub=1.5)`
我需要確保ylim
和xlim
以及main,ylab和xlab相等。 也是理查德(Richard)的附帶說明,1_fit不是法定名稱,我在這里使用它只是作為占位符名稱,但似乎可以繼續使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.