started analysis functions, added aggregate function and test_analyze.r