Sinusoidal Model

sinusoidal_model(data, precision=4)

Generates a sinusoidal regression model from a given data set

Parameters
  • data (list of lists of int or float) – List of lists of numbers representing a collection of coordinate pairs; it must include at least 10 pairs

  • precision (int, default=4) – Maximum number of digits that can appear after the decimal place of the results

Raises
  • TypeError – First argument must be a 2-dimensional list

  • TypeError – Elements nested within first argument must be integers or floats

  • ValueError – First argument must contain at least 10 elements

  • ValueError – Last argument must be a positive integer

Returns

  • model[‘constants’] (list of float) – Coefficients of the resultant sinusoidal model; the first element is the vertical stretch factor, the second element is the horizontal stretch factor, the third element is the horizontal shift, and the fourth element is the vertical shift

  • model[‘evaluations’][‘equation’] (func) – Function that evaluates the equation of the sinusoidal model at a given numeric input (e.g., model[‘evaluations’][‘equation’](10) would evaluate the equation of the sinusoidal model when the independent variable is 10)

  • model[‘evaluations’][‘derivative’] (func) – Function that evaluates the first derivative of the sinusoidal model at a given numeric input (e.g., model[‘evaluations’][‘derivative’](10) would evaluate the first derivative of the sinusoidal model when the independent variable is 10)

  • model[‘evaluations’][‘integral’] (func) – Function that evaluates the integral of the sinusoidal model at a given numeric input (e.g., model[‘evaluations’][‘integral’](10) would evaluate the integral of the sinusoidal model when the independent variable is 10)

  • model[‘points’][‘roots’] (list of lists of float or str) – List of lists of numbers representing the coordinate pairs of all the x-intercepts of the sinusoidal model (will contain either None or an initial set of points within two periods along with general terms for finding the other points)

  • model[‘points’][‘maxima’] (list of lists of float or str) – List of lists of numbers representing the coordinate pairs of all the maxima of the sinusoidal model (will contain an initial set of points within two periods along with a general term for finding the other points)

  • model[‘points’][‘minima’] (list of lists of float or str) – List of lists of numbers representing the coordinate pairs of all the minima of the sinusoidal model (will contain an initial set of points within two periods along with a general term for finding the other points)

  • model[‘points’][‘inflections’] (list of lists of float or str) – List of lists of numbers representing the coordinate pairs of all the inflection points of the sinusoidal model (will contain an initial set of points within two periods along with a general term for finding the other points)

  • model[‘accumulations’][‘range’] (float) – Total area under the curve represented by the sinusoidal model between the smallest independent coordinate originally provided and the largest independent coordinate originally provided (i.e., over the range)

  • model[‘accumulations’][‘iqr’] (float) – Total area under the curve represented by the sinusoidal model between the first and third quartiles of all the independent coordinates originally provided (i.e., over the interquartile range)

  • model[‘averages’][‘range’][‘average_value_derivative’] (float) – Average rate of change of the curve represented by the sinusoidal model between the smallest independent coordinate originally provided and the largest independent coordinate originally provided

  • model[‘averages’][‘range’][‘mean_values_derivative’] (list of float or str) – All points between the smallest independent coordinate originally provided and the largest independent coordinate originally provided where their instantaneous rate of change equals the function’s average rate of change over that interval

  • model[‘averages’][‘range’][‘average_value_integral’] (float) – Average value of the curve represented by the sinusoidal model between the smallest independent coordinate originally provided and the largest independent coordinate originally provided

  • model[‘averages’][‘range’][‘mean_values_integral’] (list of float or str) – All points between the smallest independent coordinate originally provided and the largest independent coordinate originally provided where their value equals the function’s average value over that interval

  • model[‘averages’][‘iqr’][‘average_value_derivative’] (float) – Average rate of change of the curve represented by the sinusoidal model between the first and third quartiles of all the independent coordinates originally provided

  • model[‘averages’][‘iqr’][‘mean_values_derivative’] (list of float or str) – All points between the first and third quartiles of all the independent coordinates originally provided where their instantaneous rate of change equals the function’s average rate of change over that interval

  • model[‘averages’][‘iqr’][‘average_value_integral’] (float) – Average value of the curve represented by the sinusoidal model between the first and third quartiles of all the independent coordinates originally provided

  • model[‘averages’][‘iqr’][‘mean_values_integral’] (list of float or str) – All points between the first and third quartiles of all the independent coordinates originally provided where their value equals the function’s average value over that interval

  • model[‘correlation’] (float) – Correlation coefficient indicating how well the model fits the original data set (values range between 0.0, implying no fit, and 1.0, implying a perfect fit)

Notes

  • Provided ordered pairs for the data set: \(p_i = \{ (p_{1,x}, p_{1,y}), (p_{2,x}, p_{2,y}), \cdots, (p_{n,x}, p_{n,y}) \}\)

  • Provided values for the independent variable: \(X_i = \{ p_{1,x}, p_{2,x}, \cdots, p_{n,x} \}\)

  • Provided values for the dependent variable: \(Y_i = \{ p_{1,y}, p_{2,y}, \cdots, p_{n,y} \}\)

  • Minimum value of the provided values for the independent variable: \(X_{min} \leq p_{j,x}, \forall p_{j,x} \in X_i\)

  • Maximum value of the provided values for the independent variable: \(X_{max} \geq p_{j,x}, \forall p_{j,x} \in X_i\)

  • First quartile of the provided values for the independent variable: \(X_{Q1}\)

  • Third quartile of the provided values for the independent variable: \(X_{Q3}\)

  • Mean of all provided values for the dependent variable: \(\bar{y} = \frac{1}{n}\cdot{\sum\limits_{i=1}^n Y_i}\)

  • Resultant values for the coefficients of the sinusoidal model: \(C_i = \{ a, b, c, d \}\)

  • Standard form for the equation of the sinusoidal model: \(f(x) = a\cdot{\sin(b\cdot(x - c))} + d\)

  • First derivative of the sinusoidal model: \(f'(x) = ab\cdot{\cos(b\cdot(x - c))}\)

  • Second derivative of the sinusoidal model: \(f''(x) = -ab^2\cdot{\sin(b\cdot(x - c))}\)

  • Integral of the sinusoidal model: \(F(x) = -\frac{a}{b}\cdot{\cos(b\cdot(x - c))} + d\cdot{x}\)

  • Potential x-values of the roots of the sinusoidal model: \(x_{intercepts} = \{ c + \frac{1}{b}\cdot{\left(\sin^{-1}(-\frac{d}{a}) + 2\pi\cdot{k} \right)}, c + \frac{1}{b}\cdot{\left(-\sin^{-1}(-\frac{d}{a}) + \pi\cdot(2k - 1) \right)}, \\ c - \frac{\pi}{b}\cdot(2k - 1) \}\)

    • \(k \in \mathbb{Z}\)

  • Potential x-values of the maxima of the sinusoidal model: \(x_{maxima} = \{ c + \frac{\pi}{b}\cdot(\frac{1}{2} + k) \}\)

    • \(k \in \mathbb{Z}\)

  • Potential x-values of the minima of the sinusoidal model: \(x_{maxima} = \{ c + \frac{\pi}{b}\cdot(\frac{1}{2} + k) \}\)

    • \(k \in \mathbb{Z}\)

  • Potential x-values of the inflection points of the sinusoidal model: \(x_{inflections} = \{ c + \frac{\pi}{b}\cdot{k} \}\)

    • \(k \in \mathbb{Z}\)

  • Accumulatation of the sinusoidal model over its range: \(A_{range} = \int_{X_{min}}^{X_{max}} f(x) \,dx\)

  • Accumulatation of the sinusoidal model over its interquartile range: \(A_{iqr} = \int_{X_{Q1}}^{X_{Q3}} f(x) \,dx\)

  • Average rate of change of the sinusoidal model over its range: \(m_{range} = \frac{f(X_{max}) - f(X_{min})}{X_{max} - X_{min}}\)

  • Potential x-values at which the sinusoidal model’s instantaneous rate of change equals its average rate of change over its range: \(x_{m,range} = \{ c + \frac{1}{b}\cdot{\left(\cos^{-1}(\frac{m_{range}}{ab}) + \pi\cdot{k} \right)}, c + \frac{1}{b}\cdot{\left(-\cos^{-1}(\frac{m_{range}}{ab}) + 2\pi\cdot{k} \right)} \}\)

    • \(k \in \mathbb{Z}\)

  • Average value of the sinusoidal model over its range: \(v_{range} = \frac{1}{X_{max} - X_{min}}\cdot{A_{range}}\)

  • Potential x-values at which the sinusoidal model’s value equals its average value over its range: \(x_{v,range} = \{ c + \frac{1}{b}\cdot{\left(\sin^{-1}(-\frac{d - v_{range}}{a}) + 2\pi\cdot{k} \right)}, c + \frac{1}{b}\cdot{\left(-\sin^{-1}(-\frac{d - v_{range}}{a}) + \pi\cdot(2k - 1) \right)}, \\ c + \frac{\pi}{b}\cdot(2k - 1) \}\)

    • \(k \in \mathbb{Z}\)

  • Average rate of change of the sinusoidal model over its interquartile range: \(m_{iqr} = \frac{f(X_{Q3}) - f(X_{Q1})}{X_{Q3} - X_{Q1}}\)

  • Potential x-values at which the sinusoidal model’s instantaneous rate of change equals its average rate of change over its interquartile range: \(x_{m,iqr} = \{ c + \frac{1}{b}\cdot{\left(\cos^{-1}(\frac{m_{iqr}}{ab}) + \pi\cdot{k} \right)}, c + \frac{1}{b}\cdot{\left(-\cos^{-1}(\frac{m_{iqr}}{ab}) + 2\pi\cdot{k} \right)} \}\)

    • \(k \in \mathbb{Z}\)

  • Average value of the sinusoidal model over its interquartile range: \(v_{iqr} = \frac{1}{X_{Q3} - X_{Q1}}\cdot{A_{iqr}}\)

  • Potential x-values at which the sinusoidal model’s value equals its average value over its interquartile range: \(x_{v,iqr} = \{ c + \frac{1}{b}\cdot{\left(\sin^{-1}(-\frac{d - v_{iqr}}{a}) + 2\pi\cdot{k} \right)}, c + \frac{1}{b}\cdot{\left(-\sin^{-1}(-\frac{d - v_{iqr}}{a}) + \pi\cdot(2k - 1) \right)}, \\ c + \frac{\pi}{b}\cdot(2k - 1) \}\)

    • \(k \in \mathbb{Z}\)

  • Predicted values based on the sinusoidal model: \(\hat{y}_i = \{ \hat{y}_1, \hat{y}_2, \cdots, \hat{y}_n \}\)

  • Residuals of the dependent variable: \(e_i = \{ p_{1,y} - \hat{y}_1, p_{2,y} - \hat{y}_2, \cdots, p_{n,y} - \hat{y}_n \}\)

  • Deviations of the dependent variable: \(d_i = \{ p_{1,y} - \bar{y}, p_{2,y} - \bar{y}, \cdots, p_{n,y} - \bar{y} \}\)

  • Sum of squares of residuals: \(SS_{res} = \sum\limits_{i=1}^n e_i^2\)

  • Sum of squares of deviations: \(SS_{dev} = \sum\limits_{i=1}^n d_i^2\)

  • Correlation coefficient for the sinusoidal model: \(r = \sqrt{1 - \frac{SS_{res}}{SS_{dev}}}\)

  • Regression Analysis

Examples

Import sinusoidal_model function from regressions library
>>> from regressions.models.sinusoidal import sinusoidal_model
Generate a sinusoidal regression model for the data set [[1, 3], [2, 8], [3, 3], [4, -2], [5, 3], [6, 8], [7, 3], [8, -2], [9, 3], [10, 8]], then print its coefficients, roots, total accumulation over its interquartile range, and correlation
>>> model_perfect = sinusoidal_model([[1, 3], [2, 8], [3, 3], [4, -2], [5, 3], [6, 8], [7, 3], [8, -2], [9, 3], [10, 8]])
>>> print(model_perfect['constants'])
[-5.0, 1.5708, 3.0, 3.0]
>>> print(model_perfect['points']['roots'])
[[3.4097, 0.0], [4.5903, 0.0], [7.4097, 0.0], [8.5903, 0.0], ['3.4097 + 4.0k', 0.0], ['4.5903 + 4.0k', 0.0]]
>>> print(model_perfect['accumulations']['iqr'])
11.8168
>>> print(model_perfect['correlation'])
1.0
Generate a sinusoidal regression model for the data set [[1, 32], [2, 25], [3, 14], [4, 23], [5, 39], [6, 45], [7, 42], [8, 49], [9, 36], [10, 33]], then print its coefficients, inflections, total accumulation over its range, and correlation
>>> model_agnostic = sinusoidal_model([[1, 32], [2, 25], [3, 14], [4, 23], [5, 39], [6, 45], [7, 42], [8, 49], [9, 36], [10, 33]])
>>> print(model_agnostic['constants'])
[14.0875, 0.7119, -3.7531, 34.2915]
>>> print(model_agnostic['points']['inflections'])
[[5.0729, 34.2915], [9.4859, 34.2915], [13.8985, 34.2915], [18.3114, 34.2915], ['5.0729 + 4.413k', 34.2915]]
>>> print(model_agnostic['accumulations']['range'])
307.8897
>>> print(model_agnostic['correlation'])
0.9264