alexpghayes / modelling-in-r

an initial attempt to describe a grammar of modelling for r
https://alexpghayes.github.io/modelling-in-r/
3 stars 0 forks source link

When formulas specify model parameters rather than data design #28

Open alexpghayes opened 6 years ago

alexpghayes commented 6 years ago

A la

fGarch::garchFit(~arma(1, 0) + garch(1, 0),
                 data = fGarch::dem2gbp, trace = FALSE)
#> 
#> Title:
#>  GARCH Modelling 
#> 
#> Call:
#>  fGarch::garchFit(formula = ~arma(1, 0) + garch(1, 0), data = fGarch::dem2gbp, 
#>     trace = FALSE) 
#> 
#> Mean and Variance Equation:
#>  data ~ arma(1, 0) + garch(1, 0)
#> <environment: 0x000000000909ce40>
#>  [data = fGarch::dem2gbp]
#> 
#> Conditional Distribution:
#>  norm 
#> 
#> Coefficient(s):
#>          mu          ar1        omega       alpha1  
#> -0.00163520   0.00080844   0.14652820   0.37080537  
#> 
#> Std. Errors:
#>  based on Hessian 
#> 
#> Error Analysis:
#>          Estimate  Std. Error  t value Pr(>|t|)    
#> mu     -0.0016352   0.0093710   -0.174    0.861    
#> ar1     0.0008084   0.0296164    0.027    0.978    
#> omega   0.1465282   0.0064137   22.846   <2e-16 ***
#> alpha1  0.3708054   0.0438546    8.455   <2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Log Likelihood:
#>  -1206.532    normalized:  -0.6112118 
#> 
#> Description:
#>  Thu Apr 05 09:54:29 2018 by user: alex

I like this interface but it raises a question about the appropriate way to specify model parameters (as opposed to hyperparameters). Or maybe the question is whether the ARMA and GARCH values are parameters or hyperparameters. Also, the model fitting process here is very iterative working with a single model at a time, then comparing several models at the end. I think this is a good canonical example of a workflow that needs to be supported.

alexpghayes commented 6 years ago

Additionally, the estimatr::lm_robust cluster argument

alexpghayes commented 6 years ago

Should bare/unquoted variables be a standard? Or should formulas? But would standard formula semantics make sense or would that be overloading the formula operator (I suspect it would).

An example of just passing model parameters directly as arguments: astsa::sarima(sunspots, 1, 2, 0)