# q2-longitudinal pairwise distances for a dataset with unevenly spaced time points

**URL:** https://forum.qiime2.org/t/q2-longitudinal-pairwise-distances-for-a-dataset-with-unevenly-spaced-time-points/19550
**Category:** User Support
**Tags:** longitudinal
**Created:** [May 13, 2021, 5:36am UTC](https://forum.qiime2.org/t/q2-longitudinal-pairwise-distances-for-a-dataset-with-unevenly-spaced-time-points/19550 "2021-05-13T05:36:25Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![prdas](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/p/b77776/32.png) [@prdas](https://forum.qiime2.org/u/prdas)
#### Post date: [May 13, 2021, 5:36am UTC](https://forum.qiime2.org/t/q2-longitudinal-pairwise-distances-for-a-dataset-with-unevenly-spaced-time-points/19550/1 "2021-05-13T05:36:25Z")

</div>

Hello there,

I have a longitudinal dataset with samples collected from multiple sites and unevenly spaced time points. For example, some of the subjects have only one sample per site, some have replicates for a single time point per site, and some have unique time points.

 ![Screen Shot 2021-05-12 at 10.15.10 PM](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/2X/9/9a5982a2efede8636b45673f0e63413b8a7d19df.png) ![Screen Shot 2021-05-12 at 10.15.47 PM](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/2X/a/a0ed7ba3b4cde02b4a63725220238f408097361c.png) ![Screen Shot 2021-05-12 at 10.17.55 PM](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/2X/9/9e0d0c673318d934350614df50b7d6092983f35f.png)

When I ran the following code:  
qiime longitudinal first-distances   
--i-distance-matrix $inputDir/$inputTable/$inputTable-Distance.qza   
--m-metadata-file $metadata   
--p-state-column timepoint\_allstays   
--p-individual-id-column host\_subject\_id   
--p-replicate-handling random   
--o-first-distances $outDir/$inputTable-first-distances.qza  
qiime longitudinal linear-mixed-effects   
--m-metadata-file $outDir/$inputTable-first-distances.qza   
--m-metadata-file $metadata   
--p-metric Distance   
--p-state-column timepoint\_allstays   
--p-individual-id-column host\_subject\_id   
--p-group-columns sample\_sarscov2\_screening\_result   
--o-visualization $outDir/$inputTable-first-distances-LME.qzv

The output file had distances calculated only for 4 subjects. [FirstDifferences.tsv](https://forum.qiime2.org/uploads/short-url/itobooJU48VzJ4iGBDvz8Ro104K.tsv) (184 Bytes)  
And the LME command did not work at all due to insufficient input rows.

I am aware that the command cannot handle duplicates. Hence, I was trying to add ranks as a new time point column. But I am stuck on how to deal with subjects like H5 and H6 as shown in the image above. Could you suggest how to calculate longitudinal distances per site with this kind of irregular time series dataset?

Please let me know if I could provide more info.

Sincerely,  
Promi.

---

<div class="post-metadata">

### Author: ![jwdebelius](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jwdebelius/32/9655_2.png) [@jwdebelius](https://forum.qiime2.org/u/jwdebelius)
#### Post date: [May 13, 2021, 5:24pm UTC](https://forum.qiime2.org/t/q2-longitudinal-pairwise-distances-for-a-dataset-with-unevenly-spaced-time-points/19550/2 "2021-05-13T17:24:20Z")

</div>

Hi @prdas,

I move this to user support, since it falls into that category more than a technical issue.

This is complex data! 🙂

My first suggestion would be to separate your body sites, I think it will make subsequence modeling easier.

I'm not sure if QIIME can do this, but I might specifically filter to your duplicated timepoints, and look at whether the within-duplicate distances are smaller than the between timepoint differences for those individuals. If they're small, i would drop duplicates.

I think the ranking approach is okay; if there are timepoints you can fudge or ranges you can define, that might help. Like, 5-9 days might be classified as 7 for the sake of convenience and modeling. That also lets you have samples with missing timepoints. Depending on your sample size, I would also consider how you're defining your baseline.

You could also try testing cross sectional timepoints.

Best,  
Justine

---

<div class="post-metadata">

### Author: ![prdas](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/p/b77776/32.png) [@prdas](https://forum.qiime2.org/u/prdas)
#### Post date: [May 13, 2021, 7:28pm UTC](https://forum.qiime2.org/t/q2-longitudinal-pairwise-distances-for-a-dataset-with-unevenly-spaced-time-points/19550/3 "2021-05-13T19:28:03Z")

</div>

Hey Justine,

Thanks for your suggestions 🙂

Yes, I did separate feature tables as per the body site.  
For duplicate samples, I have your suggestion.

But could you also confirm if H5-kinda samples that have only a single time point would get ignored during calculation?

Re to defining baseline - I have not chosen a baseline as mentioned in the command. I assume, in that case, the pairwise distances are calculated between all available time points? If not, could you tell me how?

I am also wondering - When does one choose to define baseline and not define baseline?

---

<div class="post-metadata">

### Author: ![jwdebelius](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jwdebelius/32/9655_2.png) [@jwdebelius](https://forum.qiime2.org/u/jwdebelius)
#### Post date: [May 13, 2021, 9:27pm UTC](https://forum.qiime2.org/t/q2-longitudinal-pairwise-distances-for-a-dataset-with-unevenly-spaced-time-points/19550/4 "2021-05-13T21:27:19Z")

</div>

Hi @prdas

> [@prdas](#):
>
> But could you also confirm if H5-kinda samples that have only a single time point would get ignored during calculation?

Yes, they will be skipped beccause a distance between timepoints requires two timepoints.

> [@prdas](#):
>
> Re to defining baseline - I have not chosen a baseline as mentioned in the command. I assume, in that case, the pairwise distances are calculated between all available time points? If not, could you tell me how?

"First distances" measures from a baseline timepoint (the first timepoint), so thinking about how you define this is important. The `pairwise-differences` command would look at th change between timepoints.

> [@prdas](#):
>
> I am also wondering - When does one choose to define baseline and not define baseline?

It depends on your hypothesis: do you think you have a change from baseline, or a change in step length?

Best,  
Justine

---

<div class="post-metadata">

### Author: ![prdas](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/p/b77776/32.png) [@prdas](https://forum.qiime2.org/u/prdas)
#### Post date: [May 14, 2021, 4:08pm UTC](https://forum.qiime2.org/t/q2-longitudinal-pairwise-distances-for-a-dataset-with-unevenly-spaced-time-points/19550/5 "2021-05-14T16:08:04Z")

</div>

Hey Justine,

Thanks again for answering clearly.

Re: It depends on your hypothesis: do you think you have a change from baseline or a change in step length?  
I guess I have to try both to see if there are any differences worth the interpretation.

---

<div class="post-metadata">

### Author: ![jwdebelius](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jwdebelius/32/9655_2.png) [@jwdebelius](https://forum.qiime2.org/u/jwdebelius)
#### Post date: [May 16, 2021, 5:35pm UTC](https://forum.qiime2.org/t/q2-longitudinal-pairwise-distances-for-a-dataset-with-unevenly-spaced-time-points/19550/6 "2021-05-16T17:35:36Z")

</div>



---

<div class="post-metadata">

### Author: ![jwdebelius](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jwdebelius/32/9655_2.png) [@jwdebelius](https://forum.qiime2.org/u/jwdebelius)
#### Post date: [May 17, 2021, 3:24pm UTC](https://forum.qiime2.org/t/q2-longitudinal-pairwise-distances-for-a-dataset-with-unevenly-spaced-time-points/19550/7 "2021-05-17T15:24:10Z")

</div>

Hi @prdas,

Good luck! Let us know if you run into more snags.

Best,  
Justine

---

<div class="post-metadata">

### Author: ![jwdebelius](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jwdebelius/32/9655_2.png) [@jwdebelius](https://forum.qiime2.org/u/jwdebelius)
#### Post date: [May 17, 2021, 3:24pm UTC](https://forum.qiime2.org/t/q2-longitudinal-pairwise-distances-for-a-dataset-with-unevenly-spaced-time-points/19550/8 "2021-05-17T15:24:12Z")

</div>



---

<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: [June 17, 2021, 9:25pm UTC](https://forum.qiime2.org/t/q2-longitudinal-pairwise-distances-for-a-dataset-with-unevenly-spaced-time-points/19550/9 "2021-06-17T21:25:06Z")

</div>

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