Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RatioOfProfiledLikelihoodsTestStat.cxx
Go to the documentation of this file.
1 // @(#)root/roostats:$Id$
2 // Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
3 /*************************************************************************
4  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 
11 /** \class RooStats::RatioOfProfiledLikelihoodsTestStat
12  \ingroup Roostats
13 
14 TestStatistic that returns the ratio of profiled likelihoods.
15 
16 By default the calculation is:
17 
18 \f[
19  \log{ \frac{ \lambda(\mu_{alt} , {conditional \: MLE \: for \: alt \: nuisance}) }
20  { \lambda(\mu_{null} , {conditional \: MLE \: for \: null \: nuisance}) } }
21 \f]
22 
23 where \f$ \lambda \f$ is the profile likelihood ratio, so the
24 MLE for the null and alternate are subtracted off.
25 
26 If `SetSubtractMLE(false)` then it calculates:
27 
28 \f[
29  \log{ \frac{ L(\mu_{alt} , {conditional \: MLE \: for \: alt \: nuisance}) }
30  { L(\mu_{null} , {conditional \: MLE \: for \: null \: nuisance}) } }
31 \f]
32 
33 where \f$ L \f$ is the Likelihood function.
34 
35 The values of the parameters of interest for the alternative
36 hypothesis are taken at the time of the construction.
37 If empty, it treats all free parameters as nuisance parameters.
38 
39 The value of the parameters of interest for the null hypotheses
40 are given at each call of Evaluate.
41 
42 This test statistic is often called the Tevatron test statistic, because it has
43 been used by the Tevatron experiments.
44 */
45 
47 
49 
50 #include "RooArgSet.h"
51 #include "RooAbsData.h"
52 #include "TMath.h"
53 #include "RooMsgService.h"
54 #include "RooGlobalFunc.h"
55 
56 
57 Bool_t RooStats::RatioOfProfiledLikelihoodsTestStat::fgAlwaysReuseNll = kTRUE ;
58 
59 void RooStats::RatioOfProfiledLikelihoodsTestStat::SetAlwaysReuseNLL(Bool_t flag) { fgAlwaysReuseNll = flag ; }
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// returns -logL(poi, conditional MLE of nuisance params)
63 /// subtract off the global MLE or not depending on the option
64 /// It is the numerator or the denominator of the ratio (depending on the pdf)
65 ///
66 /// L.M. : not sure why this method is needed now
67 
68 Double_t RooStats::RatioOfProfiledLikelihoodsTestStat::ProfiledLikelihood(RooAbsData& data, RooArgSet& poi, RooAbsPdf& pdf) {
69  int type = (fSubtractMLE) ? 0 : 2;
70 
71  // null
72  if ( &pdf == fNullProfile.GetPdf() )
73  return fNullProfile.EvaluateProfileLikelihood(type, data, poi);
74  else if (&pdf == fAltProfile.GetPdf() )
75  return fAltProfile.EvaluateProfileLikelihood(type, data, poi);
76 
77  oocoutE((TObject*)NULL,InputArguments) << "RatioOfProfiledLikelihoods::ProfileLikelihood - invalid pdf used for computing the profiled likelihood - return NaN"
78  << std::endl;
79 
80  return TMath::QuietNaN();
81 
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// evaluate the ratio of profile likelihood
86 
87 Double_t RooStats::RatioOfProfiledLikelihoodsTestStat::Evaluate(RooAbsData& data, RooArgSet& nullParamsOfInterest) {
88 
89  int type = (fSubtractMLE) ? 0 : 2;
90 
91  // null
92  double nullNLL = fNullProfile.EvaluateProfileLikelihood(type, data, nullParamsOfInterest);
93  const RooArgSet *nullset = fNullProfile.GetDetailedOutput();
94 
95  // alt
96  double altNLL = fAltProfile.EvaluateProfileLikelihood(type, data, *fAltPOI);
97  const RooArgSet *altset = fAltProfile.GetDetailedOutput();
98 
99  if (fDetailedOutput != NULL) {
100  delete fDetailedOutput;
101  fDetailedOutput = NULL;
102  }
103  if (fDetailedOutputEnabled) {
104  fDetailedOutput = new RooArgSet();
105  RooRealVar* var(0);
106  for(TIterator *it = nullset->createIterator();(var = dynamic_cast<RooRealVar*>(it->Next()));) {
107  RooRealVar* cloneVar = new RooRealVar(TString::Format("nullprof_%s", var->GetName()),
108  TString::Format("%s for null", var->GetTitle()), var->getVal());
109  fDetailedOutput->addOwned(*cloneVar);
110  }
111  for(TIterator *it = altset->createIterator();(var = dynamic_cast<RooRealVar*>(it->Next()));) {
112  RooRealVar* cloneVar = new RooRealVar(TString::Format("altprof_%s", var->GetName()),
113  TString::Format("%s for null", var->GetTitle()), var->getVal());
114  fDetailedOutput->addOwned(*cloneVar);
115  }
116  }
117 
118 /*
119 // set variables back to where they were
120 nullParamsOfInterest = *saveNullPOI;
121 *allVars = *saveAll;
122 delete saveAll;
123 delete allVars;
124 */
125 
126  return nullNLL -altNLL;
127 }