Project: s41467-024-50841-9 | Function: bNTI (r)

system: You are an expert R programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow R best practices and maintain consistent code style.
Return **only** the complete R function code.

user: Complete this R function:

**DESCRIPTION:** Calculates beta nearest taxon index to quantify phylogenetic turnover between communities, measuring whether community composition is more or less phylogenetically clustered than expected by chance

**KEY TERMS:** {
  "bNTI": "beta nearest taxon index",
  "bMNTD": "beta mean nearest taxon distance",
  "comdistnt": "community distance nearest taxa"
}

**CONTEXT CODE:** # @Project: DOM-in-MicroEco
# @File: bNTI.R
# @Author: Kai Ma
# Date: 18/07/2021


bNTI <- function(comm, tree, nworker = 4, reps = 1000, outgroup = NULL, output_path = NULL, abundance.weighted = TRUE) {
  stop("Function implementation has been masked")
}


Complete the function implementation replacing "stop("Not implemented")".