Package: calfpy
CALF v1.20.1 READMESetup and UsageYou can install CALF by runningpip install calfpyYou can import all CALF methods by using the folliwng import statementfrom calfpy.methods import *Calling a function (example)calf(data, 3, "binary", optimize = 'pval', verbose = False)Library Documentationcalf(data, nMarkers, targetVector, optimize = 'pval', verbose = False)Coarse Approximation Linear function.  The main function used to invoke the CALF algorithm on a dataset.parameterdescriptiontypedataData frame where first column contains case/control coded variable (0/1) if targetVector is binary or real values if targetVector is nonbinarypandas DataFramenMarkersMaximum number of markers to include in creation of sum.inttargetVectorSet to "binary" to indicate data with a target vector (first column) having case/control characteristic.  Set to "nonbinary" for target vector (first column) with real numbers.stringoptimizeCriteria to optimize.  Allowed values are "pval", "auc", for a binary target vector, or "corr" for a nonbinary target vector.stringverboseTrue to print activity at each iteration to console. Defaults to False.boolreturnsA dictionary composed of the following results from CALF:keydescription/valueselectionThe markers selected with their assigned weight (-1 or 1).aucThe AUC determined during running CALF.  AUC can be provided for given markers AUC represented for selected markers will only be optimal if set to optimzie for AUC.randomizeFalseproportionUndefinedtargetVecTarget vector argument given in the function call, 'rocPlot': Receiver operating curve plot, if applicable for dataset type and optimizer supplied.finalBestThe optimal value for the provided optimization type, e.g. if optimize='pval" this will have the calculated p-value for the run.optimizeThe optimizer argument given in the function call.calf_fractional(data, nMarkers, controlProportion = .8, caseProportion = .8, optimize = "pval", verbose = False)Randomly selects from binary input provided to data parameter while ensuring the requested proportions of case and control variables are used and runs Coarse Approximation Linear FunctionparameterdescriptiontypedataData frame where first column contains case/control coded variables (0/1) (binary data).pandas DataFramenMarkersMaximum number of markers to include in creation of sum.intcontrolProportionProportion of control samples to use, default is .8.floatcaseProportionProportion of case samples to use, default is .8.floatoptimizeCriteria to optimize.  Allowed values are "pval" or "auc".stringverboseTrue to print activity at each iteration to console. Defaults to False.boolreturnsA dictionary composed of the following results from CALF:keydescription/valueselectionThe markers selected each with their assigned weight (-1 or 1).aucThe AUC determined during running CALF.  AUC can be provided for given markers AUC represented for selected markers will only be optimal if set to optimzie for AUC.randomizeFalseproportionThe proportions of case an control applied druing the function run.targetVec"binary"rocPlotReceiver operating curve plot, if applicable for dataset type and optimizer supplied.finalBestThe optimal value for the provided optimization type, e.g. if optimize='pval" this will have the calculated p-value for the run.optimizeThe optimizer argument given in the function call.calf_randomize(data, nMarkers, targetVector, times = 1, optimize = "pval", verbose = False)Randomly selects from input provided to data parameter and runs Coarse Approximation Linear FunctionparameterdescriptiontypedataData frame where first column contains case/control coded variable (0/1) if targetVector is binary or real values if targetVector is nonbinarypandas DataFramenMarkersMaximum number of markers to include in creation of sum.inttimesIndicates the number of replications to run with randomization.intoptimizeCriteria to optimize.  Allowed values are "pval", "auc", for a binary target vector, or "corr" for a nonbinary target vector.stringverboseTrue to print activity at each iteration to console. Defaults to False.boolreturnsA dictionary composed of the following results from CALF:keydescription/valuemultipleThe markers chosen and the number of times they were selected per iteration,aucThe AUC determined during running CALF.  AUC can be provided for given markers AUC represented for selected markers will only be optimal if set to optimzie for AUC,randomizeTruetargetVec"binary"aucHistA historgram of the AUC values calcuted for all the iterations,timesThe value provided to the times parameter when the function was called,rocPlotReceiver operating curve plot, if applicable for dataset type and optimizer supplied,finalBestThe optimal value for the provided optimization type, e.g. if optimize='pval" this will have the calculated p-value for the run,optimizeThe optimizer argument given in the function call,verboseThe value supplied to the verbose parameter when the function was calledcalf_subset (data, nMarkers, targetVector, proportion = .8, times = 1, optimize = "pval", verbose = False)Randomly selects a subset of the data on which to run Coarse Approximation Linear Functionparameterdescriptiontypeparam dataData frame where first column contains case/control coded variable (0/1) if targetVector is binary or real values if targetVector is nonbinarypandas DataFrameparam nMarkersMaximum number of markers to include in creation of sum.intparam targetVectorSet to "binary" to indicate data with a target vector (first column) having case/control characteristic.  Set to "nonbinary" for target vector (first column) with real numbers.stringparam proportionA value between 0 and 1, the percentage of data, randomly chosen, to use in the calculation.  Default is .8.floatparam timesIndicates the number of replications to run with randomization.intparam optimizeCriteria to optimize.  Allowed values are "pval", "auc", for a binary target vector, or "corr" for a nonbinary target vector.stringparam verboseTrue to print activity at each iteration to console. Defaults to False.boolreturnsA dictionary composed of the following results from CALF:keydescription/valuemultipleThe markers chosen and the number of times they were selected per iteration.aucThe AUC determined during running CALF.  AUC can be provided for given markers AUC represented for selected markers will only be optimal if set to optimzie for AUC.proportionThe value supplied to the proportion paremeter when calling the function.targetVec"binary"aucHistA historgram of the AUC values calcuted for all the iterations.timesThe value provided to the times parameter when the function was called.rocPlotReceiver operating curve plot, if applicable for dataset type and optimizer supplied.finalBestThe optimal value for the provided optimization type, e.g. if optimize=pval" this will have the calculated p-value for the run.optimizeThe optimizer argument given in the function call.calf_exact_binary_subset(data, nMarkers, nCase, nControl, times = 1, optimize = "pval", verbose = False)Randomly selects subsets of data, case and control, from a binary data set, while precisely ensuring the size of the sets on which to run Coarse Approximation Linear FunctionparameterdescriptiontypedataData frame where first column contains case/control coded variable (0/1).pandas DataFramenMarkersMaximum number of markers to include in creation of sum.intnCaseThe number of data points to use for the set of case samples.intnControlThe number of data points to use for the set of control samples.inttimesIndicates the number of replications to run with randomizationintoptimizeCriteria to optimize.  Allowed values are "pval" or "auc"stringverboseTrue to print activity at each iteration to console. Defaults to False.boolreturnsA dictionary composed of the following results from CALF:keydescription/valuemultipleThe markers chosen and the number of times they were selected per iteration.aucThe AUC determined during running CALF.  AUC can be provided for given markers AUC represented for selected markers will only be optimal if set to optimzie for AUC.proportionThe value supplied to the proportion paremeter when calling the function.targetVec"binary"aucHistA historgram of the AUC values calcuted for all the iterations.timesThe value provided to the times parameter when the function was called.rocPlotReceiver operating curve plot, if applicable for dataset type and optimizer supplied.finalBestThe optimal value for the provided optimization type, e.g. if optimize='pval" this will have the calculated p-value for the run.optimizeThe optimizer argument given in the function call.calf_cv(data = CaseControl, limit = 5, times = 100, targetVector = 'binary', optimize = 'pval')Performs repeated random subsampling cross validation on data for Coarse Approximation Linear FunctionparameterdescriptiontypedataData frame where first column contains case/control coded variable (0/1) if targetVector is binary or real values if targetVector is nonbinarypandas DataFramelimitMaximum number of markers to attempt to determine per iteration.inttimesIndicates the number of replications to run with randomization.intproportionA value between 0 and 1, the percentage of data, randomly chosen, to use in each iteration of CALF.  Default is .8,floatoptimizeCriteria to optimize.  Allowed values are "pval", "auc", for a binary target vector, or "corr" for a nonbinary target vector.stringoutputPathThe path where files are to be written as output, default is None meaning no files will be written.  When targetVector is "binary" file binary.csv will be output in the provided path, showing the reults.  When targetVector is "nonbinary" file nonbinary.csv will be output in the provided path, showing the results.  In the same path, the kept and excluded variables from the LAST iteration, will be output, prefixed with the targetVector type "binary" or "nonbinary" followed by Kept and Excluded and suffixed with .csv.  Two files containing the results from each run have List in the filenames and suffixed with .txt.stringreturnsA data frame of the results from the cross validation.  Columns of all markers from data and rows representing each iteration of a CALF run.  Cells will contain the result from CALF for a given CALF run and the markers that were chose for that run.perm_target_cv(data, targetVector, limit, times, proportion = .8, optimize = 'pval', outputPath=None)Performs repeated random subsampling cross validation on data but randomly permutes the target column (first column) with each iteration, for Coarse Approximation Linear FunctionparameterdescriptiontypedataData frame where first column contains case/control coded variable (0/1) if targetVector is binary or real values if targetVector is nonbinary values if targetVector is nonbinarypandas DataFramelimitMaximum number of markers to attempt to determine per iteration.inttimesIndicates the number of replications to run with randomization.intproportionA value between 0 and 1, the percentage of data, randomly chosen, to use in each iteration of CALF.  Default is .8,floatoptimizeCriteria to optimize.  Allowed values are "pval", "auc", for a binary target vector, or "corr" for a nonbinary target vector.stringoutputPathThe path where files are to be written as output, default is None meaning no files will be written.  When targetVector is "binary" file binary.csv will be output in the provided path, showing the reults.  When targetVector is "nonbinary" file nonbinary.csv will be output in the provided path, showing the results.  In the same path, the kept and excluded variables from the LAST iteration, will be output, prefixed with the targetVector type "binary" or "nonbinary" followed by Kept and Excluded and suffixed with .csv.  Two files containing the results from each run have List in the filenames and suffixed with .txt.stringreturnsA data frame of the results from the cross validation.  Columns of all markers from data and rows representing each iteration of a CALF run.  Cells will contain the result from CALF for a given CALF run and the markers that were chose for that run.write_calf(x, filename)Writes the results from a call to calf() to a fileparameterdescriptiontypexThe dictionary object returned from calling calf().dictfilenameThe name of the file in which to write the results from calf().stringwrite_calf_randomize(x, filename)Writes the results from a call to calf_randomize() to a fileparameterdescriptiontypexThe dictionary object returned from calling calf_randomize().dictfilenameThe name of the file in which to write the results from calf_randomize().stringwrite_calf_subset(x, filename)Writes the results from a call to calf_subset() to a fileparameterdescriptiontypexThe dictionary object returned from calling calf_subset().dictfilenameThe name of the file in which to write the results from calf_subset().stringcalf_internal(data, nMarkers, randomize = False, proportion = None, times = 1, targetVector = 'binary', optimize = 'pval', verbose = False)The basic CALF algorithmparameterdescriptiontypedataData frame where first column contains case/control coded variable (0/1) if targetVector is binary or real values if targetVector is nonbinarypandas DataFramenMarkersMaximum number of markers to include in creation of sum.intrandomizeSet to True to randomize the data for each CALF run.boolproportionA value between 0 and 1, the percentage of data, randomly chosen, to use in the calculation.floattimesThe number of times to run CALF on data.inttargetVectorSet to "binary" to indicate data with a target vector (first column) having case/control characteristic.  Set to "nonbinary" for target vector (first column) with real numbers.stringoptimizeCriteria to optimize.  Allowed values are "pval", "auc", for a binary target vector, or "corr" for a nonbinary target vector.stringverboseTrue to print activity at each iteration to console. Defaults to False.* bool*returnsA dictionary composed of the following results from CALF:keydescription/valueselectionThe markers selected each with their assigned weight (-1 or 1).aucThe AUC determined during running CALF.  AUC can be provided for given markers AUC represented for selected markers will only be optimal if set to optimzie for AUC.randomizeFalseproportionUndefinedtargetVecTarget vector argument given in the function call.rocPlotReceiver operating curve plot, if applicable for dataset type and optimizer supplied.finalBestThe optimal value for the provided optimization type, e.g. if optimize='pval" this will have the calculated p-value for the run.optimizeThe optimizer argument given in the function call.