Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract formula call from schema #296

Open
DominiqueMakowski opened this issue Jun 17, 2023 · 0 comments
Open

Extract formula call from schema #296

DominiqueMakowski opened this issue Jun 17, 2023 · 0 comments

Comments

@DominiqueMakowski
Copy link

DominiqueMakowski commented Jun 17, 2023

Say I am interested in getting things like the model matrix and coef names from a formula. As far as I'm aware, the current shortest method to do that is:

using DataFrames
using StatsModels

df = DataFrame(x = rand(100), y = rand(100))

f = @formula(y ~ 1 + x)
f = apply_schema(f, schema(f, df))

modelmatrix(f, df)
coefnames(f)

I was wondering whether it was possible to add a method to extract back the formula call from schema(f, df), which would then allow us to make apply_schema() dispatch directly on a schema and get all the necessary info, and be able to write something like

f = apply_schema(schema(@formula(y ~ 1 + x), df))

# Or 

f = schema(@formula(y ~ 1 + x), df) |> 
        apply_schema

Alternatively, this would allow other methods to implicitly call apply_schema() on a schema. I am not familiar with the code base so I'm not sure this makes sense, but I think in essence what I am asking is ways to reduce the repeated input of the same objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant