使用没有直方图的 fitdistrplus 对象绘制累积密度图
plotting cumulative density plot using fitdistrplus object without a histogram
R 包 fitdistrplus 有一个 denscomp
函数,可以绘制拟合的累积密度曲线以及数据的直方图。作为 R 新手,我很欣赏这个包中提供的所有图表。
有没有一种简单的方法可以在没有直方图的情况下绘制曲线?
我在文档的 denscomp
函数中找不到像 histogram = FALSE
这样的选项。
我应该如何使用 fitdist$estimate
绘制累积密度曲线?
我不确定是否有一种简单的方法可以更改 denscomp
的行为,但您可以使用 fitdist
返回的分布参数绘制您自己的密度图。这是一个例子:
设置一次绘制三个地块window:
par(mfrow=c(3,1), mar=c(4,4,3,1))
library(fitdistrplus)
使用从 denscomp
的帮助中改编的示例创建一个 fitdist
对象:
data(groundbeef)
serving <- groundbeef$serving
fitW <- fitdist(serving, "weibull")
现在让我们制作一个标准的denscomp
情节:
denscomp(fitW, plotstyle="graphics", main="denscomp Version")
现在我们将使用 fitdist
返回的参数滚动我们自己的威布尔密度。 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")
R 包 fitdistrplus 有一个 denscomp
函数,可以绘制拟合的累积密度曲线以及数据的直方图。作为 R 新手,我很欣赏这个包中提供的所有图表。
有没有一种简单的方法可以在没有直方图的情况下绘制曲线?
我在文档的 denscomp
函数中找不到像 histogram = FALSE
这样的选项。
我应该如何使用 fitdist$estimate
绘制累积密度曲线?
我不确定是否有一种简单的方法可以更改 denscomp
的行为,但您可以使用 fitdist
返回的分布参数绘制您自己的密度图。这是一个例子:
设置一次绘制三个地块window:
par(mfrow=c(3,1), mar=c(4,4,3,1))
library(fitdistrplus)
使用从 denscomp
的帮助中改编的示例创建一个 fitdist
对象:
data(groundbeef)
serving <- groundbeef$serving
fitW <- fitdist(serving, "weibull")
现在让我们制作一个标准的denscomp
情节:
denscomp(fitW, plotstyle="graphics", main="denscomp Version")
现在我们将使用 fitdist
返回的参数滚动我们自己的威布尔密度。 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")