--- title: "Appendix 3: Quantifying persistence in a simplicial set" author: "Matthew Silk" date: "6/03/2022" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` *** *** #### Here we demonstrate how likely infection is to persist in the simplicial set illustrated in Figure 1 using transmission functions from Figure 2 and the workflow in Box 1. We define instantaneous persistence as the probability of new infections in a simplex that are unique from the currently infected hosts within the simplex. If this metric is 0, no new infections are produced indicating that instantaneous R~efffective~ in that simplex is 0. *If an infection induces permanent immunity or death, long-term persistence in this simplex would also be zero. However, if hosts can recover from infection and become susceptible again, then long-term persistence will depend on the duration and distribution of the infectious period.* *** *** First we define the simplicial set as a list of simplices (of order 1 or greater). ```{r define_set} #List of simplices s1<-c(1,2,3,4,5) s2<-c(1,2,3,4) s3<-c(1,2,4,5) s4<-c(5,6,7,8) s5<-c(1,2,4) s6<-c(1,2,5) s7<-c(1,3,4) s8<-c(5,6,7) s9<-c(6,7,8) s10<-c(1,2) s11<-c(1,3) s12<-c(1,4) s13<-c(1,5) s14<-c(3,4) s15<-c(5,6) s16<-c(6,7) s17<-c(6,8) s18<-c(7,8) #Simplicial set s_set<-list(s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18) ``` We save some basic information about the simplicial set: the identity and total number of 0-simplices (individuals), and the order of all simplices. ```{r simplex_info} #Store individual IDs (0-simplices) ids<-sort(unique(unlist(lapply(s_set,unique)))) #number of IDs n_id<-length(ids) #simplex order s_order<-unlist(lapply(s_set,length))-1 ``` For convenience we also define the simplicial set in a hypergraph format. ```{r define_hypergraph} #simplicial set as hypergraph h<-matrix(0,nr=length(s_set),nc=n_id) for(i in 1:nrow(h)){ h[i,s_set[[i]]]<-1 } ``` *** *** #### We will now examine how the likelihood of infection persistence varies for different pairs of infected individuals in the simplicial set illustrated in Figure 1. We use the dose response curve and functions from Figure 2. We first identify all possible pairs of individuals. ```{r inf_ind} #potential infection pairs inf_pairs<-combn(n_id,2) ``` We now set the infection dose on the dose-response curve illustrated in Figure 2. ```{r dose} #dose dose<-0.15 ``` We now calculate the probability of persistence for each pair of infected individuals in turn. We work out the number of infected and susceptible individuals in each simplex. We then use the function from our example in Figure 2 to calculate the probability that each individual in a simplex gets infected (`probs`) and that any individual in a simplex gets infected (`probs2`). To approximate the expectation we simulate this 100,000 times and calculate the probability that disease persists in the simplicial set for each potential pair of infected individuals. ```{r persistence_calc} #likelihood of persistence persistence<-numeric() #Loop through infection pairs and estimate likelihood of persistence for(i in 1:ncol(inf_pairs)){ inf<-inf_pairs[,i] #number of infected per simplex n_infected<-rowSums(h[,inf]) probs<-1/(1+exp(-10*(n_infected*dose-0.5)))-1/(1+exp(-10*(-0.5))) n_sus<-(s_order+1)-n_infected probs2<-(1-(1-probs)^n_sus) new<-numeric() for(j in 1:100000){ new[j]<-sign(sum(rbinom(length(probs2),1,prob=probs2))) } persistence[i]<-mean(new) } ``` *** We can inspect the distribution of peristence probabilities across all pairs with a histogram. ```{r hist} par(mar=c(5,5,2,2)) hist(persistence,breaks=seq(0,1,0.025),col="firebrick",border=NA,las=1,xlab="Persistence probability",cex.axis=1.5,cex.lab=1.6,main="") ``` We can see two discrete clusters of persistence probabilities. We can quickly inspect these: ```{r inspect} #The lower cluster inf_pairs[,which(persistence<0.55)] #The higher cluster inf_pairs[,which(persistence>0.55)] ``` We see that in this simplicial set persistence probability is consistently higher when both infected individuals are within the highest-order simplex (1,2,3,4,5). The only combination of infected individuals that are both in this simplex but with a persistence probability in the lower cluster is the pair {3,5}. ***