A modification of the Andersen-Gill gamma shared frailty model is presented. The variance of the frailty is directly modeled by means of a generalized linear model, the EM algorithm is modified in order to simultaneously estimate a semiparametric model for the failure times and a model for the variance of the frailty. A simulation study is conducted to evaluate the performance of the proposed algorithm (EMB algorithm) and compared with other methods, a marginal model, and a conditional model. Multivariate data from a nosocomial infection study is used to illustrate the methods. The EMB fit turned out to be better than the fit obtained from a marginal model or from a conditional model. The EMB provided the best fit (being the least over-dispersed and having the highest AIC and the highest pseudo-R square) and estimated the parameters most efficiently. The proposed method is able to capture and to take into account unobservable random effects in semiparametric models.