Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将多个峰值拟合到一个数据集并提取R中的单个峰值信息_R_Histogram_Curve Fitting_Gaussian - Fatal编程技术网

将多个峰值拟合到一个数据集并提取R中的单个峰值信息

将多个峰值拟合到一个数据集并提取R中的单个峰值信息,r,histogram,curve-fitting,gaussian,R,Histogram,Curve Fitting,Gaussian,我有许多数据集,由不同海拔高度的要素数量组成。目前,1-30m之间每1m间隔有数据。绘制时,我的许多数据集显示出3-4个峰值,这表示高度层 以下是一个示例数据集: 高度“如何将曲线拟合到我的数据”是一个太宽泛的问题,因为有无数种方法可以做到这一点。它也可能比这里更适合。但是,从基本R开始的ksmooth是基本平滑器的一个非常好的起点: plot(Height,Counts) smoothCounts<-ksmooth(Height,Counts,kernel="normal",bandwi

我有许多数据集,由不同海拔高度的要素数量组成。目前,1-30m之间每1m间隔有数据。绘制时,我的许多数据集显示出3-4个峰值,这表示高度层

以下是一个示例数据集:

高度“如何将曲线拟合到我的数据”是一个太宽泛的问题,因为有无数种方法可以做到这一点。它也可能比这里更适合。但是,从基本R开始的
ksmooth
是基本平滑器的一个非常好的起点:

plot(Height,Counts)
smoothCounts<-ksmooth(Height,Counts,kernel="normal",bandwidth=2)
dsmooth<-diff(smoothCounts$y)
locmax<-sign(c(0,dsmooth))>0 & sign(c(dsmooth,0))<0
lines(smoothCounts)
points(smoothCounts$x[locmax],smoothCounts$y[locmax],cex=3,c=2)
绘图(高度、计数)

smoothCounts一个简单的峰值识别可以沿着以下线路进行。看起来合理吗

library(data.table)

dt <- data.table(
Height = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30),
Counts = c(4000,2000,500,300,200,100,0,0,400,700,800,800,500,1000,1500,2000,2500,2200,1700,1100,500,0,0,1000,1500,2000,3000,4000,4000,2000)
)

# crude dHeights/dCounts
dt[,d1 := c(NA,diff(Counts))]
# previous crude dHeights/dCounts (d2Heights/dCounts2 will be even more crude so comparing change in dHeight/dCounts instead)
dt[,d2 := c(tail(d1,-1),NA)]

# local maxima
dtpeaks <- dt[d1 >=0 & d2 <=0]
库(data.table)

dt
diff(计数)
diff(计数))
应该可以帮助您识别峰值。峰值宽度是一个简单的定义吗?谢谢你的建议。我应该更好地定义峰值宽度。我指的是单个峰值的半高宽(FWHM)。一旦钟形函数或峰值拟合到数据中,例如高斯分布。然后将每个峰值视为一个单独的实体。半最大宽度(FWHM)可以总结为:中间值(计数)处钟形曲线的宽度(高度),是曲线顶部最大值的一半。这可以可视化为哈哈,我不是指wiki链接,我在本例中特别要求。那么,如何计算29处峰值的宽度呢?