﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	resolution	keywords	cc
702	Estadísticos de resultados de modelos de respuesta cualitativa (Logit, Probit)	imendez	mafernandez	"Hola, solicito que se añadan a los resultados de una estimación de un modelo de respuesta cualitativa un conjunto con los siguientes estadísticos:

* Área bajo la curva ROC (éste creo que ya se solicita en #347)
* Índice KS
* Índice de Gini

Al igual que en #346 y #347, creo que su cálculo se debería controlar mediante un parámetro de configuración de la estimación (_.DoStatistics).

El siguiente código puede ser útil (calcula el Gini a partir del AUC, no directamente; esto puede ser bueno/rápido si ya se ha calculado el AUC):

{{{
//////////////////////////////////////////////////////////////////////////////
Real AUCRoc(Set tasasROC, Set methodInterp)
//////////////////////////////////////////////////////////////////////////////
{
  Set aux = Extract(tasasROC,1,2);
  Set claTFP = Classify(aux, Real(Set reg1, Set reg2)
  {
    Real tfp1 = reg1[1];
    Real tfp2 = reg2[1];
    Compare(tfp1, tfp2)
  });
  Set graph =   EvalSet(claTFP, Set(Set class)
  {
    Real maxTvp = SetMax(Traspose(class)[2]);
    Select(class, Real(Set reg){EQ(reg[2], maxTvp)})[1]
  });
  Set tasasROCUnique = Extract(graph,1,2);
  If(Card(tasasROCUnique)>2,
  {
    Set txFP     = Traspose(tasasROCUnique)[1];
    Set txVP     = Traspose(tasasROCUnique)[2];
    Set setFunSet = SetOfSet(Traspose(SetOfSet(txFP, txVP)) );
    Real get.tvp(Real tfp)
    {
      Set tfpSet = SetOfReal(tfp);
      Real tvp = Interp(tfpSet, setFunSet, methodInterp)[1][2];
      tvp
    };
    IntegrateQAG(get.tvp, 0, 1)
  },
  {
    WriteLn(""Intervalos insuficientes para calcular AUC"",""W"");
    0
  })
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
""Calcula los valores area ROC (AUC) dado las tasas de aciertos de un modelo
(TFP, TVP,TVN,TFN)"",
 AUCRoc);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
Real GiniRoc(Set tasasROC, Set methodInterp)
//////////////////////////////////////////////////////////////////////////////
{  2*AUCRoc(tasasROC, methodInterp) - 1  };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
""Calcula el indice de GINI dado las tasas de aciertos ROC de un modelo
(TFP, TVP,TVN,TFN)"",
 GiniRoc);
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
Real KSRoc(Set tasasROC, Set methodInterp)
//////////////////////////////////////////////////////////////////////////////
{
  Set aux = Extract(tasasROC,1,2);
  Set claTFP = Classify(aux, Real(Set reg1, Set reg2)
  {
    Real tfp1 = reg1[1];
    Real tfp2 = reg2[1];
    Compare(tfp1, tfp2)
  });
  Set graph =   EvalSet(claTFP, Set(Set class)
  {
    Real maxTvp = SetMax(Traspose(class)[2]);
    Select(class, Real(Set reg){EQ(reg[2], maxTvp)})[1]
  });
  Set tasasROCUnique = Extract(graph,1,2);

  Set txFP     = Traspose(tasasROCUnique)[1];
  Set txVP     = Traspose(tasasROCUnique)[2];
  Set setFunSet = SetOfSet(Traspose(SetOfSet(txFP, txVP)) );
  Real get.tvp(Real tfp)
  {
    Set tfpSet = SetOfReal(tfp);
    Real tvp = Interp(tfpSet, setFunSet, methodInterp)[1][2];
    tvp
  };
  Set curvasROC = EvalSet(Range(0,1,0.0001), Set (Real k){
    [[k,    get.tvp(k)]]
  });
  Matrix yTvp = SetMat(Extract(curvasROC,2));
  Matrix yTfp = SetMat(Extract(curvasROC,1));
  Real IndKs = MatMax(yTvp-yTfp)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
""Calcula el indice Kolmogorov Smirnov ROC dado las tasas de aciertos de 
un modelo (TFP, TVP,TVN,TFN)"",
KSRoc);
//////////////////////////////////////////////////////////////////////////////

}}}"	enhancement	closed	major	Development 1A	General	fixed		
