Since macrobenthos play an important role in the energy flow and material circulation of marine systems, they can act as an indicator of ecosystem health. Because there are generally complex relationships between macrobenthos and environmental factors, the optimal model for simulating macrobenthos habitat is a nonlinear, nonparametric model with a relatively flexible structure. This study applied canonical correlation analysis (CCA) to identify the key ecological factors affecting the community characteristics of macrobenthos in the bivalve farming area near Xiaoqing estuary. Responses of species richness to environmental factors were studied using the generalized additive model (GAM), and the Margalef index (dM) was used instead of individual indicator species to indicate diversity variation. Six factors were selected in the optimal model by stepwise regression: salinity (Sal), sediment organic matter (SOM), ammonium nitrogen (NH4-N), phosphate in interstitial water (PO4-Psoil), ammonium nitrogen in interstitial water (NH4-Nsoil), and nitrate nitrogen in interstitial water (NO3-Nsoil) in the substrates. The response curves generated by the GAM showed a unimodal relationship between taxa diversity and Sal and SOM, dM was positively correlated with NH4-N, and was negatively correlated with PO4-Psoil. The model optimized by forward stepwise optimization explained 92.6% of biomass variation, with a small residual (2.67). The measured dM was strongly correlated with the predicted dM (Pearson R2 = 0.845, p < 0.05). This study can increase understanding of the relationships between the macrobenthic community and aquaculture activities in the bivalve farming area near Xiaoqing estuary.