private void createKsModel(string[] paramArr)
 {
     ITable sample1 = getTable(paramArr[1]);
     ITable sample2 = getTable(paramArr[2]);
     string[] explanitoryVariables = paramArr[3].Split(new char[] { ',' });
     string strataField = "";
     if (paramArr.Length > 5) strataField = paramArr[4];
     Statistics.dataPrepCompareSamples dpKs = new Statistics.dataPrepCompareSamples(sample1, sample2, explanitoryVariables, strataField);
     dpKs.writeModel(paramArr[paramArr.Length - 1]);
 }
        public void selectKSFeaturesToSample(ITable sampledTable,ITable samplesToDrawFromTable, string ksModelPath, string groupFieldName = "")
        {
            IObjectClassInfo2 objInfo2 = (IObjectClassInfo2)sampledTable;
            if (!objInfo2.CanBypassEditSession())
            {
                System.Windows.Forms.MessageBox.Show("Sampled Table participates in a composite relationship. Please export this table as a new table and try again!");
                return;
            }
            if (samplesToDrawFromTable != null)
            {
                objInfo2 = (IObjectClassInfo2)samplesToDrawFromTable;
                if (!objInfo2.CanBypassEditSession())
                {
                    System.Windows.Forms.MessageBox.Show("Samples to draw from table participates in a composite relationship. Please export this table as a new table and try again!");
                    return;
                }
            }
            if (groupFieldName == null) groupFieldName = "";
            try
            {
                esriUtil.Statistics.dataPrepCompareSamples dpComp = new Statistics.dataPrepCompareSamples(ksModelPath);
                Dictionary<string,object[]> sampledBinPropDic = calcBinValues(dpComp, sampledTable); //key = stratfield_bin, values = [0] ratios {10} for random selection [1] counts {10} from sample
                //bins and ratios calculated next use ratios to select from class and bin

                IWorkspace wks = ((IDataset)sampledTable).Workspace;
                IWorkspaceEdit wksE = (IWorkspaceEdit)wks;
                if (wksE.IsBeingEdited())
                {
                    wksE.StopEditing(true);
                }

                System.Random rd = new Random();
                string sampleFldName = geoUtil.createField(sampledTable, "sample", esriFieldType.esriFieldTypeSmallInteger, false);
                List<string> labels = dpComp.Labels.ToList();

                ICursor cur = sampledTable.Update(null, false);
                int sIndex = cur.FindField(sampleFldName);
                int cIndex = cur.FindField(groupFieldName);
                int bIndex = cur.FindField("BIN");
                IRow rw = cur.NextRow();
                while (rw != null)
                {
                    string clustStr = labels[0];
                    if (cIndex > -1)
                    {
                        clustStr = rw.get_Value(cIndex).ToString();
                    }
                    int b = System.Convert.ToInt32(rw.get_Value(bIndex));
                    double rNum = rd.NextDouble();
                    double r = ((double[])sampledBinPropDic[clustStr][0])[b];

                    int ss = 0;
                    if (rNum <= r)
                    {
                        ss = 1;
                    }
                    rw.set_Value(sIndex, ss);
                    cur.UpdateRow(rw);
                    rw = cur.NextRow();
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
                if (samplesToDrawFromTable != null)
                {
                    appendSamples(sampledTable, samplesToDrawFromTable, sampledBinPropDic,dpComp);
                }
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.ToString());
            }
        }