# Songbird error: local variable 'i' referenced before assignment

**URL:** <https://forum.qiime2.org/t/songbird-error-local-variable-i-referenced-before-assignment/20175>\
**Category:** Library Support\
**Tags:** q2-songbird\
**Created:** [July 13, 2021, 12:03pm UTC](https://forum.qiime2.org/t/songbird-error-local-variable-i-referenced-before-assignment/20175 "2021-07-13T12:03:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pau](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/p/2bfe46/32.png) [@pau](https://forum.qiime2.org/u/pau)\
**Post date:** [July 13, 2021, 12:03pm UTC](https://forum.qiime2.org/t/songbird-error-local-variable-i-referenced-before-assignment/20175/1 "2021-07-13T12:03:43Z")

</div>

Dear community,

I came up with a difficult error when performing q2-songbird suggested pipeline. Need to say that I previously ran exactly the same command (but using another feature table) and it was executed successfully.

I also saw that could be a metadata related error ([longitudinal pairwise difference error](https://forum.qiime2.org/t/longitudinal-pairwise-difference-error/12389)), but after checking carefully my metadata I discarded this option. Moreover, I had no problems running alfa and beta diversity metrics.

The command (from a genus-level collapsed table):

qiime songbird multinomial   
--i-table ancom-24/table-patology-l6.qza   
--m-metadata-file metadata-24.tsv   
--p-formula "type"   
--p-epochs 1000000   
--p-differential-prior 0.1   
--p-summary-interval 1   
--p-learning-rate 0.0001   
--p-batch-size 8   
--o-differentials songbird/24/differentials-l6.qza   
--o-regression-stats songbird/24/regression-stats-l6.qza   
--o-regression-biplot songbird/24/regression-biplot-l6.qza   
--verbose

The error:

Traceback (most recent call last):  
File "/home/pau/miniconda3/envs/qiime2-2020.6/lib/python3.6/site-packages/q2cli/commands.py", line 329, in **call**  
results = action(\*\*arguments)  
File "", line 2, in multinomial  
File "/home/pau/miniconda3/envs/qiime2-2020.6/lib/python3.6/site-packages/qiime2/sdk/action.py", line 245, in bound\_callable  
output\_types, provenance)  
File "/home/pau/miniconda3/envs/qiime2-2020.6/lib/python3.6/site-packages/qiime2/sdk/action.py", line 390, in _callable\_executor_  
output\_views = self.\_callable(\*\*view\_args)  
File "/home/pau/miniconda3/envs/qiime2-2020.6/lib/python3.6/site-packages/songbird/q2/\_method.py", line 69, in multinomial  
silent=silent)  
File "/home/pau/miniconda3/envs/qiime2-2020.6/lib/python3.6/site-packages/songbird/multinomial.py", line 213, in fit  
iter\_n.append(i)  
UnboundLocalError: local variable 'i' referenced before assignment

Plugin error from songbird:

local variable 'i' referenced before assignment

See above for debug info.

**Thanks a lot in advance** 🙂

---

<div class="post-metadata">

**Author:** ![dwt](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@dwt](https://forum.qiime2.org/u/dwt)\
**Post date:** [July 13, 2021, 1:50pm UTC](https://forum.qiime2.org/t/songbird-error-local-variable-i-referenced-before-assignment/20175/2 "2021-07-13T13:50:15Z")

</div>

It looks like i goes from 0 to

> (self.N // self.batch\_size) \* epochs

You did not set epochs to zero so it is probably self.N that is zero, which is

> self.N, self.p = trainX.shape

as in N is the number of training samples, so I would specify which samples should be train vs test, and make sure that table actually contains them and they were not filtered out unexpectedly.

---

<div class="post-metadata">

**Author:** ![pau](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/p/2bfe46/32.png) [@pau](https://forum.qiime2.org/u/pau)\
**Post date:** [July 20, 2021, 11:19am UTC](https://forum.qiime2.org/t/songbird-error-local-variable-i-referenced-before-assignment/20175/3 "2021-07-20T11:19:11Z")

</div>

Hi @dwt ! Thanks for your response, it was very helpfull!  
I specified a train-test column in my metadata and worked! However, I have two more questions regarding this topic:

- I am analyzing with songbird different groups of samples from my total samples. Why do some groups require to specify a train/test column while the analysis works well in others without specifying this column? (groups have more or less the same number of samples and samples are evenly distribuited regarding the analized field).

- For the groups that the analysis works with both training column specified and not, results are different (Qsquared, etc). Which model should be taken as better formula? Qsquared values (when compared to null model) are generally higher when training column is not specified; while when specifying this column Qsqared values are very low or negative.

Thanks a lot for your time!!

---

<div class="post-metadata">

**Author:** ![dwt](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@dwt](https://forum.qiime2.org/u/dwt)\
**Post date:** [July 20, 2021, 1:45pm UTC](https://forum.qiime2.org/t/songbird-error-local-variable-i-referenced-before-assignment/20175/4 "2021-07-20T13:45:48Z")

</div>

My understanding is that the q squared is only meaningful when the training column is specified, otherwise the null model and the primary model may be trained on different samples.  
As far as I know you should always prefer the models with the training columns specified, because you can measure their quality.

---

<div class="post-metadata">

**Author:** ![system](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/3X/2/1/21af5fe23cb6f4579467c66a9ed94e55274ca7bd.svg) [@system](https://forum.qiime2.org/u/system)\
**Post date:** [August 20, 2021, 7:46pm UTC](https://forum.qiime2.org/t/songbird-error-local-variable-i-referenced-before-assignment/20175/5 "2021-08-20T19:46:08Z")

</div>

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
