I have got a frequency table of how many events occur within a 5-minute time window.
library(data.table) library(ggplot2) plotdata <- structure(list(events = 0:6, N = c(511468L, 75194L, 7813L, 1102L, 174L, 86L, 23L)), row.names = c(NA, -7L), class = c("data.table", "data.frame")) # events frequency #1: 0 511468 #2: 1 75194 #3: 2 7813 #4: 3 1102 #5: 4 174 #6: 5 86 #7: 6 23
Explained: 7813 times there was a 5-minute timewindow in which two events occured.
I am trying to fit this data onto a poisson-curve, but I'm geting lost here. My last statistics course was waaay back in college and I'm getting lost in the terminology.
What I've tried so far:
lambda <- sum( plotdata$events * plotdata$N ) / sum( plotdata$N ) #lambda = 0.1600879401
Get estimated values of poisson-distribution Resulting in (too?) low estimated values for events > 2
plotdata[, poisson.P := exp( -1 * lambda ) * lambda^events / factorial( events )] plotdata[, poisson.N := poisson.P * sum( N ) ] ggplot( plotdata, aes( x = events ) ) + geom_line( aes( y = N ) ) + geom_line( aes( y = poisson.N), colour = "red" ) + scale_y_log10()
black = counted values, red = result from poisson
Am I doing something wrong here? Or is my data not suited for a description by poisson-distribution, or..., or... ?
Underestimation on a larger number of
events is a no-go in my usecase. So I would really like the estimated output to perform better on events > 3