Skip to content

Commit

Permalink
add Morans.I value in generate_cosine and generate_mantel
Browse files Browse the repository at this point in the history
  • Loading branch information
littlecabiria committed Aug 27, 2024
1 parent fa0406c commit 2293487
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/helpers/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ generate_cosine <- function(real, sim) {

real_new <- real[!is.na(real) & !is.na(sim)]
sim_new <- sim[!is.na(real) & !is.na(sim)]
similarity <- lsa::cosine(lsa::as.textmatrix(cbind(as.vector(real_new), as.vector(sim_new))))
similarity <- lsa::cosine(lsa::as.textmatrix(cbind(as.vector(real_new$Morans.I), as.vector(sim_new$Morans.I))))
return(mean(similarity))
}

generate_mantel <- function(real, sim) {
requireNamespace("vegan", quietly = TRUE)
mantel_test <- vegan::mantel(real, sim, na.rm = TRUE, method = "pearson")
mantel_test <- vegan::mantel(real$Morans.I, sim$Morans.I, na.rm = TRUE, method = "pearson")
return(mantel_test$statistic)
}

Expand Down Expand Up @@ -194,3 +194,5 @@ generate_sim_spatialCluster <- function(real_adata, sim_adata){
return(sim_cluster)
}



0 comments on commit 2293487

Please sign in to comment.