new python and R code for knowledge states