Thursday, March 10, 2022

get_cajo_rank ()

There was a typo in a variable name, which took 2-3 hours to fix. 





# Function to get cajo test rank

get_cajo_rank = function( in_system, in_K= 12, in_cval_index=3, in_max_cajo_order=1  ) {

    tryCatch ( 

      {   test_tmp = ca.jo(in_system, type='trace', ecdet = 'const', K= in_K)

          ratio_test_cvalPer = test_tmp@teststat / test_tmp@cval[,in_cval_index]  #ratio of test statistics vs critical values

          number_of_positive_tests = table( ratio_test_cvalPer > 1)['TRUE'] #return the number of TRUE, which can > max_cajo_order

          output_rank = min( number_of_positive_tests,  in_max_cajo_order ) # make sure max_cajo_order is the up limit

          print(paste("get_cajo_rank():: output_rank = ", output_rank))

          return(output_rank)   

      },

      error=function(error_message) {

          output_rank = -999 # an error code

          return(output_rank)   

      })

}



 





No comments:

Post a Comment