(self, paths, maxOrderNull=0, maxOrder=1, assumption='paths', significanceThreshold=0.01)
return (p<significanceThreshold), p
Performs a likelihood-ratio test between two multi-order models with given maximum orders, where maxOrderNull serves
        as null hypothesis and maxOrder serves as alternative hypothesis. The null hypothesis is rejected if the p-value for
        the observed paths under the null hypothesis is smaller than the given significance threshold.

        Applying this test makes the assumption that we have nested models, i.e. that the null model is contained
        as a special case in the parameter space of the more complex model. If we assume that the path constraint holds,
        this is not true for the test of the first- against the zero-order model (since some sequences of the zero order model
        cannot be generated in the first-order model). However, since the set of possible higher-order transitions is generated
        based on the first-order model, the nestedness property holds for all higher order models.

        @param paths: the path data to be used in the liklihood ratio test
        @param maxOrderNull: maximum order of the multi-order model
                to be used as a null hypothesis
        @param maxOrder: maximum order of the multi-order model to be used as
                alternative hypothesis
        @param assumption: paths or ngrams
        @param significanceThreshold: the threshold for the p-value
                below which to accept the alternative hypothesis
        @returns: a tuple of the format (reject, p) which captures whether or
                not the null hypothesis is rejected in favor of the alternative
                hypothesis, as well as the p-value that led to the decision
Performs a likelihood-ratio test between two multi-order models with given maximum orders, where maxOrderNull serves
        as null hypothesis and maxOrder serves as alternative hypothesis. The null hypothesis is rejected if the p-value for
        the observed paths under the null hypothesis is smaller than the given significance threshold.
Performs a likelihood - ratio test between two multi - order models with given maximum orders where maxOrderNull serves as null hypothesis and maxOrder serves as alternative hypothesis . The null hypothesis is rejected if the p - value for the observed paths under the null hypothesis is smaller than the given significance threshold .
def likeliHoodRatioTest(self, paths, maxOrderNull=0, maxOrder=1, assumption='paths', significanceThreshold=0.01):
        """
        Performs a likelihood-ratio test between two multi-order models with given maximum orders, where maxOrderNull serves
        as null hypothesis and maxOrder serves as alternative hypothesis. The null hypothesis is rejected if the p-value for
        the observed paths under the null hypothesis is smaller than the given significance threshold.

        Applying this test makes the assumption that we have nested models, i.e. that the null model is contained
        as a special case in the parameter space of the more complex model. If we assume that the path constraint holds,
        this is not true for the test of the first- against the zero-order model (since some sequences of the zero order model
        cannot be generated in the first-order model). However, since the set of possible higher-order transitions is generated
        based on the first-order model, the nestedness property holds for all higher order models.

        @param paths: the path data to be used in the liklihood ratio test
        @param maxOrderNull: maximum order of the multi-order model
                to be used as a null hypothesis
        @param maxOrder: maximum order of the multi-order model to be used as
                alternative hypothesis
        @param assumption: paths or ngrams
        @param significanceThreshold: the threshold for the p-value
                below which to accept the alternative hypothesis
        @returns: a tuple of the format (reject, p) which captures whether or
                not the null hypothesis is rejected in favor of the alternative
                hypothesis, as well as the p-value that led to the decision
        """

        assert maxOrderNull < maxOrder, 'Error: order of null hypothesis must be smaller than order of alternative hypothesis'
        # let L0 be the likelihood for the null model and L1 be the likelihood for the alternative model

        # we first compute a test statistic x = -2 * log (L0/L1) = -2 * (log L0 - log L1)
        x = -2 * (self.getLikelihood(paths, maxOrder=maxOrderNull, log=True) - self.getLikelihood(paths, maxOrder=maxOrder, log=True))

        # we calculate the additional degrees of freedom in the alternative model
        dof_diff = self.getDegreesOfFreedom(maxOrder=maxOrder, assumption=assumption) - self.getDegreesOfFreedom(maxOrder=maxOrderNull, assumption=assumption)

        Log.add('Likelihood ratio test for K_opt = ' + str(maxOrder) + ', x = ' + str(x))
        Log.add('Likelihood ratio test, d_1-d_0 = ' + str(dof_diff))

        # if the p-value is *below* the significance threshold, we reject the null hypothesis
        p = 1-chi2.cdf(x, dof_diff)

        Log.add('Likelihood ratio test, p = ' + str(p))
        return (p<significanceThreshold), p
def likeliHoodRatioTest ( self , paths , maxOrderNull = 0 , maxOrder = 1 , assumption = 'paths' , significanceThreshold = 0.01 ) : assert maxOrderNull < maxOrder , 'Error: order of null hypothesis must be smaller than order of alternative hypothesis' # let L0 be the likelihood for the null model and L1 be the likelihood for the alternative model # we first compute a test statistic x = -2 * log (L0/L1) = -2 * (log L0 - log L1) x = - 2 * ( self . getLikelihood ( paths , maxOrder = maxOrderNull , log = True ) - self . getLikelihood ( paths , maxOrder = maxOrder , log = True ) ) # we calculate the additional degrees of freedom in the alternative model dof_diff = self . getDegreesOfFreedom ( maxOrder = maxOrder , assumption = assumption ) - self . getDegreesOfFreedom ( maxOrder = maxOrderNull , assumption = assumption ) Log . add ( 'Likelihood ratio test for K_opt = ' + str ( maxOrder ) + ', x = ' + str ( x ) ) Log . add ( 'Likelihood ratio test, d_1-d_0 = ' + str ( dof_diff ) ) # if the p-value is *below* the significance threshold, we reject the null hypothesis p = 1 - chi2 . cdf ( x , dof_diff ) Log . add ( 'Likelihood ratio test, p = ' + str ( p ) ) return ( p < significanceThreshold ) , p