UnboundLocalError when using design matrix
I'm trying to use a design matrix to run a simple test, in place of a formula but I cannot use due to this error:
>>> dmat_flat = de.utils.design_matrix(data = adata, formula="~0 + groups")
>>> test_flat = de.test.wald(
data = adata,
dmat_loc=dmat_flat[0],
)
UnboundLocalError Traceback (most recent call last)
<ipython-input-167-850899a8ac49> in <module>
1 test_flat = de.test.wald(
2 data = adata,
----> 3 dmat_loc=dmat_flat[0],
4
5 )
~/anaconda3/envs/graph-tool/lib/python3.7/site-packages/diffxpy/testing/tests.py in wald(data, factor_loc_totest, coef_to_test, formula_loc, formula_scale, as_numeric, init_a, init_b, gene_names, sample_description, dmat_loc, dmat_scale, constraints_loc, constraints_scale, noise_model, size_factors, batch_size, backend, train_args, training_strategy, quick_scale, dtype, **kwargs)
651 as_numeric=as_numeric,
652 constraints=constraints_loc,
--> 653 return_type="patsy"
654 )
655 design_scale, design_scale_names, constraints_scale, term_names_scale = constraint_system_from_star(
~/anaconda3/envs/graph-tool/lib/python3.7/site-packages/diffxpy/testing/utils.py in constraint_system_from_star(dmat, sample_description, formula, as_numeric, constraints, return_type)
270 as_categorical=as_categorical,
271 constraints=constraints,
--> 272 return_type=return_type
273 )
274
~/anaconda3/envs/graph-tool/lib/python3.7/site-packages/batchglm/data.py in constraint_system_from_star(dmat, sample_description, formula, as_categorical, constraints, return_type)
259 )
260
--> 261 return dmat, coef_names, cmat, term_names
262
263
UnboundLocalError: local variable 'coef_names' referenced before assignment
Note that I'm not sure how to pass a design matrix in place of a formula, I was performing some usage test...
You still have to declare a coefficient that you want to test right now you just gave .wald() instructions for fitting a GLM but not which coefficient to test. I guess you want to test the group parameter, you have to define this as a subset of all model parameters using factor_loc_totest or coef_to_test!
I have the very same error if coef_to_test is specified (btw, factor_loc_totest is not supported when dmat_loc is given)
I have the very same error if
coef_to_testis specified (btw,factor_loc_totestis not supported whendmat_locis given)
can you post the exact code you are using when specifying coef_to_test? for now could just give wald the formula instead of building it yourself first? that makes parsing easier, also the reason via factors are not supported in this mode
Given the design matrix above
dmat_flat = de.utils.design_matrix(data = adata, formula="~0 + groups")
I use the list of coefficients names in the second element of the tuple
de.test.wald(
data = adata,
dmat_loc=dmat_flat[0],
coef_to_test=dmat_flat[1])
or any subset of it