While random effects models have been widely used to analyze the general insurance datasets, likelihood functions of such models are usually complicated so that naïve applications of convex optimization methods may not be effective. In this article, we propose an EM algorithm to calibrate Poisson/gamma frequency and gamma/inverse-gamma severity models with longitudinal data, which are widely used in the posterior ratemaking and compare the efficiency of the proposed algorithm with pre-existing optimization routines. Based on numerical studies, it is shown the proposed EM algorithm provides us more accurate and stable results compared to pre-existing industry benchmarks for the parameter estimation.