R程序包fitdistrplus具有denscomp
函數,該函數繪製擬合累積密度曲線以及數據的直方圖。作爲一名R新手,我很欣賞這個軟件包中的所有情節。使用沒有直方圖的fitdistrplus對象繪製累積密度圖
有沒有簡單的方法來繪製沒有直方圖的曲線?
我在文檔中的denscomp
函數中找不到像histogram = FALSE
這樣的選項。
我該如何使用fitdist$estimate
來繪製累積密度曲線?
R程序包fitdistrplus具有denscomp
函數,該函數繪製擬合累積密度曲線以及數據的直方圖。作爲一名R新手,我很欣賞這個軟件包中的所有情節。使用沒有直方圖的fitdistrplus對象繪製累積密度圖
有沒有簡單的方法來繪製沒有直方圖的曲線?
我在文檔中的denscomp
函數中找不到像histogram = FALSE
這樣的選項。
我該如何使用fitdist$estimate
來繪製累積密度曲線?
我不確定是否有簡單的方法來改變denscomp
的行爲,但是您可以使用由fitdist
返回的分佈參數來滾動您自己的密度圖。這裏有一個例子:
設置繪製三幅地塊在一個窗口:
par(mfrow=c(3,1), mar=c(4,4,3,1))
library(fitdistrplus)
爲denscomp
創建使用從幫助adpated一個例子的fitdist
對象:
data(groundbeef)
serving <- groundbeef$serving
fitW <- fitdist(serving, "weibull")
現在讓我們做標準denscomp
圖:
denscomp(fitW, plotstyle="graphics", main="denscomp Version")
現在我們將使用由fitdist
返回的參數來滾動我們自己的Weibull密度。 fitW$estimate
包含serving
數據的擬合威布爾分佈的shape
和scale
參數。
x=seq(0, max(serving), length=100)
serving_dwei = dweibull(x, shape=fitW$estimate["shape"], scale=fitW$estimate["scale"])
hist(serving, freq=FALSE, main="Roll Your Own")
lines(x=x, y=serving_dwei, col="red")
最後,密度單獨情節:下面我們如上使用這些參數生成相同的情節
plot(x=x, y=serving_dwei, type="l", main="Density alone", xlab="Serving", ylab="Density")
所有三個地塊如下:
如果你想比較威布爾擬合和經驗覈密度,你可以這樣做:
plot(x=x, y=serving_dwei, type="l", main="Weibull fit plus empirical density",
xlab="Serving", ylab="Density",
ylim=c(0,max(c(serving_dwei, density(serving)$y))))
lines(density(serving), col="red")
感謝您提供全面,明確的答案。對我來說缺少的一個環節是使用密度函數(dweibull)。 –
爲downvote解釋將是有益的! –