# How to measure and visualise relationship between two sets of count data over time?

I have two sets of count data - one for different viral species, and one for different mosquito species. The count data spans 7 weeks, in 3 different locations.

I want to be able to show that changes in the mosquito species counts correspond to changes in the viral species counts. This is how far I've gotten in visualising that relationship:

While this clearly shows what kind of data I have, it is pretty clunky and I haven't actually measured the correlation between the two datasets.

I'm struggling to figure out what kind of statistical test I should use for this. I've looked into a different options - I thought perhaps something like:

cor(as.vector(mosquito_matrix), as.vector(virus_matrix))


But my matrices are of different dimensions and that only gives me one value. I was hoping for something that could show the correlation over time. Is there a statistical test suitable for this?

I am working in R and have been using the Phyloseq package to analyse my data so far.

Thank you so much for your help. Apologies if there is already a question about this - the only one that seemed to have the same kind of data was this one: Count Data and Relationships but it has 0 answers.

I recommend you read some of this literature to get an idea of the available models for this kind of data. So far as I know, there are computational packages in R to implement most of these model forms, but I will leave it to you to check the details. Personally, I have always found that the negative-binomial GLM models most count data well, so I would start by fitting a multivariate negative-binomial GLM. If you are willing to ignore possible auto-correlation over time, one option would be to drop the time variable from the model, and treat the outcomes at different times as exchangeable data points. This should allow you to estimate the statistical association between the counts of mosquito species and virus species.
Visualising the data (and model output): I think you have made quite a good attempt at visualising your data. You are trying to visualise the relationship between three variables at a time (species, time, count), and this can be difficult, so kudos on your attempt. I agree with you that the present plots are quite complicated, and not easy to interpret, so I will offer some suggestions that can simplify them. Probably the most obvious way to simplify this visualisation would be to replace the bar-charts for each time point with a $$5 \times 7$$ heatmap showing the log-counts of each combination of virus and mosquito species. (I am assuming that none of your counts are zero, so a log-scale would not drop any of the values.) This would give you one heatmap showing each time period, and you could then see the change in the pattern in the heatmap over time. Another way to further simplify the visualisation would be to change your time-series plot to an animation. If you made both of these changes then you would end up with a single animation of a $$5 \times 7$$ heatmap that is changing over time. (If you can post your data I might have time to knock up a plot to show you what I have in mind.)