signaturescience / focustools

Forecasting COVID-19 in the US
https://signaturescience.github.io/focustools/
GNU General Public License v3.0
0 stars 0 forks source link

Retrieve ARIMA params #49

Closed stephenturner closed 3 years ago

stephenturner commented 3 years ago

In addition to extracting p,d,q parameters I'm also grabbing the results from tidy() and glance() on the model object. You'll note that we have more rows than we have locations. In the case where p>1, tidy() returns >1 row for each AR term. For example, see location=13. To get one row per location, remove the term:p.value columns and %>% to dplyr::distinct().

# A tibble: 61 x 22
   location abbreviation location_name        .model     p     d     q     P     D     Q constant period term  estimate std.error statistic    p.value      sigma2 log_lik   AIC  AICc   BIC
   <chr>    <chr>        <chr>                <chr>  <int> <int> <dbl> <dbl> <dbl> <dbl> <lgl>     <dbl> <chr>    <dbl>     <dbl>     <dbl>      <dbl>       <dbl>   <dbl> <dbl> <dbl> <dbl>
 1 01       AL           Alabama              arima      1     1     0     0     0     0 FALSE        52 ar1     0.119      0.138     0.862 0.393         6803599.   -473.  950.  950.  954.
 2 02       AK           Alaska               arima      1     1     0     0     0     0 FALSE        52 ar1     0.314      0.131     2.40  0.0203         130624.   -372.  749.  749.  752.
 3 04       AZ           Arizona              arima      1     1     0     0     0     0 FALSE        52 ar1     0.437      0.124     3.53  0.000883     24464040.   -506. 1016. 1016. 1019.
 4 05       AR           Arkansas             arima      1     1     0     0     0     0 FALSE        52 ar1     0.213      0.136     1.56  0.124         2699882.   -450.  903.  903.  907.
 5 06       CA           California           arima      1     1     0     0     0     0 FALSE        52 ar1     0.567      0.112     5.04  0.00000615  417944259.   -578. 1161. 1161. 1164.
 6 08       CO           Colorado             arima      1     1     0     0     0     0 FALSE        52 ar1     0.479      0.120     3.98  0.000220      5976355.   -470.  944.  944.  948.
 7 09       CT           Connecticut          arima      1     1     0     0     0     0 FALSE        52 ar1    -0.0241     0.139    -0.174 0.863         4415999.   -462.  928.  928.  932.
 8 10       DE           Delaware             arima      1     1     0     0     0     0 FALSE        52 ar1     0.166      0.137     1.22  0.230          259699.   -390.  784.  784.  787.
 9 11       DC           District of Columbia arima      1     1     0     0     0     0 FALSE        52 ar1     0.187      0.137     1.36  0.179           37155.   -340.  684.  685.  688.
10 12       FL           Florida              arima      1     1     0     0     0     0 FALSE        52 ar1     0.392      0.127     3.10  0.00319      75487902.   -535. 1073. 1073. 1077.
11 13       GA           Georgia              arima      2     1     0     0     0     0 FALSE        52 ar1    -0.121      0.134    -0.906 0.369        50720034.   -524. 1054. 1054. 1059.
12 13       GA           Georgia              arima      2     1     0     0     0     0 FALSE        52 ar2     0.237      0.133     1.78  0.0810       50720034.   -524. 1054. 1054. 1059.
13 15       HI           Hawaii               arima      1     1     0     0     0     0 FALSE        52 ar1     0.436      0.124     3.51  0.000960        24013.   -329.  662.  663.  666.
14 16       ID           Idaho                arima      1     1     0     0     0     0 FALSE        52 ar1     0.397      0.127     3.14  0.00280        544093.   -409.  821.  822.  825.
15 17       IL           Illinois             arima      1     1     0     0     0     0 FALSE        52 ar1     0.510      0.118     4.34  0.0000679    31693591.   -512. 1029. 1029. 1033.
16 18       IN           Indiana              arima      1     1     0     0     0     0 FALSE        52 ar1     0.470      0.121     3.89  0.000295      9245792.   -481.  966.  966.  970.
17 19       IA           Iowa                 arima      1     1     0     0     0     0 FALSE        52 ar1    -0.492      0.159    -3.09  0.00327      30029186.   -511. 1026. 1026. 1030.
18 20       KS           Kansas               arima      1     1     0     0     0     0 FALSE        52 ar1    -0.0221     0.140    -0.158 0.875         4301512.   -461.  927.  927.  931.
19 21       KY           Kentucky             arima      1     1     0     0     0     0 FALSE        52 ar1     0.207      0.136     1.53  0.133         4815370.   -464.  933.  933.  936.
20 22       LA           Louisiana            arima      1     1     0     0     0     0 FALSE        52 ar1     0.133      0.138     0.962 0.341         8915334.   -480.  964.  964.  968.
21 23       ME           Maine                arima      2     1     0     0     0     0 FALSE        52 ar1     0.262      0.134     1.96  0.0559          81764.   -360.  726.  726.  732.
22 23       ME           Maine                arima      2     1     0     0     0     0 FALSE        52 ar2     0.284      0.135     2.10  0.0411          81764.   -360.  726.  726.  732.
23 24       MD           Maryland             arima      1     1     0     0     0     0 FALSE        52 ar1     0.332      0.130     2.55  0.0138        2776697.   -450.  905.  905.  908.
24 25       MA           Massachusetts        arima      1     1     0     0     0     0 FALSE        52 ar1     0.496      0.119     4.18  0.000116      8118517.   -478.  959.  960.  963.
25 26       MI           Michigan             arima      1     1     0     0     0     0 FALSE        52 ar1     0.595      0.110     5.43  0.00000158   11139042.   -486.  976.  976.  980.
26 27       MN           Minnesota            arima      1     1     0     0     0     0 FALSE        52 ar1     0.544      0.114     4.76  0.0000166    11187270.   -486.  976.  976.  980.
27 28       MS           Mississippi          arima      1     1     0     0     0     0 FALSE        52 ar1     0.126      0.137     0.915 0.365         2503943.   -448.  899.  899.  903.
28 29       MO           Missouri             arima      1     1     0     0     0     0 FALSE        52 ar1     0.170      0.137     1.25  0.218         8297503.   -478.  960.  961.  964.
29 30       MT           Montana              arima      1     1     0     0     0     0 FALSE        52 ar1     0.126      0.138     0.918 0.363          450897.   -404.  812.  812.  816.
30 31       NE           Nebraska             arima      2     1     0     0     0     0 FALSE        52 ar1     0.112      0.131     0.856 0.396         1636719.   -436.  879.  879.  884.
31 31       NE           Nebraska             arima      2     1     0     0     0     0 FALSE        52 ar2     0.308      0.133     2.32  0.0241        1636719.   -436.  879.  879.  884.
32 32       NV           Nevada               arima      1     1     0     0     0     0 FALSE        52 ar1     0.296      0.132     2.25  0.0290        2548072.   -448.  900.  900.  904.
33 33       NH           New Hampshire        arima      1     1     0     0     0     0 FALSE        52 ar1     0.402      0.127     3.16  0.00264        182025.   -381.  766.  766.  769.
34 34       NJ           New Jersey           arima      2     1     0     0     0     0 FALSE        52 ar1     0.259      0.136     1.91  0.0617       13046431.   -489.  985.  985.  990.
35 34       NJ           New Jersey           arima      2     1     0     0     0     0 FALSE        52 ar2     0.227      0.138     1.64  0.106        13046431.   -489.  985.  985.  990.
36 35       NM           New Mexico           arima      1     1     0     0     0     0 FALSE        52 ar1     0.307      0.131     2.33  0.0236        1564401.   -436.  875.  875.  879.
37 36       NY           New York             arima      2     1     0     0     0     0 FALSE        52 ar1     0.715      0.136     5.27  0.00000275   59771612.   -528. 1062. 1063. 1068.
38 36       NY           New York             arima      2     1     0     0     0     0 FALSE        52 ar2    -0.215      0.136    -1.57  0.122        59771612.   -528. 1062. 1063. 1068.
39 37       NC           North Carolina       arima      1     1     0     0     0     0 FALSE        52 ar1     0.438      0.125     3.52  0.000930     10394222.   -484.  972.  972.  976.
40 38       ND           North Dakota         arima      1     1     0     0     0     0 FALSE        52 ar1     0.433      0.124     3.50  0.000985       486002.   -406.  816.  816.  820.
41 39       OH           Ohio                 arima      1     1     0     0     0     0 FALSE        52 ar1     0.0820     0.138     0.594 0.555        46077293.   -522. 1048. 1048. 1052.
42 40       OK           Oklahoma             arima      2     1     0     0     0     0 FALSE        52 ar1     0.198      0.136     1.46  0.150         6839443.   -473.  951.  952.  957.
43 40       OK           Oklahoma             arima      2     1     0     0     0     0 FALSE        52 ar2    -0.218      0.137    -1.59  0.119         6839443.   -473.  951.  952.  957.
44 41       OR           Oregon               arima      1     1     0     0     0     0 FALSE        52 ar1     0.277      0.133     2.09  0.0419         619754.   -412.  828.  828.  832.
45 42       PA           Pennsylvania         arima      1     1     0     0     0     0 FALSE        52 ar1     0.481      0.120     4.00  0.000206     17868152.   -498.  999.  999. 1003.
46 44       RI           Rhode Island         arima      2     1     0     0     0     0 FALSE        52 ar1     0.163      0.130     1.25  0.216          963973.   -423.  852.  852.  857.
47 44       RI           Rhode Island         arima      2     1     0     0     0     0 FALSE        52 ar2    -0.351      0.128    -2.74  0.00839        963973.   -423.  852.  852.  857.
48 45       SC           South Carolina       arima      1     1     0     0     0     0 FALSE        52 ar1     0.190      0.139     1.37  0.177         8351922.   -478.  961.  961.  964.
49 46       SD           South Dakota         arima      2     1     0     0     0     0 FALSE        52 ar1     0.177      0.131     1.36  0.181          468664.   -404.  815.  815.  821.
50 46       SD           South Dakota         arima      2     1     0     0     0     0 FALSE        52 ar2     0.303      0.130     2.33  0.0238         468664.   -404.  815.  815.  821.
51 47       TN           Tennessee            arima      1     1     0     0     0     0 FALSE        52 ar1     0.373      0.128     2.91  0.00532      18879300.   -499. 1002. 1003. 1006.
52 48       TX           Texas                arima      1     1     0     0     0     0 FALSE        52 ar1    -0.0208     0.142    -0.147 0.884       295199186.   -569. 1142. 1143. 1146.
53 49       UT           Utah                 arima      1     1     0     0     0     0 FALSE        52 ar1     0.304      0.132     2.30  0.0253        3549280.   -457.  917.  917.  921.
54 50       VT           Vermont              arima      1     1     0     0     0     0 FALSE        52 ar1    -0.0472     0.139    -0.340 0.735           12522.   -312.  629.  629.  633.
55 51       VA           Virginia             arima      2     1     0     0     0     0 FALSE        52 ar1     0.166      0.130     1.27  0.209         7242583.   -474.  955.  955.  960.
56 51       VA           Virginia             arima      2     1     0     0     0     0 FALSE        52 ar2     0.319      0.137     2.32  0.0243        7242583.   -474.  955.  955.  960.
57 53       WA           Washington           arima      1     1     0     0     0     0 FALSE        52 ar1    -0.489      0.120    -4.09  0.000155     10242949.   -484.  971.  971.  975.
58 54       WV           West Virginia        arima      1     1     0     0     0     0 FALSE        52 ar1     0.401      0.126     3.18  0.00254        449098.   -404.  812.  812.  816.
59 55       WI           Wisconsin            arima      1     1     0     0     0     0 FALSE        52 ar1    -0.0290     0.139    -0.209 0.835        22033006.   -503. 1010. 1010. 1014.
60 56       WY           Wyoming              arima      1     1     0     0     0     0 FALSE        52 ar1     0.474      0.121     3.93  0.000260       164321.   -378.  760.  761.  764.
61 US       US           US                   arima      1     1     0     0     0     0 FALSE        52 ar1     0.528      0.116     4.55  0.0000339  9418039563.   -658. 1319. 1320. 1323.
stephenturner commented 3 years ago

False start earlier, better now.

vpnagraj commented 3 years ago

@stephenturner this is great.

i ran through the code. pretty sure i track what its doing. made one minor change to the submission script (removing the plausibility check and replacing it with a inline comment)

last thing before i merge ... i want to build the pkg and test in our automation pipeline. if that generates a submission and params file i'll go ahead and merge this and close #48

vpnagraj commented 3 years ago

also just noting here (because i didnt see it at first in the rendered tibble in your comment) ... this param output includes the AIC, BIC, etc from each model ... so we can theoretically retrospectively try different params and compare / better understand the criteria by which the model was selected.

stephenturner commented 3 years ago

also just noting here (because i didnt see it at first in the rendered tibble in your comment) ... this param output includes the AIC, BIC, etc from each model ... so we can theoretically retrospectively try different params and compare / better understand the criteria by which the model was selected.

I went back and forth on whether to include output from tidy() - that's what brings in coefficients and term p-values. glance() adds the AIC, BIC, etc.. If we remove the results from tidy() we'll have one row per location.

vpnagraj commented 3 years ago

hmmm ok. i dont think its a big deal to parse with distinct() ? and i do like having that model output for posterity. so (at least for now) my opinion is to leave in

vpnagraj commented 3 years ago

cool. just forced the automation pipeline to run. workflow executed fine and submission and param csv files were written to S3 as expected.

merging