I have data that reflects the arrival time of a flight. {3, -2, 16, 13, -6, 5, 4, -7, 7, 0……..n} this is for 8:45am and has 150 elements "arrivals" The positive values represent the time in minutes past the planned time,{“late”} and the negative, is before planned time {“early”} My question, I would like to find the time of arrival with the highest probability. Can I use this data as is?

  • $\begingroup$ Is your question related to Mathematica (TM)? If not, you're in the wrong site $\endgroup$ Feb 23, 2013 at 1:08
  • $\begingroup$ Yes this is a question directed to mathematica. $\endgroup$
    – Bob Brooks
    Feb 23, 2013 at 1:24
  • 1
    $\begingroup$ Histogram[data,Automatic,"Probability"] seems like a good start. To say anything about highest probability you need to make some assumptions about the underlying distributions. You can try to fit various distributions to the data. $\endgroup$
    – ssch
    Feb 23, 2013 at 1:33
  • 2
    $\begingroup$ On a related note, anyone know how DistributionFitTest is supposed to be interpreted? sets = 100; size = 10000; data = RandomVariate[NormalDistribution[], {sets, size}]; Histogram[DistributionFitTest[#, Automatic] & /@ data] It's all over the place $\endgroup$
    – ssch
    Feb 23, 2013 at 1:53
  • 1
    $\begingroup$ @ssch, As far as I understand DistributionFitTest gives you back the p-value from the test which is going to vary for each set but most of the results of the actual test are what you expect sets=100;size=10000;data=RandomVariate[NormalDistribution[x,{sets,size}];Tally[(DistributionFitTest[#,Automatic,"ShortTestConclusion"] & /@ data)] $\endgroup$ Feb 23, 2013 at 2:20

1 Answer 1


For the sake of giving a (hopefully) useful answer.

Lets generate 150 arrival times where negative values indicate early and positive times indicate late arrivals. Here I'm assuming that people are as likely to be late as early and the distribution of arrival times is BinomialDistribution[20, 1/2]. This further assumes that people tend to be about 10 minutes early or 10 minutes late.

arrival = 
 RandomChoice[{-1, 1}, 150]*
  RandomVariate[BinomialDistribution[20, 1/2], 150];

Now there are a number of things available to us in Mathematica for working with this data.

Lets compute the expected arrival time.

Expectation[a, a \[Distributed] arrival]

(* -(109/75) *)

Or we could say, what is the probability someone is late?

Probability[a > 0, a \[Distributed] arrival]

(* 13/30 *)

We can estimate distributions from the data. Here a mixture of normals is used which is a little silly given that the data is discrete but normal is known to be a reasonable approximation to the binomial distribution with large enough samples and we expect a bimodal distribution given the setup.

 est = EstimatedDistribution[arrival, 
 MixtureDistribution[{1/2, 1/2}, {NormalDistribution[a, b], 
   NormalDistribution[c, d]}]]

(* MixtureDistribution[{1/2, 1/2}, {NormalDistribution[9.75385, 2.15571], 
  NormalDistribution[-10.0235, 2.35635]}] *)

We can plot all sorts of things and assess the goodness of fit to our chosen distribution.

Show[Plot[PDF[est, x], {x, -25, 25}], SmoothHistogram[arrival]]

enter image description here

We should keep in mind here that the p-value will probably be larger than it should be since I've estimated the distribution from the data first...

DistributionFitTest[arrival, est]

(* 0.107467 *)

We can always check further with a QuantilePlotwhich claims it doesn't fit so well in the body of the distribution...

QuantilePlot[arrival, est]

enter image description here

The bottom line is that there is nothing special about negative arrival times as far as Mathematica is concerned. It is happy to work with them just like any other data.

  • $\begingroup$ Thank you @AndyRoss, I think this will do just fine! $\endgroup$
    – Bob Brooks
    Feb 23, 2013 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.