简体   繁体   English

如何在R的直方图上绘制尖峰时间的指数分布?

[英]How to Plot an exponential distribution of spike times over a histogram of them, in R?

So my question follows the development after my last one. 所以我的问题跟随我上一次的发展。 I have been trying to work on getting the spike times as a rastor plot for a spike train. 我一直在尝试将尖峰时间作为尖峰列车的rastor情节。 I took a firing rate of 100 and got spike train for 20 trials: The code for that is: 我的射击率为100,并获得20次试验的加速训练:代码为:

fr = 100
dt = 1/1000 #dt in milisecond
duration = 2 #no of duration in s
nBins = 2000 #SpikeTrain
nTrials = 20 #NumberOfSimulations
MyPoissonSpikeTrain = function(p, fr= 100) {
  p = runif(nBins)
  q = ifelse(p < fr*dt, 1, 0)
  return(q)
}

set.seed(1)
SpikeMat <- t(replicate(nTrials, MyPoissonSpikeTrain()))

plot(x=-1,y=-1, xlab="time (s)", ylab="Trial",
main="Spike trains",
ylim=c(0.5, nTrials+1), xlim=c(0, duration))
for (i in 1: nTrials)
{
  clip(x1 = 0, x2= duration, y1= (i-0.2), y2= (i+0.4))
  abline(h=i, lwd= 1/4)
  abline(v= dt*which( SpikeMat[i,]== 1))
}

This gives the result: 这给出了结果: 斯派克火车

After all this was done, my next task was to get a vector of Inter-Spike intervals and get a histogram of them. 完成所有这些之后,我的下一个任务是获得Inter-Spike间隔的向量并获得它们的直方图。 Because the distribution of ISIs follows the exponential distribution, if I plot the exponential distribution of ISIs with the same data, it will match the curve made by the height of the histograms. 由于ISI的分布遵循指数分布,如果我绘制具有相同数据的ISI的指数分布,它将匹配由直方图的高度产生的曲线。 So to get the interspike timings first, I used: 因此,为了首先获得interpike时间,我使用了:

spike_times <- c(dt*which( SpikeMat[i, ]==1))

Then to get a vector for interspike intervals and their histogram, I used the following command line, 然后为了得到一个interpike间隔的矢量及其直方图,我使用了以下命令行,

ISI <- diff(spike_times)
hist(ISI, density= 10, col= 'blue', xlab='ISI(ms)', ylab='number of occurences')

and it gave me this plot: 它给了我这个情节:

HistogramsofISIs

Now, What I want is to plot the exponential distributions within the histograms that justifies the exponential distribution nature of the inter spike intervals. 现在,我想要的是绘制直方图中的指数分布,证明了峰值间隔的指数分布特性。 I am confused about what parameters to use and which rate to use. 我对使用什么参数以及使用哪种速率感到困惑。 If somebody has worked with Interspike interval plotting, please help. 如果有人使用Interspike间隔绘图,请帮忙。 And I am sorry if my data seems incomplete, please let me know if I am missing something. 如果我的数据看起来不完整,我很抱歉,如果我错过了什么,请告诉我。

My fellow researcher just told me a simple line of codes: 我的研究员刚给我讲了一行简单的代码:

x <- seq(0, 0.05, length=1000)
y <- dexp(x, rate=100)
lines(x,y)

which gave me, this: 这给了我,这个: HistogramWithExpoDis

If somebody has any way of making this process more efficient, please help me. 如果有人有办法让这个过程更有效率,请帮助我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM