I think I can avoid that by removing the duplicated terms. The code would now look like this:
data(iris)
#create distance matrix from first two principal components
iris.dist<-as.matrix(dist(prcomp(iris[,1:2],scale=T)$x[,1:2]))
#scale to mean 0, SD 1
iris.dist<-iris.dist-mean(iris.dist)
iris.dist<-iris.dist/sd(iris.dist)iris.dat ← data.frame(matrix(ncol = 3, nrow = 0))
colnames(iris.dat) ← c(“Distance”,“RowID”, “ColumnID”, “SameSpecies”)
for(i in 1:nrow(iris)) {
for(j in 1:nrow(iris)) {
if(i<j) { #only include the lower diagonal of the distance matrix
iris.dat<-rbind(iris.dat,data.frame(
Distance=iris.dist[i,j], # distance
RowID=as.character(i), # row ID
ColumnID=as.character(j), # column ID
SameSpecies=as.numeric(iris$Species[i]==iris$Species[j])
#are the two individuals of the same species?
))
}
}
}brm.iris<-brm(Distance~SameSpecies+(1|mm(RowID,ColumnID)),
family=gaussian,
data=iris.dat,cores=4, inits = 0,
prior=c(prior(“normal(0,2)”, “b”)))
summary(brm.iris)