calculate R in als.py