R中绘图的最佳拟合曲线
我在一个名为 ph 的图中有一个概率密度函数,它是在 stackoverflow 用户的帮助下从两个数据样本中得出的,这样
few <-read.table('outcome.dat',head=TRUE)
many<-read.table('alldata.dat',head=TRUE)
mh <- hist(many$G,breaks=seq(0,1.,by=0.03), plot=FALSE)
fh <- hist(few$G, breaks=mh$breaks, plot=FALSE)
ph <- fh
ph$density <- fh$counts/(mh$counts+0.001)
plot(ph,freq=FALSE,col="blue")
我想拟合 ph 图中的最佳曲线,但我可以'找不到工作方法。 我该怎么做?我必须从 ph 中提取值然后对它们进行处理?或者有相同的功能可以
plot(ph,freq=FALSE,col="blue")
直接使用?
I have a probability density function in a plot called ph that i derived from two samples of data, by the help of a user of stackoverflow, in this way
few <-read.table('outcome.dat',head=TRUE)
many<-read.table('alldata.dat',head=TRUE)
mh <- hist(many$G,breaks=seq(0,1.,by=0.03), plot=FALSE)
fh <- hist(few$G, breaks=mh$breaks, plot=FALSE)
ph <- fh
ph$density <- fh$counts/(mh$counts+0.001)
plot(ph,freq=FALSE,col="blue")
I would like to fit the best curve of the plot of ph, but i can't find a working method.
how can i do this? I have to extract the vaule from ph and then works on they? or there is same function that works on
plot(ph,freq=FALSE,col="blue")
directly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设你的意思是你想要对 ph 中的数据进行曲线拟合,那么沿着
nls(FUN, cbind(ph$counts, ph$mids),...)
可能有效。您需要知道您认为直方图数据应该适合哪种函数“FUN”,例如正态分布。阅读nls()
的帮助文件,了解如何为 FUN 中的系数设置起始“猜测”值。如果您只是想将曲线叠加到直方图上,那么 smoo<-spline(ph$mids,ph$counts);
lines(smoo$x,smoo$y)
将接近做到这一点。您可能需要调整 x 和/或 y 缩放比例。
Assuming you mean that you want to perform a curve fit to the data in ph, then something along the lines of
nls(FUN, cbind(ph$counts, ph$mids),...)
may work. You need to know what sort of function 'FUN' you think the histogram data should fit, e.g. normal distribution. Read the help file onnls()
to learn how to set up starting "guess" values for the coefficients in FUN.If you simply want to overlay a curve onto the histogram, then
smoo<-spline(ph$mids,ph$counts);
lines(smoo$x,smoo$y)
will come close to doing that. You may have to adjust the x and/or y scaling.
你想要密度函数吗?
Do you want a density function?