I am trying to write some code to perform a statistical test called model-reduction. Basically what I want to know is whether each variable in my function makes a meaningful contribution (i.e. significantly explains variance). Say for example my original fit-function looks like this:
full_model(x, a, b, c, d):
return a + b*x + c*x**3 + sin(d*x)
I want to compare reduced forms of this model. The once I need to check are:
reduced = lambda x, b, c, d: full_model(x, 0, b, c, d)
reduced = lambda x, a, c, d: full_model(x, a, 0, c, d)
reduced = lambda x, a, b, d: full_model(x, a, b, 0, d)
reduced = lambda x, a, b, c: full_model(x, a, b, c, 0)
For each case, I run some sort of test that I don't go into detail:
compare_models(full_model, reduced, x, y)
In reality, my fit function has more parameters, and I want test even further reduced functions. The code will be really messy if I have to explicitly define all possible models. Is there any way to define the reduced function in a for-loop? And is there any existing python module that can achieve what I want to do?
question from:
https://stackoverflow.com/questions/65916938/iterating-functions-definitions-based-on-a-parent-function