R中绘图的最佳拟合曲线

发布于 2024-12-05 21:35:57 字数 539 浏览 0 评论 0原文

我在一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戈亓 2024-12-12 21:35:57

假设你的意思是你想要对 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 on nls() 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.

说谎友 2024-12-12 21:35:57

你想要密度函数吗?

x = rnorm(1000)
hist(x, breaks = 30, freq = FALSE)
lines(density(x), col = "red")

Do you want a density function?

x = rnorm(1000)
hist(x, breaks = 30, freq = FALSE)
lines(density(x), col = "red")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文