added calculateR function implementation