R中绘图的最佳拟合曲线

R中绘图的最佳拟合曲线,r,curve-fitting,R,Curve Fitting,我在一个叫做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

我在一个叫做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值中的数据进行曲线拟合,然后沿着
nls(乐趣,cbind(ph$counts,ph$mids),…)
可能有效。你需要知道你认为直方图数据应该适合哪种类型的函数“有趣”,例如正态分布。阅读
nls()
上的帮助文件,了解如何为FUN中的系数设置起始“猜测”值


如果您只是想在直方图上叠加一条曲线,那么
smoo您想要密度函数吗

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

实际上,我认为这是一种比样条线更好的画线方法。
x = rnorm(1000)
hist(x, breaks = 30, freq = FALSE)
lines(density(x), col = "red")