R code to use Rubin's rule