Type: Package
Title: Fit Neutral Community Model to Microbiome or Ecological Data
Version: 0.1.0
Description: Provides tools for fitting the neutral community model (NCM) to assess the role of stochastic processes in community assembly. The package implements the framework of Sloan et al. (2006) <doi:10.1111/j.1462-2920.2005.00956.x>, enabling users to evaluate neutral dynamics in ecological and microbial communities.
License: GPL (≥ 3)
Encoding: UTF-8
LazyData: true
Depends: R (≥ 3.5)
Imports: dplyr, Hmisc, minpack.lm
RoxygenNote: 7.3.3
URL: https://github.com/h-xuanjiu/ncmR
NeedsCompilation: no
Packaged: 2026-04-06 00:38:00 UTC; 15225
Author: Yuxuan He ORCID iD [aut, cre, cph]
Maintainer: Yuxuan He <heyuxuan0525@outlook.com>
Repository: CRAN
Date/Publication: 2026-04-10 13:50:02 UTC

Example OTU table and grouping information for NCM demonstration

Description

A simulated dataset containing an OTU table (ASV counts) and corresponding group labels. The data are intended to illustrate the usage of the fit_ncm function.

Usage

example_data

Format

A list with two components:

otu

A data frame with 15 rows (samples) and 2000 columns (ASVs). Row names are sample identifiers, column names are ASV identifiers. Values represent counts of each ASV in each sample.

grp

A data frame with 15 rows and 1 column named group. Row names correspond to the samples in otu. The group column contains character labels ("A", "A", ..., etc.) indicating group membership for each sample.

Source

Simulated data for package examples.


Fit Neutral Community Model (NCM) with optional grouping and total pooling

Description

Fit Neutral Community Model (NCM) with optional grouping and total pooling

Usage

fit_ncm(
  otu,
  grp = NULL,
  group_col = "group",
  groups = NULL,
  simplify = TRUE,
  return_model = FALSE,
  ...
)

Arguments

otu

OTU table, rows = samples, columns = species (data.frame or matrix)

grp

Optional data.frame with rownames = sample IDs, and one column specifying group membership. If NULL, all samples in otu are used as one group.

group_col

Column name in grp that contains group labels (default "group").

groups

Character vector of group names to analyze. If NULL and grp is provided, the function fits models for each group AND for all samples combined (total). If non-NULL, only those groups are analyzed (no total model).

simplify

If TRUE and only one model is fitted, return the model list directly (not nested).

return_model

Whether to return the nlsLM model object (default FALSE to save space).

...

Additional arguments passed to nlsLM (e.g., lower, upper, control).

Value

A list containing model results. If multiple models, a named list with keys: - "all" (if total model fitted) and group names. Each value is a list with: m, N, Nm, ci, rsqr, predictions, (model optional).

Examples

# Load example data
data(example_data)
otu <- example_data$otu
grp <- example_data$grp

# 1. No grouping: fit the total model using all samples
res_total <- fit_ncm(otu)
print(paste("m =", round(res_total$m, 4)))
print(paste("R^2 =", round(res_total$rsqr, 4)))
head(res_total$predictions)

# 2. With grouping: fit models for all groups + total
res_all <- fit_ncm(otu, grp)

# 3. Only specific groups (no total model), returns a single model object
res_sub <- fit_ncm(otu, grp, groups = "A")
res_sub$status_summary


Print summary of NCM model

Description

Print summary of NCM model

Usage

## S3 method for class 'summary_ncm'
print(x, ...)

Arguments

x

An object of class "summary_ncm".

...

Additional arguments (not used).

Value

No return value, called for side effects. Prints a formatted table of NCM results to the console.


Print summary of NCM group results

Description

Print summary of NCM group results

Usage

## S3 method for class 'summary_ncm_group'
print(x, ...)

Arguments

x

An object of class "summary_ncm_group".

...

Additional arguments (not used).

Value

No return value, called for side effects. Prints a formatted table of NCM group results to the console.


Summary method for NCM objects

Description

Summary method for NCM objects

Usage

## S3 method for class 'NCM'
summary(object, ...)

Arguments

object

An object of class "NCM" (single model).

...

Additional arguments (not used).

Value

An object of class "summary_ncm" containing key model statistics.


Summary method for NCM group results

Description

Summary method for NCM group results

Usage

## S3 method for class 'NCM_group'
summary(object, ...)

Arguments

object

An object of class "NCM_group" (list of NCM objects).

...

Additional arguments (not used).

Value

An object of class "summary_ncm_group" containing summary for each group.