codedthinking / Kezdi.jl

An umbrella of Julia packages for data analysis, in loving memory of Gábor Kézdi
Other
9 stars 0 forks source link

Refactor #69

Closed korenmiklos closed 5 days ago

korenmiklos commented 5 days ago
  1. All command rewrites moved to rewrites.jl. Helper functions remained in codegen.jl.
  2. For simpler commands, all setup code (bitmask, creating sdf, checking for syntax) is prewritten. You can just add $setup to the beginning of the quote block.
  3. $teardown is a function that passes through the argument given to it, while executing some side effects necessary to finish the command. For example, removing _n if it was added to the df.

So, the typical use case is:

function rewrite(::Val{:regress}, command::Command)
    gc = generate_command(command; options=[:variables, :ifable])
    (; df, local_copy, sdf, gdf, setup, teardown, arguments) = gc
    quote
        $setup
        reg($sdf, @formula $(arguments[1]) ~ $(sum(arguments[2:end]))) |> $teardown
    end |> esc
end
korenmiklos commented 5 days ago
julia> @regress df a _n @if _n < _N
[ Info: The variance-covariance matrix is not invertible. F-statistic not computed
                            FixedEffectModel
=========================================================================
Number of obs:                    9   Converged:                     true
dof (model):                      1   dof (residuals):                  6
R²:                           1.000   R² adjusted:                  1.000
F-statistic:                    NaN   P-value:                        NaN
=========================================================================
             Estimate  Std. Error  t-stat  Pr(>|t|)  Lower 95%  Upper 95%
─────────────────────────────────────────────────────────────────────────
_n                1.0         0.0     Inf    <1e-99        1.0        1.0
(Intercept)       0.0         0.0    NaN     NaN           0.0        0.0
=========================================================================

julia> df
10×1 DataFrame
 Row │ a
     │ Int64
─────┼───────
   1 │     1
   2 │     2
   3 │     3
   4 │     4
   5 │     5
   6 │     6
   7 │     7
   8 │     8
   9 │     9
  10 │    10