Ammonia is a major reservoir of nitrogen atoms in cometary materials. However, detections of ammonia in comets are rare, with several achieved at radio wavelengths. A few more detections were obtained through near-infrared observations (around the 3 μm wavelength region), but moderate relative velocity shifts are required to separate emission lines of cometary ammonia from telluric absorption lines in the 3 μm wavelength region. On the other hand, the amidogen radical (NH 2 -a photodissociation product of ammonia in the coma) also shows rovibrational emission lines in the 3 μm wavelength region. Thus, gas production rates for ammonia can be determined from the rovibrational emission lines of ammonia (directly) and amidogen radical (indirectly) simultaneously in the near-infrared. In this article, we present new fluorescence excitation models for cometary ammonia and amidogen radical in the near-infrared, and we apply these models to the near-infrared high-dispersion spectra of comet C/2004 Q2 (Machholz) to determine the mixing ratio of ammonia to water in the comet. Based on direct detection of NH 3 lines, the mixing ratio of NH 3 /H 2 O is 0.46% ± 0.03% in C/2004 Q2 (Machholz), in agreement with other results. The mixing ratio of ammonia determined from the NH 2 observations (0.31%-0.79%) is consistent but has relatively larger error, owing to uncertainty in the photodissociation rates of ammonia. At the present level of accuracy, we confirm that NH 3 could be the sole parent of NH 2 in this comet.