I am working with vegetation surveys that were conducted in several river networks. See the attached image that shows one of the those river basins/networks. I am interested in analyzing how the number of species in common between sample sites changes as function of distance (both network distance and euclidean distance).
I calculated 1) the number of species in common between all pairs of points and 2) network/euclidian distances between pairs of points. I am using Bayesian statistics and the software STAN to analyze this relationship. As an interface for STAN I am using the "rethinking" package from Richard McElreath's book "Statistical Rethinking".
The code below fits a linear multilevel model with varying intercepts and slopes for each river basin/network:
m1<-map2stan(alist( species~dnorm(mu,sigma), mu<-a_basin[basin_id]+b_basin[basin_id]*net_distance, c(a,b)[basin_id]~dmvnorm2(c(a,b),sigma_basin,Rho), a~dnorm(0,1), b~dnorm(0,1), sigma_basin~dcauchy(0,1), Rho ~ dlkjcorr(2), sigma~dcauchy(0,1) ),data=d,warmup=1000,iter=5000,chains=3,cores=5 )
The code works but I am not sure the model is correct. I calculated metrics for each pair of points, which means the same point shows up in several pairwise comparisons. Does this create some kind of lack of independence that has to be taken into account in the model? If so, how should I include it?