public LinRegressionResults GetRegressionResult(GadgetParameters gadgetOptions, List <string> columnNames, List <DictionaryDTO> inputDtoList, IEnumerable <EwavDataFilterCondition> ewavDataFilters, List <EwavRule_Base> rules, string filterString = "") { if (gadgetOptions.UseAdvancedDataFilter) { dh = new DashboardHelper(gadgetOptions, filterString, rules); gadgetOptions.UseAdvancedDataFilter = true; gadgetOptions.AdvancedDataFilterText = filterString; } else { dh = new DashboardHelper(gadgetOptions, ewavDataFilters, rules); } DataTable dt; LinRegressionResults results = new LinRegressionResults(); try { dt = dh.GenerateTable(columnNames, gadgetOptions); } catch (Exception e) { results.ErrorMessage = e.Message; return(results); } Dictionary <string, string> inputVariableList = RegressionManager.ConvertDtoToDic(inputDtoList); StatisticsRepository.LinearRegression linearRegression = new StatisticsRepository.LinearRegression(); StatisticsRepository.LinearRegression.LinearRegressionResults regressionResults = linearRegression.LinearRegression(inputVariableList, dt); results.RegressionResults = RegressionManager.ConvertToLinRegResults(regressionResults); results.CorrelationCoefficient = results.RegressionResults.CorrelationCoefficient; results.RegressionDf = results.RegressionResults.RegressionDf; results.RegressionF = results.RegressionResults.RegressionF; results.RegressionMeanSquare = results.RegressionResults.RegressionMeanSquare; results.RegressionSumOfSquares = results.RegressionResults.RegressionSumOfSquares; results.ResidualsDf = results.RegressionResults.ResidualsDf; results.ResidualsMeanSquare = results.RegressionResults.ResidualsMeanSquare; results.ResidualsSumOfSquares = results.RegressionResults.ResidualsSumOfSquares; results.TotalDf = results.RegressionResults.TotalDf; results.TotalSumOfSquares = results.RegressionResults.TotalSumOfSquares; results.Variables = results.RegressionResults.Variables; if (results.RegressionResults.ErrorMessage != null) { results.ErrorMessage = results.RegressionResults.ErrorMessage.Replace("<tlt>", string.Empty).Replace("</tlt>", string.Empty); } return(results); }
public ScatterDataDTO GenerateTable(GadgetParameters gadgetOptions, IEnumerable <EwavDataFilterCondition> ewavDataFilters, List <EwavRule_Base> rules, string filterString = "") { List <ListOfStringClass> lls = new List <ListOfStringClass>(); if (gadgetOptions.UseAdvancedDataFilter) { dh = new DashboardHelper(gadgetOptions, filterString, rules); gadgetOptions.UseAdvancedDataFilter = true; gadgetOptions.AdvancedDataFilterText = filterString; } else { dh = new DashboardHelper(gadgetOptions, ewavDataFilters, rules); } MyString ms = new MyString(); string xAxisVar = gadgetOptions.MainVariableName; string yAxisVar = gadgetOptions.CrosstabVariableName; List <string> columns = new List <string>(); columns.Add(xAxisVar); columns.Add(yAxisVar); DataTable dt = dh.GenerateTable(columns, gadgetOptions); List <NumericDataValue> dataValues = new List <NumericDataValue>(); NumericDataValue minValue = null; NumericDataValue maxValue = null; //regressTable.FieldsList.Fields //foreach (DataRow row in regressTable.Rows) foreach (DataRow row in dt.Rows) { //if (regressTable.GetValueAtRow(yAxisVar, row).Equals(DBNull.Value) || regressTable.GetValueAtRow(xAxisVar, row).Equals(DBNull.Value)) if (row[yAxisVar].Equals(DBNull.Value) || row[xAxisVar].Equals(DBNull.Value)) { continue; } NumericDataValue currentValue = new NumericDataValue() { DependentValue = Convert.ToDecimal(row[yAxisVar]), IndependentValue = Convert.ToDecimal(row[xAxisVar]) }; //NumericDataValue currentValue = new NumericDataValue() { DependentValue = Convert.ToDecimal(regressTable.GetValueAtRow(yAxisVar, row)), IndependentValue = Convert.ToDecimal(regressTable.GetValueAtRow(xAxisVar, row)) }; dataValues.Add(currentValue); if (minValue == null) { minValue = currentValue; } else { if (currentValue.IndependentValue < minValue.IndependentValue) { minValue = currentValue; } } if (maxValue == null) { maxValue = currentValue; } else { if (currentValue.IndependentValue > maxValue.IndependentValue) { maxValue = currentValue; } } } StatisticsRepository.LinearRegression linearRegression = new StatisticsRepository.LinearRegression(); Dictionary <string, string> inputVariableList = new Dictionary <string, string>(); inputVariableList.Add(yAxisVar, "dependvar"); inputVariableList.Add("intercept", "true"); inputVariableList.Add("includemissing", "false"); inputVariableList.Add("p", "0.95"); inputVariableList.Add(xAxisVar, "unsorted"); StatisticsRepository.LinearRegression.LinearRegressionResults regresResults = linearRegression.LinearRegression(inputVariableList, dt); LinRegressionResults results = new LinRegressionResults(); results = RegressionManager.ConvertToLinRegResults(regresResults); //results.CorrelationCoefficient = results.RegressionResults.CorrelationCoefficient; //results.RegressionDf = results.RegressionResults.RegressionDf; //results.RegressionF = results.RegressionResults.RegressionF; //results.RegressionMeanSquare = results.RegressionResults.RegressionMeanSquare; //results.RegressionSumOfSquares = results.RegressionResults.RegressionSumOfSquares; //results.ResidualsDf = results.RegressionResults.ResidualsDf; //results.ResidualsMeanSquare = results.RegressionResults.ResidualsMeanSquare; //results.ResidualsSumOfSquares = results.RegressionResults.ResidualsSumOfSquares; //results.TotalDf = results.RegressionResults.TotalDf; //results.TotalSumOfSquares = results.RegressionResults.TotalSumOfSquares; //results.Variables = results.RegressionResults.Variables; if (results.ErrorMessage != null) { results.ErrorMessage = results.ErrorMessage.Replace("<tlt>", string.Empty).Replace("</tlt>", string.Empty); } ScatterDataDTO scatterDTO = new ScatterDataDTO(); scatterDTO.DataValues = dataValues; scatterDTO.RegresResults = results; scatterDTO.MinValue = minValue; scatterDTO.MaxValue = maxValue; //RegressionManager lrm = new RegressionManager(); //lls = lrm.ConvertDataTableToList(dt); //return new List<ListOfStringClass>(); return(scatterDTO); }