spikes icon indicating copy to clipboard operation
spikes copied to clipboard

psthRasterAndCounts gives psth that is undercounted in at the edge-bins

Open ilandau opened this issue 4 years ago • 4 comments

Hey there, I'm a new user. I noticed that the psth created by psthRasterAndCounts was undercounted in the first and last bin. Both psth and bins are returned as vectors that are the length of the number of edges, i.e. one more than the number of bins. This could be related to the old matlab hist function which used to accept bin-centers as inputs, whereas the new histogram function only accepts a vector of edges as inputs.

In any case, I made minor changes in the file locally to make it return psth and bins corresponding to the bin-centers and with length corresponding to the actual number of bins. I'd be happy to share that change. But maybe people out there are still using old versions of Matlab and that's why they're not running into issues?

ilandau avatar May 12 '20 12:05 ilandau

Good catch, yes looks like the first bin will be half as wide as the others (this is only going to be true for the last bin if the window size is evenly divisible by the bin size - I don't think it applies to the last bin in general). I think the correct fix is to change line 31 to start from window(1)+psthBinSize/2 rather than starting from window(1). Do you agree?

nsteinme avatar May 12 '20 16:05 nsteinme

So what I did was to replace line 31 with the following:

edges = window(1):psthBinSize:window(2); [psth, edges] = histcounts(stRelToEvent, edges); bins = edges(1:end-1) + psthBinSize/2;

Matlab seems to highly recommend switching out the old calls to hist.

ilandau avatar May 13 '20 08:05 ilandau

Ok, looks good, could you make a pull request with that?

On Wed, May 13, 2020 at 1:33 AM ilandau [email protected] wrote:

So what I did was to replace line 31 with the following:

edges = window(1):psthBinSize:window(2); [psth, edges] = histcounts(stRelToEvent, edges); bins = edges(1:end-1) + psthBinSize/2;

Matlab seems to highly recommend switching out the old calls to hist.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cortex-lab/spikes/issues/12#issuecomment-627835848, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZ5IP4DGMB532THTMKEG53RRJLN5ANCNFSM4M6Y5MLA .

nsteinme avatar May 13 '20 15:05 nsteinme

Sure.

I'm a bit of a newbie to github collaboration. It looks like I need to be assigned as a "collaborator" in order to start a new branch and then make the pull request. Is that right?

ilandau avatar May 13 '20 16:05 ilandau