We have formulated a grand partition function of electrons for a stell
ar gas and applied it to generating an equation of state. Atomic confi
gurations are included in the grand partition function in terms of the
number of the electrons bound in the configuration and their total en
ergy. Free electrons are included in terms of their energy levels in f
ree phase space. The perturbation of the atomic configuration by the e
nvironments is also included in terms of an occupation probability whi
ch represents the interaction of surrounding particles on the atom. Al
so included is the perturbation of the energy levels of the free elect
rons by the environment in terms of an average energy shift. According
to the theory of the grand canonical ensemble, the grand partition fu
nction of electrons is used to derive a conservation equation for the
electron number, which is solved for the probability of the atomic con
figuration. Thermodynamic functions resulting from the atomic configur
ations and the free electrons can thus be expressed by means of the gr
and partition function in analytical forms. The resulting formulae sho
w nonideal terms in gas pressure and internal energy, as well as in th
e atomic configuration probabilities, which are the result of nonideal
effects due to the perturbations of the atomic configurations and the
free electrons by their environments.