RatioOfProfiledLikelihoodsTestStat.h

Go to the documentation of this file.
00001 // @(#)root/roostats:$Id: RatioOfProfiledLikelihoodsTestStat.h 36602 2010-11-11 16:52:13Z moneta $
00002 // Authors: Kyle Cranmer, Sven Kreiss    June 2010
00003 /*************************************************************************
00004  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
00005  * All rights reserved.                                                  *
00006  *                                                                       *
00007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00009  *************************************************************************/
00010 
00011 #ifndef ROOSTATS_RatioOfProfiledLikelihoodsTestStat
00012 #define ROOSTATS_RatioOfProfiledLikelihoodsTestStat
00013 
00014 //_________________________________________________
00015 /*
00016 BEGIN_HTML
00017 <p>
00018 TestStatistic that returns the ratio of profiled likelihoods.
00019 </p>
00020 END_HTML
00021 */
00022 //
00023 
00024 #ifndef ROOT_Rtypes
00025 #include "Rtypes.h"
00026 #endif
00027 
00028 #ifndef ROO_NLL_VAR
00029 #include "RooNLLVar.h"
00030 #endif
00031 
00032 #ifndef ROOSTATS_TestStatistic
00033 #include "RooStats/TestStatistic.h"
00034 #endif
00035 
00036 namespace RooStats {
00037 
00038 class RatioOfProfiledLikelihoodsTestStat: public TestStatistic {
00039 
00040   public:
00041 
00042    RatioOfProfiledLikelihoodsTestStat() :
00043       fNullPdf(NULL),
00044       fAltPdf(NULL),
00045       fAltPOI(NULL),
00046       fSubtractMLE(true)
00047    {
00048       // Proof constructor. Don't use.
00049    }
00050 
00051   RatioOfProfiledLikelihoodsTestStat(RooAbsPdf& nullPdf, RooAbsPdf& altPdf, 
00052                                      const RooArgSet* altPOI=0) :
00053     fNullPdf(&nullPdf), fAltPdf(&altPdf), fSubtractMLE(true)
00054       {
00055         /*
00056          Calculates the ratio of profiled likelihoods. 
00057 
00058          By default the calculation is:
00059 
00060             Lambda(mu_alt , conditional MLE for alt nuisance) 
00061         log --------------------------------------------
00062             Lambda(mu_null , conditional MLE for null nuisance)
00063 
00064         where Lambda is the profile likeihood ratio, so the 
00065         MLE for the null and alternate are subtracted off.
00066 
00067         If SetSubtractMLE(false) then it calculates:
00068 
00069             L(mu_alt , conditional MLE for alt nuisance) 
00070         log --------------------------------------------
00071             L(mu_null , conditional MLE for null nuisance)
00072 
00073 
00074         The values of the parameters of interest for the alternative 
00075         hypothesis are taken at the time of the construction.
00076         If empty, it treats all free parameters as nuisance parameters.
00077 
00078         The value of the parameters of interest for the null hypotheses 
00079         are given at each call of Evaluate(data,nullPOI).
00080         */
00081         if(altPOI)
00082           fAltPOI = (RooArgSet*) altPOI->snapshot();
00083         else
00084           fAltPOI = new RooArgSet(); // empty set
00085 
00086       }
00087 
00088     //__________________________________________
00089     ~RatioOfProfiledLikelihoodsTestStat(void) {
00090       if(fAltPOI) delete fAltPOI;
00091     }
00092     
00093     //__________________________________________
00094     Double_t ProfiledLikelihood(RooAbsData& data, RooArgSet& poi, RooAbsPdf& pdf) {
00095       // returns -logL(poi, conditonal MLE of nuisance params)
00096       // it does not subtract off the global MLE
00097       // because  nuisance parameters of null and alternate may not
00098       // be the same.
00099       RooAbsReal* nll = pdf.createNLL(data, RooFit::CloneData(kFALSE));      
00100       RooAbsReal* profile = nll->createProfile(poi);
00101       // make sure we set the variables attached to this nll
00102       RooArgSet* attachedSet = nll->getVariables();
00103       *attachedSet = poi;
00104       // now evaluate profile to set nuisance to conditional MLE values
00105       double nllVal =  profile->getVal();
00106       // but we may want the nll value without subtracting off the MLE      
00107       if(!fSubtractMLE) nllVal = nll->getVal();
00108 
00109       delete attachedSet;
00110       delete profile;
00111       delete nll;
00112       
00113       return nllVal;
00114     }
00115     
00116     //__________________________________________
00117     virtual Double_t Evaluate(RooAbsData& data, RooArgSet& nullParamsOfInterest) {
00118       RooFit::MsgLevel msglevel = RooMsgService::instance().globalKillBelow();
00119       RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL);
00120       
00121 /*
00122       // construct allVars
00123       RooArgSet *allVars = fNullPdf->getVariables();
00124       RooArgSet *altVars = fAltPdf->getVariables();
00125       allVars->add(*altVars);
00126       delete altVars;
00127 
00128       RooArgSet *saveNullPOI = (RooArgSet*)nullParamsOfInterest.snapshot();
00129       RooArgSet *saveAll = (RooArgSet*)allVars->snapshot();
00130 */
00131 
00132       // null
00133       double nullNLL = ProfiledLikelihood(data, nullParamsOfInterest, *fNullPdf);
00134       
00135       // alt 
00136       double altNLL = ProfiledLikelihood(data, *fAltPOI, *fAltPdf);
00137            
00138 /*
00139       // set variables back to where they were
00140       nullParamsOfInterest = *saveNullPOI;
00141       *allVars = *saveAll;
00142       delete saveAll;
00143       delete allVars;
00144 */
00145 
00146       RooMsgService::instance().setGlobalKillBelow(msglevel);
00147       return nullNLL -altNLL;
00148     }
00149     
00150    
00151     virtual const TString GetVarName() const { return "log(L(#mu_{1},#hat{#nu}_{1}) / L(#mu_{0},#hat{#nu}_{0}))"; }
00152     
00153     //    const bool PValueIsRightTail(void) { return false; } // overwrites default
00154     
00155     void SetSubtractMLE(bool subtract){fSubtractMLE = subtract;}
00156     
00157   private:
00158     RooAbsPdf* fNullPdf;
00159     RooAbsPdf* fAltPdf;
00160     RooArgSet* fAltPOI;
00161     Bool_t fSubtractMLE;
00162     
00163   protected:
00164     ClassDef(RatioOfProfiledLikelihoodsTestStat,2)
00165       };
00166 
00167 }
00168 
00169 
00170 #endif

Generated on Tue Jul 5 14:26:26 2011 for ROOT_528-00b_version by  doxygen 1.5.1