Edge illumination X-ray phase-contrast imaging makes use of two absorbing masks for precise beam shaping and analysis. As the system is being translated to clinical and industrial environments, a robust quantitative algorithm is required to keep the masks precisely aligned without the need of an expert operator. We present a model for how the illumination on the detector varies as one mask is moved relative to the rest of the system. This model is based on a superposition of known illumination patterns associated with misalignment in each degree of freedom. Through inversion of this model, quantitative estimates of the degree of misalignment can be obtained, and hence can show the position of optimal alignment. The precision of alignment achievable through model inversion was tested, showing at least an order of magnitude improvement when compared to the established mask alignment procedure. Precision of the alignment along the optical axis, and around the three rotational degrees of freedom were found to be [+/- 0.78 mu m, +/- 0.17 mdeg, +/- 5.08 mdeg, +/- 2.39 mdeg] respectively, whereas the established procedure would be limited to [+/- 42.5 mu m, +/- 6.69 mdeg, +/- 348 mdeg, +/- 195 mdeg]. Furthermore, the model allows the decomposition of residuals into random and systematic components, the latter enabling accurate evaluation of imperfections in the masks' structure which have now become the main limiting factor in the final degree of alignment.