You are here

public function AcquiaLiftTest::testGetConfidence in Acquia Lift Connector 7.2

File

tests/AcquiaLiftAPI.test, line 495
Unit tests for Acquia Lift module.

Class

AcquiaLiftTest
@file Unit tests for Acquia Lift module.

Code

public function testGetConfidence() {

  // These are some randomly generated test statistics.
  $tscores = array(
    0.4805467,
    1.0867155,
    2.03041,
    0.6468293000000001,
    0.7536823,
    0.8284473999999999,
    3.0653412,
    3.6732662,
    0.141854,
    3.7283742,
    2.0828125,
    3.3117355,
    2.240636,
    0.2041437,
    1.957721,
    1.5808247,
    0.7013603,
    1.1398363,
    1.0242696,
    0.6061602,
  );

  // These are the correct confidence calculations for each of the test statistics
  // for various numbers of degrees of freedom. The confidence calculation was
  // calculated as 1 - (2*pvalue), where pvalue is the one-sided p-value for
  // the test statistic in a t-distribution with the given number of degrees
  // of freedom.
  $expected_conf_for_df = array(
    1 => array(
      0.28518286,
      0.5264401399999999,
      0.70865811,
      0.36551081,
      0.41116319,
      0.44044402,
      0.79924695,
      0.83078906,
      0.08970851000000001,
      0.8331764,
      0.71503783,
      0.81331077,
      0.73276339,
      0.12820038,
      0.69935717,
      0.64092581,
      0.38938105,
      0.54154342,
      0.50763227,
      0.34691752,
    ),
    2 => array(
      0.321731133778587,
      0.609308720517642,
      0.820572669919182,
      0.4159361722188,
      0.470313762361463,
      0.505458687321669,
      0.90802241111149,
      0.933224775169066,
      0.099805071823134,
      0.934997304904042,
      0.827313975647084,
      0.919657199583924,
      0.845646477754138,
      0.142870544798576,
      0.810619488215369,
      0.74529016194306,
      0.444298979128066,
      0.627532739628972,
      0.586578904550922,
      0.39395701965503,
    ),
    3 => array(
      0.33629480709496,
      0.6433235117977339,
      0.864709487640965,
      0.436178847682057,
      0.494202014927769,
      0.53182827923953,
      0.945237516690831,
      0.9650794718085,
      0.103814085430066,
      0.966387538004865,
      0.871343536460682,
      0.954666745466566,
      0.88910385799165,
      0.148694462126641,
      0.854825248439982,
      0.787945836328694,
      0.466411468106253,
      0.662879846637519,
      0.61891190400939,
      0.412800864588036,
    ),
    4 => array(
      0.344060732520784,
      0.66173425697076,
      0.88783964145001,
      0.447012711543791,
      0.5070251442199319,
      0.546014051757527,
      0.962537258394631,
      0.97867020790152,
      0.105946804742343,
      0.979674366628576,
      0.894313876262353,
      0.970393663265782,
      0.911440543372091,
      0.151792836936525,
      0.878127261469194,
      0.810926332328602,
      0.478263655611114,
      0.682025435645122,
      0.636392561607109,
      0.422875640739763,
    ),
    5 => array(
      0.348872590213502,
      0.673247577857089,
      0.9019400848843619,
      0.453740741011865,
      0.515003145765327,
      0.554851631846377,
      0.972068452678761,
      0.985605746666516,
      0.107266079646819,
      0.986406176389672,
      0.908266482557063,
      0.97880007180349,
      0.924845369552082,
      0.15370959818393,
      0.892398658774908,
      0.825241501794211,
      0.485630805355636,
      0.694003512672696,
      0.647316580023835,
      0.429128283586675,
    ),
    7 => array(
      0.354506492642159,
      0.686839551363136,
      0.918136762308111,
      0.461634172393793,
      0.52437834322903,
      0.565249338381959,
      0.981813736854778,
      0.992070073554429,
      0.108808277611316,
      0.992625537185657,
      0.9242301454449871,
      0.987089266518561,
      0.9399784612550059,
      0.155950446508762,
      0.908874841151574,
      0.842069356759047,
      0.494281088965469,
      0.708149574285593,
      0.660204772993723,
      0.436459827861411,
    ),
    10 => array(
      0.358821640881669,
      0.697337674983186,
      0.930243205020935,
      0.467692447239002,
      0.531585781419877,
      0.573252532697909,
      0.988064738894333,
      0.995706120627185,
      0.109987468927327,
      0.996079165912913,
      0.936104513746093,
      0.992143727011932,
      0.951048608534409,
      0.157664028996801,
      0.92126653113738,
      0.85500072502173,
      0.500925719280955,
      0.719079855770193,
      0.670152980753418,
      0.442083618851362,
    ),
    15 => array(
      0.362227942789561,
      0.705682298260295,
      0.939565083845544,
      0.472482908493155,
      0.537292675193398,
      0.579595833545905,
      0.992146229588172,
      0.997740494991185,
      0.110916931705493,
      0.997981654839318,
      0.945203287091726,
      0.995256623846651,
      0.959388442269268,
      0.159014851406112,
      0.930866724141701,
      0.865229334281472,
      0.506183388802112,
      0.727770699115161,
      0.6780563436578469,
      0.446528417713003,
    ),
    17 => array(
      0.363035503306125,
      0.707668428772818,
      0.9417394282689719,
      0.47361972531188,
      0.538648014019032,
      0.581103166834317,
      0.992994425853601,
      0.998115913229186,
      0.111137098312304,
      0.998328395278229,
      0.94731885743241,
      0.995875741758514,
      0.961305919285539,
      0.159334848040135,
      0.933114899527684,
      0.867656434934316,
      0.5074315573660541,
      0.72983959745938,
      0.679936887760102,
      0.44758292290387,
    ),
    20 => array(
      0.363946690979086,
      0.709913114386589,
      0.944174663334389,
      0.474902940211458,
      0.5401783849619189,
      0.582805564199948,
      0.993894157366836,
      0.9984917731649861,
      0.111385426720091,
      0.998673427981963,
      0.9496848416033949,
      0.9965186859188701,
      0.963439368169264,
      0.159695785849071,
      0.935637363065205,
      0.870395766283665,
      0.508840689825675,
      0.732177996158949,
      0.682061976654317,
      0.448773092728646,
    ),
    30 => array(
      0.365675398529195,
      0.714182705704945,
      0.948738228251312,
      0.477339001602929,
      0.543085110200437,
      0.586040225423774,
      0.995430133349328,
      0.999070811580651,
      0.111856286455336,
      0.999199169591111,
      0.9541079730190219,
      0.997575989207067,
      0.967393616097289,
      0.160380196437941,
      0.940378532642214,
      0.875594675425648,
      0.511516463712829,
      0.736626342508035,
      0.686103296886397,
      0.451032121509195,
    ),
    33 => array(
      0.365990751995235,
      0.714963146057895,
      0.9495622449504429,
      0.477783612820041,
      0.5436158328437311,
      0.58663099555738,
      0.995685749787549,
      0.999158293668445,
      0.111942142533966,
      0.999277752642082,
      0.954905029171162,
      0.997745983125873,
      0.968101041106194,
      0.160504995571902,
      0.94123674729256,
      0.876543271421895,
      0.512004921409688,
      0.73743952965685,
      0.686841898487861,
      0.451444365457069,
    ),
    40 => array(
      0.366543378686206,
      0.716331982066238,
      0.950999610545224,
      0.478562918066783,
      0.544546230294766,
      0.587666790211157,
      0.996115171406128,
      0.9992987263090251,
      0.112092567623536,
      0.999403262649842,
      0.956294105704047,
      0.998026988650297,
      0.969329874587483,
      0.160723654646787,
      0.942735441178112,
      0.878205705700574,
      0.512861152191222,
      0.7388658553927691,
      0.688137267081932,
      0.452166895360514,
    ),
    57 => array(
      0.367321992678436,
      0.7182631739538889,
      0.953009912999637,
      0.479661270281878,
      0.5458578757914579,
      0.589127303406635,
      0.996679933230877,
      0.999469809239211,
      0.112304442139025,
      0.999554851873905,
      0.958234053494374,
      0.998386723140775,
      0.971037015342133,
      0.161031644502609,
      0.944835264066759,
      0.880548144404564,
      0.514068080798177,
      0.740878273369558,
      0.689964623105861,
      0.453185135504987,
    ),
    60 => array(
      0.367413716925937,
      0.718490878451717,
      0.953245558325412,
      0.479790689319615,
      0.546012453899267,
      0.589299447528958,
      0.99674335075119,
      0.999487976412148,
      0.112329396909682,
      0.999570845625073,
      0.958461227754519,
      0.998426341287789,
      0.971236209872293,
      0.161067920404185,
      0.945081701125294,
      0.880824104051006,
      0.514210305633712,
      0.741115564274432,
      0.690180070009289,
      0.453305107716232,
    ),
    80 => array(
      0.36784975611477,
      0.7195739259970531,
      0.954362283975042,
      0.48040600396436,
      0.546747463181902,
      0.590118045622644,
      0.997035824627958,
      0.999568828198109,
      0.112448012469306,
      0.999641732808476,
      0.959537144189648,
      0.998606808111039,
      0.9721774861313039,
      0.161240349503513,
      0.94625045376088,
      0.882135979320654,
      0.514886540094607,
      0.742244234830493,
      0.691204773951122,
      0.453875487115079,
    ),
    120 => array(
      0.368286367685257,
      0.720659368696563,
      0.955474587013883,
      0.48102226236432,
      0.547483728623568,
      0.590938148419598,
      0.997313763688539,
      0.999640947284813,
      0.112566759480835,
      0.999704497085381,
      0.960607676272085,
      0.998774607575318,
      0.973110461355534,
      0.161412972522644,
      0.947416073636598,
      0.883449590370861,
      0.515563870736662,
      0.743375445461584,
      0.6922316742451921,
      0.454446706574094,
    ),
    1000 => array(
      0.369056176583741,
      0.722575555017276,
      0.957420884676493,
      0.48210914875127,
      0.548782586378181,
      0.592385164904709,
      0.99776743572675,
      0.99974783504205,
      0.112776067753023,
      0.999796463624135,
      0.962478047643747,
      0.999039621631611,
      0.974731446622683,
      0.161717251830057,
      0.949459443486883,
      0.885765647068382,
      0.516758614347958,
      0.745372536268692,
      0.694044341033876,
      0.455454072967608,
    ),
    1020 => array(
      0.369058237220439,
      0.722580688425125,
      0.957426068472277,
      0.482112058722065,
      0.548786064415127,
      0.592389040123939,
      0.997768587892168,
      0.999748088161675,
      0.11277662792957,
      0.99979667955566,
      0.962483024213869,
      0.999040279095181,
      0.974735743669313,
      0.161718066191921,
      0.949464892495558,
      0.885771846597004,
      0.5167618133395609,
      0.745377886603245,
      0.694049196819958,
      0.455456769888718,
    ),
  );

  // We'll confirm that our getConfidence method returns a confidence measure
  // that is either equal to 0.5 if the expected result is <= 0.5 or within
  // 0.015 of the expected result otherwise.
  foreach ($expected_conf_for_df as $df => $expected) {
    foreach ($tscores as $i => $tscore) {
      $conf = AcquiaLiftLearnReport::getConfidence($tscore, $df);
      if ($expected[$i] <= 0.5) {
        $this
          ->assertTrue($conf == 0.5);
      }
      else {
        $diff = abs($expected[$i] - $conf);
        $this
          ->assertTrue($diff < 0.015);
      }
    }
  }
}