https://github.com/morgankain/RRV_HostVectorCompetence
Raw File
Tip revision: be7e87c3c4c8af0420a8dd42cdcff5586fdbad90 authored by Morgan Kain on 25 May 2021, 16:23 UTC
Merge pull request #1 from morgankain/add-license-1
Tip revision: be7e87c
17_matrix_algebra_exploration.R
#############################################
## Further breakdown of the matrix algebra ##
#############################################

####
## Host to Host transmission matrix
####

## Host 1 ability to infect mosquitoes is given by a column over WAIFW_right
WAIFW_right[,1,k]

## Because mosquitoes are the columns of WAIFW_left, and we now have a vector of host species 1 -> all mosquito species ^^,
 ## we can multiply the transmission of that vector of mosquitoes by how much transmission they do to host species X to get how
  ## many new infections in host species X we get for every infection in host species 1. For example, 
sum(WAIFW_right[,1,k] * WAIFW_left[1,,k])
## gives the number of new generation 2 infections of species 1 infected by one infection in species 1. Similarly, 
sum(WAIFW_right[,1,k] * WAIFW_left[2,,k])
## gives the number of new generation 2 infections of species 2 infected by one infection in species 1.

## An equivalent calculation is 
WAIFW_right[,1,k] %*% WAIFW_left[2,,k]

## and through the power of matrix algebra, can do it all at once
t(WAIFW_right[,,k]) %*% t(WAIFW_left[,,k]) 

## Note that this is equivalent to the above calculation to get host-to-host transitions, just the output is transposed
WAIFW_left[,,k] %*% WAIFW_right[,,k] 

## Because I prefer source as the column and recipient (second generation) as the row I do it this way, which means that the colSums are 
 ## the total new infections in the second generation generated by an infected in the first generation
colSums(WAIFW_left[,,k] %*% WAIFW_right[,,k])

## Note the 0s for the second and third columns which are dogs and cats

####
## Mosquito to Mosquito transmission matrix
####

## Mosquito 1 ability to infect hosts is given by a column over WAIFW_left
WAIFW_left[,1,k]

## Because hosts are the columns of WAIFW_right, and we now have a vector of mosquito species 1 -> all host species ^^,
 ## we can multiply the transmission of that vector of hosts by how much transmission they do to mosquito species X to get how
  ## many new infections in mosquito species X we get for every infection in mosquito species 1. For example, 
sum(WAIFW_left[,1,k] * WAIFW_right[1,,k])
## gives the number of new generation 2 infections of species 1 infected by one infection in species 1. Similarly, 
sum(WAIFW_left[,1,k] * WAIFW_right[2,,k])
## gives the number of new generation 2 infections of species 2 infected by one infection in species 1.

## An equivalent calculation is 
WAIFW_left[,1,k] %*% WAIFW_right[2,,k]

## and through the power of matrix algebra, can do it all at once
t(WAIFW_left[,,k]) %*% t(WAIFW_right[,,k])

## Note that this is equivalent to the above calculation to get host-to-host transitions, just the output is transposed
WAIFW_right[,,k] %*% WAIFW_left[,,k]

## Because I prefer source as the column and recipient (second generation) as the row I do it this way, which means that the colSums are 
 ## the total new infections in the second generation generated by an infected in the first generation
colSums(WAIFW_right[,,k] %*% WAIFW_left[,,k])

####
## Mosquito competence using a host-centric view to include infection probability and transmission probability
####

## It is important to note that the above calculation:
colSums(WAIFW_right[,,k] %*% WAIFW_left[,,k])
## assumes we begin with an infected mosquito. Which strongly downweights the importance of mosquito infection probability (as this
 ## will only enter when mosquito biting preference is considered as the identity of hosts that become infected in the mosquito -> host step
  ## now become important -- However, it does, even in this case remain secondary to mosquito transmission. This might be alright, as we 
   ## really don't care if a mosquito becomes infected, it is the transmission step that matters... but maybe we care about both?). Given that 
    ## we start with host -> mosquito as the first measure of mosquito competence continuing to host -> host is logical while switching to 
     ## mosquito -> mosquito not only adds components but shifts the balance of how we are defining competence. Two shifts at once could be difficult 
      ## to explain... Either way this nuance is a downfall of a metric centered on a single generation of transmission because it inevitably weights 
       ## one step more than another...

## ... but the way around this is to take a host-centric view and to treat the vector as just an agent to do the transmission. It is important 
 ## to note however, that this measure will differ from the mosquito-mosquito ecological measure

## This calculation relies upon slightly different algebra:

## For mosquito species 1, the ability for it to pick up infection is given by:
WAIFW_right[1,,k]

## A downfall of this metric is we have to assume some aggregate ability of the mosquito to pick up infection from all hosts (in order to compare to
 ## the other hosts). e.g. if we just measure mosquito competence as the ability to pick up infection from the community in general (a sum here but could
  ## be an average)
sum(WAIFW_right[1,,k])

## Then this total number of mosquitoes of species 1 infects hosts based on this species transmission ability
WAIFW_left[,1,k]

## thus, taken in this way, this species ability to infect a total number of new hosts is given by (calculated for all mosquitoes at the same time):
sweep(WAIFW_left[,,k], 2, rowSums(WAIFW_right[,,k]), FUN = "*") %>% colSums()

## which is different than: 
colSums(WAIFW_right[,,k] %*% WAIFW_left[,,k])

## Note the positive correlation but NOT PERFECT RANK CORRESPONDENCE!
plot(sweep(WAIFW_left[,,k], 2, rowSums(WAIFW_right[,,k]), FUN = "*") %>% colSums(), colSums(WAIFW_right[,,k] %*% WAIFW_left[,,k]))

## Note that this has less of a connection to the idea of an R0 as we aren't starting with one infection in one species, which means this 
 ## quantity is more of an artificial metric for mosquito competence and thus possibly a weaker measure of "importance", though that remains unclear

back to top