Adonis error for a specific column

I have a metadata file where there is a column named "Geological_location". And I'm trying to performing adonis for every categorical column with the following code,

qiime diversity adonis \
  --i-distance-matrix core-metrics-results-deblur_MERGED_200/unweighted_unifrac_distance_matrix.qza \
  --m-metadata-file Complete_metadata_Normalized.tsv \
  --o-visualization ADONIS_result/adonis_unw_unifrac_dm_Age_BMI_sex_BMI_city_geoloc_1500.qzv \
  --p-formula "Cardiometabolic_Status+Age_range+BMI_class+SEX*BMI+City+Geological_location" \
  --p-permutations 3500

But I'm having the following error,

Running external command line application. This may print messages to stdout and/or stderr.
The command being run is below. This command cannot be manually re-run as it will depend on temporary files that no longer exist.

Command: run_adonis.R /tmp/tmpafg5dxba/dm.tsv /tmp/tmpafg5dxba/md.tsv Cardiometabolic_Status+Age_range+BMI_class+SEX+BMI+City+Geological_location 3500 1 /tmp/qiime2-temp-ze5f9vse/adonis.tsv

R version 4.2.2 (2022-10-31)
Loading required package: permute
Loading required package: lattice
This is vegan 2.6-4
'adonis' will be deprecated: use 'adonis2' instead
Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
Calls: adonis ... model.matrix -> model.matrix.default -> contrasts<-
5: stop("contrasts can be applied only to factors with 2 or more levels")
4: contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]])
3: model.matrix.default(formula, rhs.frame)
2: model.matrix(formula, rhs.frame)
1: adonis(formula, data = sample.md, permutations = perms, parallel = njobs)
Traceback (most recent call last):
File "/home/turtle/miniconda3/envs/qiime2-2022.11/lib/python3.8/site-packages/q2cli/commands.py", line 352, in call
results = action(**arguments)
File "", line 2, in adonis
File "/home/turtle/miniconda3/envs/qiime2-2022.11/lib/python3.8/site-packages/qiime2/sdk/action.py", line 234, in bound_callable
outputs = self.callable_executor(scope, callable_args,
File "/home/turtle/miniconda3/envs/qiime2-2022.11/lib/python3.8/site-packages/qiime2/sdk/action.py", line 443, in callable_executor
ret_val = self._callable(output_dir=temp_dir, **view_args)
File "/home/turtle/miniconda3/envs/qiime2-2022.11/lib/python3.8/site-packages/q2_diversity/_beta/_visualizer.py", line 382, in adonis
_run_command(cmd)
File "/home/turtle/miniconda3/envs/qiime2-2022.11/lib/python3.8/site-packages/q2_diversity/_beta/_visualizer.py", line 408, in _run_command
subprocess.run(cmd, check=True)
File "/home/turtle/miniconda3/envs/qiime2-2022.11/lib/python3.8/subprocess.py", line 516, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['run_adonis.R', '/tmp/tmpafg5dxba/dm.tsv', '/tmp/tmpafg5dxba/md.tsv', 'Cardiometabolic_Status+Age_range+BMI_class+SEX+BMI+City+Geological_location', '3500', '1', '/tmp/qiime2-temp-ze5f9vse/adonis.tsv']' returned non-zero exit status 1.

But If I exclude the Geological_location variable there is no error. In the Geological_location column there are two types, is this the reason?

Hello again @turtle,

It's good to hear from you! Here's the core error

This makes sense to me, as you are passing a lot of metadata column in your formula.

Unlike other ANOVA tests, the ADONIS tests partitions and removes variance one level at a time. It looks like after partitioning by all these columns, you only have one level left.

Yes. If you want to compare groups, you have to have more than one group.

1 Like

Thank you so much! Now I get it.
:orange_heart:

1 Like

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