R中的最佳拟合曲线 [英] best fitting curve from plot in R

查看:300
本文介绍了R中的最佳拟合曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个称为ph的图中,我有一个概率密度函数,我是通过stackoverflow用户的帮助从两个数据样本中得出的,以此方式

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")

我想拟合ph曲线的最佳曲线,但我不能找到一种工作方法。
我该怎么做?我必须从ph提取值,然后对其进行处理?或在

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")

直接?

推荐答案

假设您要对ph中的数据进行曲线拟合,然后沿着
nls(FUN,cbind(ph $ counts,ph $ mids), ...)可能有效。您需要知道直方图数据应该适合哪种功能 FUN,例如正态分布。阅读 nls()上的帮助文件,以了解如何为FUN中的系数设置起始猜测值。

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.

如果只想在直方图上覆盖一条曲线,则 smoo <-spline(ph $ mids,ph $ counts);
行(smoo $ x,smoo $ y)

If you simply want to overlay a curve onto the histogram, then smoo<-spline(ph$mids,ph$counts); lines(smoo$x,smoo$y)

差不多可以做到这一点。您可能需要调整x和/或y缩放比例。

will come close to doing that. You may have to adjust the x and/or y scaling.

这篇关于R中的最佳拟合曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆