Quasi restricted maximum likelihood (qREML) algorithm for models with penalised splines or simple i.i.d. random effects