R code to estimate the ESCS model