  We present a new HI mass estimator which relates the HI-to-stellar mass ratio
to four galaxy properties: stellar surface mass density, color index $u-r$,
stellar mass and concentration index, with the scatter of individual galaxies
around the mean HI mass modeled with a Gaussian distribution. We calibrate the
estimator using the xGASS sample, including both HI detection and
non-detection, and constrain the model parameters through Bayesian inferences.
Tests with mock catalogs demonstrate that our estimator provides unbiased HI
masses for optical samples like the SDSS, thus suitable for statistical studies
of HI gas contents in galaxies and dark matter halos. We apply our estimator to
the SDSS spectroscopic sample to estimate the local HI mass function (HIMF),
the conditional HI mass function (CHIMF) in galaxy groups and the HI-halo mass
(HIHM) relation. Our HIMF agrees with the ALFALFA measurements at
$M_{HI}\gtrsim 5\times 10^9M_{\odot}$, but with higher amplitude and a steeper
slope at lower masses. We show that this discrepancy is caused primarily by the
cosmic variance which is corrected for the SDSS sample but not for the ALFALFA.
The CHIMFs for all halo masses can be described by a single Schechter function,
and this is true for red, blue and satellite galaxies. For central galaxies the
CHIMFs show a double-Gaussian profile, with the two components contributed by
the red and blue galaxies, respectively. The total HI mass in a group increases
monotonically with halo mass. The HI mass of central galaxies in galaxy groups
increases rapidly with halo mass only at $M_h\lesssim10^{12}M_{\odot}$, while
the mass dependence becomes much weaker at higher halo masses. The observed
HI-halo mass relation is not reproduced by current hydrodynamic simulations and
semi-analytic models of galaxy formation.
