R中是否有一个函数将曲线拟合到直方图?
假设你有下面的直方图
hist(c(rep(65, times=5), rep(25, times=5), rep(35, times=10), rep(45, times=4)))
看起来很正常,但有点歪.我想拟合一条倾斜的法线曲线,以环绕这个直方图.
这个问题很基本,但我似乎在网上找不到R的答案.
R中是否有一个函数将曲线拟合到直方图?
假设你有下面的直方图
hist(c(rep(65, times=5), rep(25, times=5), rep(35, times=10), rep(45, times=4)))
看起来很正常,但有点歪.我想拟合一条倾斜的法线曲线,以环绕这个直方图.
这个问题很基本,但我似乎在网上找不到R的答案.
如果我正确理解了你的问题,那么你可能需要密度估计和直方图:
X <- c(rep(65, times=5), rep(25, times=5), rep(35, times=10), rep(45, times=4))
hist(X, prob=TRUE) # prob=TRUE for probabilities not counts
lines(density(X)) # add a density estimate with defaults
lines(density(X, adjust=2), lty="dotted") # add another "smoother" density
Edit a long while later:
下面是一个稍微打扮一下的版本:
X <- c(rep(65, times=5), rep(25, times=5), rep(35, times=10), rep(45, times=4))
hist(X, prob=TRUE, col="grey")# prob=TRUE for probabilities not counts
lines(density(X), col="blue", lwd=2) # add a density estimate with defaults
lines(density(X, adjust=2), lty="dotted", col="darkgreen", lwd=2)
以及它生成的图形: