Time Series - Simulations
Overview
Simulations are a way to approximately compute the statistics areound a give process or distribution when you dont know how to derive an analytical formula
for that statistic. For example, lets say you wanted to know what the standard deviation of a coin flip was. If you didnt know the formula, but you did
have a program that generated 0s and 1s with a 50% probability each, you could just generate a large number of 0s and 1s and take the standard deviation of the result.
This would give you a number which would be approximately the true distributions standard deviation.
A Generic Time Series Simulation
A time series is a realization of a set of ordered random variables. This can be modeled as an array of varies. For
example, if we have a function that generates the next random variable realization, the following would generate
one realization of the times series.
let series = [];
for(let i=0;i<100;i++){
series.push(generate(series));
}
This code assumes that you have a function, here named generate, which when given the previous values in the series,
generates a random realization of the next random variable in the series.
Note that this is one realization of a time series. To get multiple realizations, you would have to iterate this process
multiple times.
The above code could be used to generate most examples of time series, given a suitable generate function.
However, most time series can be simplified. Notice that the code above passes into the generate function the
entire series up to that point. This is based on the assumption that a point in a time series can have complex
relationships to all the prior data points. (Here, we assume there is no dependence on data points in the future.)
A common assumption in time series , is the Markov assumption, which generally assumes that the current data point is
independent of all previous data points once the prior data point is known. The most common example of this is the
random walk, where the current point is equal to the prior point plus a random amount.
When this assumption is made, we no longer need to pass the prior values into the generate function.
let last = 0;
let series = [last];
for(let i=0;i<100;i++){
last += generate();
series.push(last);
}
Other Distributions
Once you have a generator for a uniform distribution, you can get a generator for any distribution for which you have a function that is the
inverse cumulative function, using the following formula.
{% X = F^{-1}(U) %}
The following code geneartes 100 samples takne from a anormal distribution by using the inverse cumulative normal function.
let nm = await import('/lib/statistics/distributions/normal/v1.0.0/normal.mjs');
let sample = [];
for(let i=0;i<100;i++){
sample.push(nm.invCumulative(Math.random()));
}
Additional Processes