We extend earlier work [Phys. Rev. Lett. 84, 3740 (2000)]] on the statistical mechanics of the cubic one-dimensional discrete nonlinear Schrödinger (DNLS) equation to a more general class of models, including higher dimensionalities and nonlinearities of arbitrary degree. These extensions are physically motivated by the desire to describe situations with an excitation threshold for creation of localized excitations, as well as by recent work suggesting noncubic DNLS models to describe Bose-Einstein condensates in deep optical lattices, taking into account the effective condensate dimensionality. Considering ensembles of initial conditions with given values of the two conserved quantities, norm and Hamiltonian, we calculate analytically the boundary of the "normal" Gibbsian regime corresponding to infinite temperature, and perform numerical simulations to illuminate the nature of the localization dynamics outside this regime for various cases. Furthermore, we show quantitatively how this DNLS localization transition manifests itself for small-amplitude oscillations in generic Klein-Gordon lattices of weakly coupled anharmonic oscillators (in which energy is the only conserved quantity), and determine conditions for the existence of persistent energy localization over large time scales.