rlog-likelihood

Error: object 'calculate_lr_test' not found


when calling the function calculate_lr_test the following error appears:

Error: object 'calculate_lr_test' not found

I have installed and loaded the required package (mfp2). Is there a way to resolve this issue? Is there another function to calculate the p-values for likelihood-ratio test?


Solution

  • It's a bit weird, but as @VinceGreg suggests, the calculate_lr_test() function is not exported from the package. What makes it weird is that there is a help page for the function (?mfp2::calculate_lr_test). This is inconsistent — it's normal for packages to contain internal functions that aren't meant to be accessed by the end-user, but not for those functions to be documented without any indication that they're private.

    You can make use of this function by referring to it as mfp2:::calculate_lr_test (the triple-colon indicates that you want to retrieve a private function). In general accessing private functions is bad practice, but in this case it seems to make sense.

    Or, as @VinceGreg also suggests, you could just define the function yourself:

    function (logl, dfs) 
    {
        statistic <- 2 * (logl[2] - logl[1])
        list(statistic = statistic, pvalue = pchisq(statistic, df = dfs[2] - 
            dfs[1], lower.tail = FALSE))
    }
    

    It might make sense to open an issue on the package repository about this ...