Although the maximum-likelihood estimator of b values is optimal from a certain statistical point of view, given the Gutenberg-Richter frequency-magnitude relation, many researchers have been using least-squares fitting of a straight line to the frequency-magnitude plot. However, ordinary least squares is an inefficient method. A generalized least-squares approach is statistically more satisfactory. The details of this method are given and applied to data from California. The improvement in efficiency is substantial. In addition, the generalized least-squares approach works well also for data from a different frequency-magnitude relation, proposed by Lomnitz-Adler and Lomnitz. The maximum-likelihood estimator (from the Gutenberg-Richter model) has too large a variability in this situation.