# Help with First Distances and First Differences

**URL:** https://forum.qiime2.org/t/help-with-first-distances-and-first-differences/17322
**Category:** User Support
**Tags:** longitudinal
**Created:** [November 4, 2020, 12:54am UTC](https://forum.qiime2.org/t/help-with-first-distances-and-first-differences/17322 "2020-11-04T00:54:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Mary\_Ahern](https://forum.qiime2.org/user_avatar/forum.qiime2.org/mary_ahern/32/8642_2.png) [@Mary\_Ahern](https://forum.qiime2.org/u/Mary_Ahern)
#### Post date: [November 4, 2020, 12:54am UTC](https://forum.qiime2.org/t/help-with-first-distances-and-first-differences/17322/1 "2020-11-04T00:54:53Z")

</div>

Hi Everyone!

So I am still pretty new to qiime and microbiome analysis in general. I am at the end of my analysis but I have a question on the results and a few things I couldn't find in the forums or documents. I am interested in studying the changes in gut microbiome over time in relation to weight gain. I have a sample of about 130 college students from the beginning and the end of each semester of their freshman year. To explain some of the variables, participants were put into groups (weight loss, weight gain or weight maintenance) based on how their weight changed over the course of the year.

Among other tests, I ran first differences and first distances, then took these outputs and ran a LME model. Everything ran smoothly but now I am interpreting them and am having a hard time distinguishing the difference between first distance and first difference, especially when it comes to the beta diversity metrics. If first distances is similar to first differences just with a distance matrix as the input, then how would I interpret these results?

As an example I have attached my commands for first differences jaccard and first distances jaccard with the corresponding LME commands and results. I couldn't find any documentation that went over the units for the coefficient for first differences and distances, which is also contributing to my confusion as to how to interpret all of this. For example, are the First Distances Jaccard LME results telling me that the rate of change in the weight loss group (when compared to the reference group of weight gain) is increasing by that coefficient or that the distance between the weight loss group and weight gain group is increasing by that coefficient?

First Distances Jaccard  
qiime longitudinal first-distances   
--i-distance-matrix jaccard\_distance\_matrix.qza   
--m-metadata-file DWmetadataBaseline.txt   
--p-state-column FecalTP   
--p-individual-id-column sparkid   
--p-replicate-handling random   
--o-first-distances jaccard-first-distancesFecalTP.qza

LME- First Distances Jaccard  
qiime longitudinal linear-mixed-effects   
--m-metadata-file DWmetadataBaseline.txt   
--m-metadata-file jaccard-first-distancesFecalTP.qza   
--p-state-column days\_tp2   
--p-metric Distance   
--p-formula Distance~days\_tp2+baseline\_BMI+d\_raceeth4\_num+d\_gen\_num+weight\_category   
--p-individual-id-column sparkid   
--p-group-columns d\_raceeth4\_num,d\_gen\_num,baseline\_BMI,weight\_category   
--o-visualization LME-firstdist-jaccard\_ categorical.qzv

**![|895px;x360px;](https://lh6.googleusercontent.com/jXrqdm90r2d6975cEKFfZf6OBgJpeIfQU4NoU3jW0pWH5DPB9WeU5VQiTRqL7zRW42AN2epimiy9qqkvTy4rQh7hP_1t6VAdEuIow4dCiVsqRxdJf7H7cmLcFdJZUe4CUx4cqDjFHZ4)**

First Differences Jaccard  
qiime longitudinal first-differences   
--m-metadata-file DWmetadataBaseline.txt   
--m-metadata-file jaccard\_pcoa\_results.qza   
--p-state-column FecalTP   
--p-metric "Axis 1"   
--p-individual-id-column sparkid   
--p-replicate-handling random   
--o-first-differences jaccard-first-differencesFecalTP.qza

LME- First Differences Jaccard  
qiime longitudinal linear-mixed-effects   
--m-metadata-file DWmetadataBaseline.txt   
--m-metadata-file jaccard-first-differencesFecalTP.qza   
--p-state-column days\_tp2   
--p-metric Difference   
--p-individual-id-column sparkid   
--p-group-columns baseline\_BMI,d\_raceeth4\_num,d\_gen\_num,weight\_category   
--p-formula Difference~days\_tp2+baseline\_BMI+d\_raceeth4\_num+d\_gen\_num+weight\_category   
--o-visualization LME-firstdiff-jaccard\_categorical.qzv

**![|895px;x368px;](https://lh4.googleusercontent.com/U5vHiNsLZPV1MtKUxDZ673MAU0Ke0z7uNibcCpK7rnRblrHquf6063M43rm_ynKMRwnzb2spjRCF6CLEsYElASYhFu-c8KWGZXnbQUOoVPdcWKM8fqRz9iEEyv9yuW9jzc1t27OB-DA)**

Thank you so much!!  
Mary

---

<div class="post-metadata">

### Author: ![colinbrislawn](https://forum.qiime2.org/user_avatar/forum.qiime2.org/colinbrislawn/32/6221_2.png) [@colinbrislawn](https://forum.qiime2.org/u/colinbrislawn)
#### Post date: [November 4, 2020, 9:58pm UTC](https://forum.qiime2.org/t/help-with-first-distances-and-first-differences/17322/2 "2020-11-04T21:58:03Z")

</div>

Hello Mary,

Thank you for explaining your study. This sounds fascinating. 👩‍🎓 👨‍🎓

I think these two examples from the [longitudinal tutorial](https://docs.qiime2.org/2020.8/tutorials/longitudinal/#first-differencing-to-track-rate-of-change) show how these methods contrast.

`first-difference` is used on alpha diversity measures (like Shannon's index, in this example), while `first-distance` is used on beta diversity measure like (Jaccard distances in this example).

That's also sort of mentioned in this sentence of the tutorial

> A similar method [to `first-difference`] is `first-distances`, which instead identifies the beta diversity distances between successive samples from the same subject, [instead of alpha diversity differences].

* * *

Can I qiime dev to comment on using `first-differences` with Jaccard distances? 🤔

```auto
# First Differences Jaccard
qiime longitudinal first-differences
–m-metadata-file DWmetadataBaseline.txt
–m-metadata-file jaccard_pcoa_results.qza
–p-state-column FecalTP
–p-metric “Axis 1”
–p-individual-id-column sparkid
–p-replicate-handling random
–o-first-differences jaccard-first-differencesFecalTP.qza

```

Does that help?  
Colin

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [November 5, 2020, 6:16am UTC](https://forum.qiime2.org/t/help-with-first-distances-and-first-differences/17322/3 "2020-11-05T06:16:30Z")

</div>

Hello Mary!

If you have not already, my first advice is to use the "volatility" action to plot both the first distances and differences (you should be able to input both and view in the same visualization!). This will make the differences in behavior clearer.

> [@Mary\_Ahern](#):
>
> If first distances is similar to first differences just with a distance matrix as the input, then how would I interpret these results?

In your example, you are using First Differences to look at FD in Jaccard PCoA coordinates (Axis 1), so the output is effectively telling you "how do individuals move around on Axis 1 over the course of the study?" (as in what is their rate of change at each timepoint interval, not their absolute position)

First distances is looking instead at the Jaccard distance (fraction of features not shared by each pair of samples) from the same individual at each time interval.

So these two results are tangentially related but will not necessarily yield the same results, as you are looking at position on a PC axis (i.e., after dimensionality reduction, so these coordinates are impacted by the relationship of those samples to every other sample as well) vs. what fraction of features disappear/emerge in the same individual across each interval.

> [@Mary\_Ahern](#):
>
> the units for the coefficient for first differences and distances

This is because the units are whatever the input is — so we cannot document all possibilities! In your case:  
differences: change in PC1 position  
distances: Jaccard distance (fraction of unique features gained/lost at each interval in that individual)

> [@Mary\_Ahern](#):
>
> are the First Distances Jaccard LME results telling me that the rate of change in the weight loss group (when compared to the reference group of weight gain) is increasing by that coefficient or that the distance between the weight loss group and weight gain group is increasing by that coefficient?

Somewhere between those two. That the change in Jaccard distance between an individual and themselves at baseline is increased by that coefficient in the weight loss group vs. the reference group. So individuals losing weight have more species "turnover" than do those gaining weight.

A couple more tips:

> [@Mary\_Ahern](#):
>
> –p-formula Distance~days\_tp2+baseline\_BMI+d\_raceeth4\_num+d\_gen\_num+weight\_category

you can add interaction terms, e.g., if you want to look at time:weight\_category interaction

> [@Mary\_Ahern](#):
>
> –p-group-columns d\_raceeth4\_num,d\_gen\_num,baseline\_BMI,weight\_category

If you are using a formula, the group columns parameter is ignored so this line is unnecessary.

I hope that helps!

---

<div class="post-metadata">

### Author: ![Mary\_Ahern](https://forum.qiime2.org/user_avatar/forum.qiime2.org/mary_ahern/32/8642_2.png) [@Mary\_Ahern](https://forum.qiime2.org/u/Mary_Ahern)
#### Post date: [November 5, 2020, 11:05pm UTC](https://forum.qiime2.org/t/help-with-first-distances-and-first-differences/17322/4 "2020-11-05T23:05:20Z")

</div>

Thank you so much, that was very helpful and answered all of my questions!

---

<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: [December 7, 2020, 5:05am UTC](https://forum.qiime2.org/t/help-with-first-distances-and-first-differences/17322/5 "2020-12-07T05:05:24Z")

</div>

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