regression-tests.bootstrap

accuracy-percentiles

(accuracy-percentiles y x values samples)
Runs bootstrapping to estimate confidence intervals
for the accuracy to the specified values in another sample.
   y: A list of dependent variable values.
   x: A list of predictors.
   values: A hash-map of observations and predictors in another sample.
   samples: A list of bootstrapped samples (indexes).
returns: A hash-map with lower and upper bounds of the 95% confidence
        quartile interval and boostrap quartile samples.

## Usage

   (require '[regression-tests.bootstrap :refer :all])

   (def y [1.1 1 0.95 1.15 2.1 2.05 3 3.01 3.02 2.9])
   (def x [[1 1 4] [2 3 2] [2 2 3] [1.5 1.5 1.5] [3 3.1 5] [3.5 3 5.5]
           [4 3 6] [3.8 2.5 6.3] [3.9 2.7 6.5] [4.2 3.4 6]])

   (def with-replacement [[0 1 2 0 4 5 6 7 8 6]
                          [0 1 5 3 5 5 6 7 0 9]
                          [0 1 2 3 5 5 6 7 8 9]
                          [0 1 2 3 4 5 8 7 8 9]])

   (def cells {:y [1 1.4 3.4]
               :urban [1 2 1]
               :x [[1 1 1] [1.1 1.3 1.1] [3 4 1]]})


   (accuracy-percentiles y x cells with-replacement)
   =>
       {:sample {:p-min [0.7325939406113093 0.09426067621289036 0.1313719684139727 0.2726825935013899 0.2694252999022879],
                 :p-25-percent [0.7325939406113093 0.09426067621289036 0.1313719684139727 0.2726825935013899 0.2694252999022879],
                 :p-50-percent [1.0906469325799546 0.39726963364663037 0.5991781261463421 0.694437572706074 0.6910235979522977],
                 :p-75-percent [2.4663489187595444 2.1983467121001516 2.271866486743393 2.2249032313817714 2.194299660522469],
                 :p-max [2.4663489187595444 2.1983467121001516 2.271866486743393 2.2249032313817714 2.194299660522469]},
        :p-value {['all' :p-min] [0.09426067621289036 0.7325939406113093 0.30006689572837003],
                  ['all' :p-25-percent] [0.09426067621289036 0.7325939406113093 0.30006689572837003],
                  ['all' :p-50-percent] [0.39726963364663037 1.0906469325799546 0.6945111726062597],
                  ['all' :p-75-percent] [2.194299660522469 2.4663489187595444 2.271153001901466],
                  ['all' :p-max] [2.194299660522469 2.4663489187595444 2.271153001901466],

                  [1 :p-min] [0.09426067621289036 0.7325939406113093 0.30006689572837003],
                  [1 :p-25-percent] [0.09426067621289036 0.7325939406113093 0.30006689572837003],
                  [1 :p-75-percent] [2.194299660522469 2.4663489187595444 2.271153001901466],
                  [1 :p-50-percent] [0.09426067621289036 0.7325939406113093 0.30006689572837003],
                  [1 :p-max] [2.194299660522469 2.4663489187595444 2.271153001901466],

                  [2 :p-min] [0.39726963364663037 1.0906469325799546 0.6945111726062597],
                  [2 :p-25-percent] [0.39726963364663037 1.0906469325799546 0.6945111726062597],
                  [2 :p-50-percent] [0.39726963364663037 1.0906469325799546 0.6945111726062597],
                  [2 :p-75-percent] [0.39726963364663037 1.0906469325799546 0.6945111726062597],
                  [2 :p-max] [0.39726963364663037 1.0906469325799546 0.6945111726062597]}}

 ## References
     [1] Efron, B., & Tibshirani, R. (1993). An Introduction to the Bootstrap.
         New York: Chapman and Hall.

regression-stats-percentiles

(regression-stats-percentiles y x samples)
Runs bootstrapping to estimate confidence intervals
 for the set of statistics in the regression model (using percentile bootstrapping).
    y: A list of dependent variable values.
    x: A list of predictors.
    samples: A list of bootstrapped samples (indexes).
 returns: A hash-map with lower and upper bounds of the
          95% confidence interval.

## Usage

  (require '[regression-tests.bootstrap :refer :all])

  (def y [1.1 1 0.95 1.15 2.1 2.05 3 3.01 3.02 2.9])
  (def x [[1 1 4] [2 3 2] [2 2 3] [1.5 1.5 1.5] [3 3.1 5] [3.5 3 5.5]
          [4 3 6] [3.8 2.5 6.3] [3.9 2.7 6.5] [4.2 3.4 6]])

  (def with-replacement [[0 1 2 0 4 5 6 7 8 6]
                         [0 1 5 3 5 5 6 7 0 9]
                         [0 1 2 3 5 5 6 7 8 9]
                         [0 1 2 3 4 5 8 7 8 9]])

  (regression-stats-percentiles y x with-replacement)
  =>
     {:r-squared [0.9401664271263236 0.9573638262472198 0.9485972809614914],
      :mse [0.05119649671254231 0.07484392157787506 0.0625135321898773],
      :coefficients [[0.5095454591100292 1.0084063307610052 0.8108528980792314]
                     [-0.6364733499450175 -0.11761529878943122 -0.41016539093890503]
                     [-0.014289379521162715 0.26277051757180914 0.09815780110702263]
                     [-0.3872946185037165 0.7366170749180654 0.23879206650943702]]}

## References
    [1] Efron, B., & Tibshirani, R. (1993). An Introduction to the Bootstrap.
        New York: Chapman and Hall.

residuals-independence

(residuals-independence y x neighbours samples)
Returns bootstrap estimates for tests
related to independence of the residuals.
   y: A list of dependent variable values.
   x: A list of predictors.
   neighbours: A hash-map with neighbours.
   samples: A list of bootstrapped samples (indexes).
returns: A hash-map with lower and upper bounds of the 95% confidence
         interval and mean of test statistic and p-value for
         1) Moran's I bootstrap test.
         2) Geary's C bootstrap test (for population)
         and boostrap samples for each indicator.

## Usage

   (require '[regression-tests.bootstrap :refer :all])

   (def y [1.1 1 0.95 1.15 2.1 2.05 3 3.01 3.02 2.9])
   (def x [[1 1 4] [2 3 2] [2 2 3] [1.5 1.5 1.5] [3 3.1 5] [3.5 3 5.5]
           [4 3 6] [3.8 2.5 6.3] [3.9 2.7 6.5] [4.2 3.4 6]])

   (def with-replacement [[0 1 2 0 4 5 6 7 8 6]
                          [0 1 5 3 5 5 6 7 0 9]
                          [0 1 2 3 5 5 6 7 8 9]
                          [0 1 2 3 4 5 8 7 8 9]])

   (def neighbours-matrix {0 [1 5] 1 [0] 3 [9] 5 [0 7 8 9] 7 [5] 8 [5] 9 [3 5]})

   (residuals-independence y x neighbours-matrix with-replacement)
   =>
       {:samples {:morans-i-stat [-0.45324978913939	-0.497197740828216 -0.184984968964908	-0.298642827973139 -0.27016109547253],
                  :geary-c-stat [2.35284987913462 1.38087785015786 0.953671521804377 1.45717331902477 1.42817391460185]},
        :tests {:morans-i-test [-0.497197740828216 -0.184984968964908 -0.340847284475637 2/5],
                :geary-c-test [0.953671521804377 2.35284987913462 1.51454929694469 4/5]}}

## References
    [1] Efron, B., & Tibshirani, R. (1993). An Introduction to the Bootstrap.
        New York: Chapman and Hall.
    [2] Geary, R. (1954). The Contiguity Ratio and Statistical Mapping.
        The Incorporated Statistician, 5(3): 115-145. DOI: 10.2307/2986645.
    [3] Moran, P. (1950). Notes on Continuous Stochastic Phenomena.
        Biometrika, 37(1-2): 17-23. DOI: 10.2307/2332142.
    [4] Lin, K.-P., Long, Z.-H., & Ou, B. (2011). The Size and Power of Bootstrap Tests for Spatial Dependence in a Linear Regression Model.
        Computational Economics, 38(2): 153-171. DOI: 10.1007/s10614-010-9224-0.