implement R version of xi.i.j.hat