-
Notifications
You must be signed in to change notification settings - Fork 31
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
method for human to make formula with FunctionTerm #232
Comments
My current workaround: function single_functional_term(f, x)
symbol = Expr(:call, Symbol(f), x)
fanon = eval(:(($x,) -> log($x)))
StatsModels.capture_call(f, fanon, (x,), symbol, [Term(x)])
end
f = let res = Term(:y)
pres = mapreduce(vcat, 1:3) do i
s = Symbol("x$i")
[Term(s), single_functional_term(log, s)]
end
FormulaTerm(res, (pres...,))
end It doesn't work on multiple arity functions though, like My second hack by abusing the @formula macro: function functional_term(f, arg_expr...)
expr = Expr(:call, Symbol(f), arg_expr...)
eval(:(@formula somethingsomethingvarhopefullynodup ~ $expr)).rhs
end
t1 = functional_term(log, :(x * y))
t2 = functional_term(*, :x, :y)
t3 = functional_term(*, [Symbol("x$i") for i in 1:4]...)
display(t1)
# (x,y)->log(x * y)
display(t2)
# x(unknown)
# y(unknown)
# x(unknown) & y(unknown)
display(t3)
# x1(unknown)
# x2(unknown)
# x3(unknown)
# x4(unknown)
# x1(unknown) & x2(unknown)
# x1(unknown) & x3(unknown)
# x2(unknown) & x3(unknown)
# x1(unknown) & x4(unknown)
# x2(unknown) & x4(unknown)
# x3(unknown) & x4(unknown)
# x1(unknown) & x2(unknown) & x3(unknown)
# x1(unknown) & x2(unknown) & x4(unknown)
# x1(unknown) & x3(unknown) & x4(unknown)
# x2(unknown) & x3(unknown) & x4(unknown)
# x1(unknown) & x2(unknown) & x3(unknown) & x4(unknown) |
There's definitely no reason to deal with |
seems second case not working with GLM |
#183 is merged and there are examples in the tests of how to create function terms programatically! |
Method for human to make formula with FunctionTerm in expression.
I try to make dynamic formula like this:
for simple Term it easy:
at the end i get:
The text was updated successfully, but these errors were encountered: