private void BrushingToQQPlot(frmQQPlotResults pfrmPointsPlot, IFeatureLayer pFLayer, IFeatureSelection featureSelection) { try { if (pfrmPointsPlot.m_pFLayer == pFLayer) { IFeatureClass pFeatureClass = pFLayer.FeatureClass; int intVar1Idx = pFeatureClass.Fields.FindField(pfrmPointsPlot.strVar1Name); string strVar1Name = pfrmPointsPlot.strVar1Name; ICursor pCursor = null; featureSelection.SelectionSet.Search(null, false, out pCursor); IRow pRow = pCursor.NextRow(); int dblOriPtsSize = pfrmPointsPlot.pChart.Series[0].MarkerSize; System.Drawing.Color pMarkerColor = System.Drawing.Color.Red; var seriesPts = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "SelPoints", Color = pMarkerColor, BorderColor = pMarkerColor, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point, MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle, MarkerSize = dblOriPtsSize * 2 }; var checkDup = pfrmPointsPlot.pChart.Series.FindByName("SelPoints"); if (checkDup != null) { pfrmPointsPlot.pChart.Series.RemoveAt(2); } pfrmPointsPlot.pChart.Series.Add(seriesPts); int intNfeature = featureSelection.SelectionSet.Count; //int i = 0; Double[] adblVar1 = new Double[intNfeature]; while (pRow != null) { for (int j = 0; j < pfrmPointsPlot.adblVar1.Length; j++) { if (pfrmPointsPlot.adblVar1[j] == Convert.ToDouble(pRow.get_Value(intVar1Idx))) { seriesPts.Points.AddXY(pfrmPointsPlot.adblVar2[j], pfrmPointsPlot.adblVar1[j]); } } pRow = pCursor.NextRow(); } } } catch (Exception ex) { MessageBox.Show("Exception:" + ex.Message); return; } }
public string RemoveWarningByBrushingTechnique(IFeatureLayer pFLayer) { //try //{ FormCollection pFormCollection = System.Windows.Forms.Application.OpenForms; //IActiveView pActiveView = mForm.axMapControl1.ActiveView; string strRelatedPlotName = string.Empty; for (int j = 0; j < pFormCollection.Count; j++) { if (pFormCollection[j].Name == "frmHistResults")//Brushing to Histogram { frmHistResults pfrmHistResults = pFormCollection[j] as frmHistResults; if (pfrmHistResults.pFLayer == pFLayer) { strRelatedPlotName += "Histogram, "; } } if (pFormCollection[j].Name == "frmScatterPlotResults") //Brushing to Scatterplot { frmScatterPlotResults pfrmPointsPlot = pFormCollection[j] as frmScatterPlotResults; if (pfrmPointsPlot.m_pFLayer == pFLayer) { strRelatedPlotName += "Scatter plot, "; } } if (pFormCollection[j].Name == "frmQQPlotResults") //Brushing to QQPlot { frmQQPlotResults pfrmQQPlotResult = pFormCollection[j] as frmQQPlotResults; if (pfrmQQPlotResult.m_pFLayer == pFLayer) { strRelatedPlotName += "QQ-plot, "; } } //if (pFormCollection[j].Name == "frmAttributeTable")//Brushing to AttributeTable //{ // frmAttributeTable pfrmAttTable = pFormCollection[j] as frmAttributeTable; // BrushingToAttTable(pfrmAttTable, pFLayer, featureSelection); //} if (pFormCollection[j].Name == "frmBoxPlotResults")//Brushing to AttributeTable { frmBoxPlotResults pfrmBoxPlotResult = pFormCollection[j] as frmBoxPlotResults; if (pfrmBoxPlotResult.pFLayer == pFLayer) { strRelatedPlotName += "Boxplot, "; } } //if (pFormCollection[j].Name == "frmClassificationGraph")//Brushing to Optiize Graph //{ // frmClassificationGraph pfrmClassGraph = pFormCollection[j] as frmClassificationGraph; // BrushingToOptimizeGraph(pfrmClassGraph, pFLayer, featureSelection); //} //if (pFormCollection[j].Name == "frmCSDesign")//Brushing to CS Graph //{ // frmCSDesign pfrmCSDesign = pFormCollection[j] as frmCSDesign; // if (pfrmCSDesign.pFLayer == pFLayer) // strRelatedPlotName += "Uncertainty Classification, "; //} if (pFormCollection[j].Name == "frmMScatterResults")//Brushing to Moran ScatterPlot { frmMScatterResults pfrmMScatterPlot = pFormCollection[j] as frmMScatterResults; if (pfrmMScatterPlot.m_pFLayer == pFLayer) { strRelatedPlotName += "Moran Scatter Plot, "; } } } if (strRelatedPlotName != string.Empty) { strRelatedPlotName = strRelatedPlotName.Remove(strRelatedPlotName.Length - 2); } return(strRelatedPlotName); //} //catch (Exception ex) //{ // MessageBox.Show("Exception:" + ex.Message); // return; //} }
public void BrushingToOthers(IFeatureLayer pFLayer, IntPtr intPtrParent) { try { FormCollection pFormCollection = System.Windows.Forms.Application.OpenForms; //IActiveView pActiveView = mForm.axMapControl1.ActiveView; if (pFLayer.Visible) { //Brushing to Mapcontrol string ShapeFieldName = pFLayer.FeatureClass.ShapeFieldName; IFeatureSelection featureSelection = (IFeatureSelection)pFLayer; for (int j = 0; j < pFormCollection.Count; j++) { if (pFormCollection[j].Handle != intPtrParent) // Brushing to Others { if (pFormCollection[j].Name == "frmHistResults") //Brushing to Histogram { frmHistResults pfrmHistResults = pFormCollection[j] as frmHistResults; BrushingToHistogram(pfrmHistResults, pFLayer, featureSelection); } if (pFormCollection[j].Name == "frmScatterPlotResults") //Brushing to Scatterplot { frmScatterPlotResults pfrmPointsPlot = pFormCollection[j] as frmScatterPlotResults; BrushingToScatterPlot(pfrmPointsPlot, pFLayer, featureSelection); } if (pFormCollection[j].Name == "frmQQPlotResults") //Brushing to QQPlot { frmQQPlotResults pfrmQQPlotResult = pFormCollection[j] as frmQQPlotResults; BrushingToQQPlot(pfrmQQPlotResult, pFLayer, featureSelection); } if (pFormCollection[j].Name == "frmAttributeTable")//Brushing to AttributeTable { frmAttributeTable pfrmAttTable = pFormCollection[j] as frmAttributeTable; BrushingToAttTable(pfrmAttTable, pFLayer, featureSelection); } if (pFormCollection[j].Name == "frmBoxPlotResults")//Brushing to AttributeTable { frmBoxPlotResults pfrmBoxPlotResult = pFormCollection[j] as frmBoxPlotResults; BrushingToBoxPlot(pfrmBoxPlotResult, pFLayer, featureSelection); } //if (pFormCollection[j].Name == "frmClassificationGraph")//Brushing to Optiize Graph //{ // frmClassificationGraph pfrmClassGraph = pFormCollection[j] as frmClassificationGraph; // BrushingToOptimizeGraph(pfrmClassGraph, pFLayer, featureSelection); //} //if (pFormCollection[j].Name == "frmCSDesign")//Brushing to CS Graph //{ // frmCSDesign pfrmCSDesign = pFormCollection[j] as frmCSDesign; // BrushingToClassSepGraph(pfrmCSDesign, pFLayer, featureSelection); //} if (pFormCollection[j].Name == "frmMScatterResults")//Brushing to Moran ScatterPlot { frmMScatterResults pfrmMScatterPlot = pFormCollection[j] as frmMScatterResults; BrushingToMScatterPlot(pfrmMScatterPlot, pFLayer, featureSelection); } if (pFormCollection[j].Name == "frmCCMapsResults")//Brushing to Moran ScatterPlot { frmCCMapsResults pfrmCCMApsResults = pFormCollection[j] as frmCCMapsResults; BrushingToCCMaps(pfrmCCMApsResults, pFLayer, featureSelection); } if (pFormCollection[j].Name == "frmBoxCox")//Brushing to Box-Cox transformation tool { frmBoxCox pfrmBoxCox = pFormCollection[j] as frmBoxCox; BrushingToBoxCox(pfrmBoxCox, pFLayer, featureSelection); } if (pFormCollection[j].Name == "frmCorrelogram_local")//Brushing to Correlogram { frmCorrelogram_local pfrmCorrelogram = pFormCollection[j] as frmCorrelogram_local; BrushingToCorrelogram(pfrmCorrelogram, pFLayer, featureSelection); } } } } } catch (Exception ex) { MessageBox.Show("Exception:" + ex.Message); return; } }
public void CloseAllRelatedPlots(IFeatureLayer pFLayer) { //try //{ FormCollection pFormCollection = System.Windows.Forms.Application.OpenForms; List <int> lstPlotIdx = new List <int>(); for (int j = 0; j < pFormCollection.Count; j++) { if (pFormCollection[j].Name == "frmHistResults")//Brushing to Histogram { frmHistResults pfrmHistResults = pFormCollection[j] as frmHistResults; if (pfrmHistResults.pFLayer == pFLayer) { lstPlotIdx.Add(j); } } if (pFormCollection[j].Name == "frmScatterPlotResults") //Brushing to Scatterplot { frmScatterPlotResults pfrmPointsPlot = pFormCollection[j] as frmScatterPlotResults; if (pfrmPointsPlot.m_pFLayer == pFLayer) { lstPlotIdx.Add(j); } } if (pFormCollection[j].Name == "frmQQPlotResults") //Brushing to QQPlot { frmQQPlotResults pfrmQQPlotResult = pFormCollection[j] as frmQQPlotResults; if (pfrmQQPlotResult.m_pFLayer == pFLayer) { lstPlotIdx.Add(j); } } if (pFormCollection[j].Name == "frmAttributeTable")//Brushing to AttributeTable { frmAttributeTable pfrmAttTable = pFormCollection[j] as frmAttributeTable; if (pfrmAttTable.m_pLayer == (ILayer)pFLayer) { lstPlotIdx.Add(j); } } if (pFormCollection[j].Name == "frmBoxPlotResults")//Brushing to AttributeTable { frmBoxPlotResults pfrmBoxPlotResult = pFormCollection[j] as frmBoxPlotResults; if (pfrmBoxPlotResult.pFLayer == pFLayer) { lstPlotIdx.Add(j); } } //if (pFormCollection[j].Name == "frmClassificationGraph")//Brushing to Optiize Graph //{ // frmClassificationGraph pfrmClassGraph = pFormCollection[j] as frmClassificationGraph; // BrushingToOptimizeGraph(pfrmClassGraph, pFLayer, featureSelection); //} //if (pFormCollection[j].Name == "frmCSDesign")//Brushing to CS Graph //{ // frmCSDesign pfrmCSDesign = pFormCollection[j] as frmCSDesign; // if (pfrmCSDesign.pFLayer == pFLayer) // lstPlotIdx.Add(j); //} if (pFormCollection[j].Name == "frmMScatterResults")//Brushing to Moran ScatterPlot { frmMScatterResults pfrmMScatterPlot = pFormCollection[j] as frmMScatterResults; if (pfrmMScatterPlot.m_pFLayer == pFLayer) { lstPlotIdx.Add(j); } } if (pFormCollection[j].Name == "frmCorrelogram_local")//Brushing to Correlogram { frmCorrelogram_local pfrmCorrelogram = pFormCollection[j] as frmCorrelogram_local; if (pfrmCorrelogram.m_pFLayer == pFLayer) { lstPlotIdx.Add(j); } } } lstPlotIdx.Sort(); for (int j = lstPlotIdx.Count - 1; j >= 0; j--) { pFormCollection[lstPlotIdx[j]].Close(); } //} //catch (Exception ex) //{ // MessageBox.Show("Exception:" + ex.Message); // return; //} }
public int RemoveBrushing(MainForm mForm, IFeatureLayer pFLayer) { try { FormCollection pFormCollection = System.Windows.Forms.Application.OpenForms; IActiveView pActiveView = mForm.axMapControl1.ActiveView; int intFormCnt = 0; if (pFLayer.Visible) { //Brushing to Mapcontrol string ShapeFieldName = pFLayer.FeatureClass.ShapeFieldName; //IFeatureSelection featureSelection = (IFeatureSelection)pFLayer; for (int j = 0; j < pFormCollection.Count; j++) { if (pFormCollection[j].Name == "frmHistResults")//Brushing to Histogram { frmHistResults pfrmHistResults = pFormCollection[j] as frmHistResults; if (pfrmHistResults.pFLayer == pFLayer) { intFormCnt++; } } if (pFormCollection[j].Name == "frmScatterPlotResults") //Brushing to Scatterplot { frmScatterPlotResults pfrmPointsPlot = pFormCollection[j] as frmScatterPlotResults; if (pfrmPointsPlot.m_pFLayer == pFLayer) { intFormCnt++; } } if (pFormCollection[j].Name == "frmQQPlotResults") //Brushing to QQPlot { frmQQPlotResults pfrmQQPlotResult = pFormCollection[j] as frmQQPlotResults; if (pfrmQQPlotResult.m_pFLayer == pFLayer) { intFormCnt++; } } if (pFormCollection[j].Name == "frmAttributeTable")//Brushing to AttributeTable { frmAttributeTable pfrmAttTable = pFormCollection[j] as frmAttributeTable; if ((IFeatureLayer)pfrmAttTable.m_pLayer == pFLayer) { intFormCnt++; } } if (pFormCollection[j].Name == "frmBoxPlotResults")//Brushing to AttributeTable { frmBoxPlotResults pfrmBoxPlotResult = pFormCollection[j] as frmBoxPlotResults; if (pfrmBoxPlotResult.pFLayer == pFLayer) { intFormCnt++; } } //if (pFormCollection[j].Name == "frmClassificationGraph")//Brushing to Optiize Graph //{ // frmClassificationGraph pfrmClassGraph = pFormCollection[j] as frmClassificationGraph; // if (pfrmClassGraph.m_pFLayer == pFLayer) // intFormCnt++; //} if (pFormCollection[j].Name == "frmMScatterResults")//Brushing to Moran ScatterPlot { frmMScatterResults pfrmMScatterPlot = pFormCollection[j] as frmMScatterResults; if (pfrmMScatterPlot.m_pFLayer == pFLayer) { intFormCnt++; } } } return(intFormCnt); } else { return(-1); } } catch (Exception ex) { MessageBox.Show("Exception:" + ex.Message); return(-1); } }
private void btnQQplot_Click(object sender, EventArgs e) { try { //string strTargetLayerName = cboTargetLayer.Text; //string strVar1Name = cboVariable1.Text; //int intTargetIndex = m_pSnippet.GetIndexNumberFromLayerName(m_pActiveView, strTargetLayerName); //int intNFeatureCount = 0; //ILayer pTargetLayer = m_pForm.axMapControl1.get_Layer(intTargetIndex); //IFeatureLayer pTargetFLayer = (IFeatureLayer)pTargetLayer; ////Extract geometry from selected feature //IFeatureCursor pFCursor = null; //pFCursor = pTargetFLayer.Search(null, true); //intNFeatureCount = pTargetFLayer.FeatureClass.FeatureCount(null); //#region deprecated function ////Considering only all features 032317 HK ////IFeatureSelection pFeatureSelection = pTargetFLayer as IFeatureSelection; ////intNFeatureCount = pFeatureSelection.SelectionSet.Count; ////if (intNFeatureCount > 0 && chkUseSelected.Checked == true) ////{ //// ICursor pCursor = null; //// pFeatureSelection.SelectionSet.Search(null, true, out pCursor); //// pFCursor = (IFeatureCursor)pCursor; ////} ////else if (intNFeatureCount == 0 && chkUseSelected.Checked == true) ////{ //// MessageBox.Show("Select at least one feature"); //// return; ////} ////else ////{ //// pFCursor = pTargetFLayer.Search(null, true); //// intNFeatureCount = pTargetFLayer.FeatureClass.FeatureCount(null); ////} //#endregion //IFeature pFeature = pFCursor.NextFeature(); ////Source and Group Field Index //int intVar1Idx = pTargetFLayer.FeatureClass.Fields.FindField(strVar1Name); //int intFIDIdx = pTargetFLayer.FeatureClass.FindField(pTargetFLayer.FeatureClass.OIDFieldName); //m_adblVar1 = new double[intNFeatureCount]; //m_arrFID = new int[intNFeatureCount]; ////Feature Value to Array //int i = 0; //while (pFeature != null) //{ // m_adblVar1[i] = Convert.ToDouble(pFeature.get_Value(intVar1Idx)); // m_arrFID[i] = Convert.ToInt32(pFeature.get_Value(intFIDIdx)); // i++; // pFeature = pFCursor.NextFeature(); //} ////Draw Boxplot at the Form ////Array to R vector. //NumericVector vecVar1 = m_pEngine.CreateNumericVector(m_adblVar1); //m_pEngine.SetSymbol(strVar1Name, vecVar1); //IntegerVector vecFID = m_pEngine.CreateIntegerVector(m_arrFID); //m_pEngine.SetSymbol("FID", vecFID); //Sorting the variables m_pEngine.Evaluate("n <- length(" + m_strVar1Name + "); p <- ((1:n)-0.5)/(n)"); m_pEngine.Evaluate("y <- quantile(" + m_strVar1Name + ", c(0.25, 0.75))"); m_pEngine.Evaluate("sample.bind <- cbind(" + m_strVar1Name + ", FID)"); Double[] dblSortedVariable = m_pEngine.Evaluate("sample.bind[order(sample.bind[,1]),1]").AsNumeric().ToArray(); m_arrSortedFID = m_pEngine.Evaluate("sample.bind[order(sample.bind[,1]),2]").AsInteger().ToArray(); string strTitle = null; Double[] dblTransformedX = null; double dblSlope = 0; double dblyInt = 0; switch (cboDistribution.Text) { case "Normal": //sbCommand.Append("qqPlot(" + strVar1Name + ", dist='norm');"); strTitle = "Normal Quantile"; m_pEngine.Evaluate("q <- qnorm(p)"); dblTransformedX = m_pEngine.Evaluate("q").AsNumeric().ToArray(); m_pEngine.Evaluate("x <- qnorm(c(0.25, 0.75))"); //Calculate Slope and y intercept m_pEngine.Evaluate("slope <- diff(y)/diff(x)"); m_pEngine.Evaluate("int <- y[1L] - slope * x[1L]"); dblSlope = m_pEngine.Evaluate("slope").AsNumeric().ToArray().First(); dblyInt = m_pEngine.Evaluate("int").AsNumeric().ToArray().First(); //Calculate Low and upper bound m_pEngine.Evaluate("conf <- 0.95; zz<-qnorm(1-(1-conf)/2)"); m_pEngine.Evaluate("SE<-(slope/dnorm(q))*sqrt(p*(1-p)/n)"); m_pEngine.Evaluate("fit.value<-int+slope*q"); break; case "t": //sbCommand.Append("qqPlot(" + strVar1Name + ", dist='t', df=" + txtDf1.Text + ");"); strTitle = "t Quantile"; m_pEngine.Evaluate("q <- qt(p, df=" + txtDf1.Text + ")"); dblTransformedX = m_pEngine.Evaluate("q").AsNumeric().ToArray(); m_pEngine.Evaluate("x <- qt(c(0.25, 0.75), df=" + txtDf1.Text + ")"); //Calculate Slope and y intercept m_pEngine.Evaluate("slope <- diff(y)/diff(x)"); m_pEngine.Evaluate("int <- y[1L] - slope * x[1L]"); dblSlope = m_pEngine.Evaluate("slope").AsNumeric().ToArray().First(); dblyInt = m_pEngine.Evaluate("int").AsNumeric().ToArray().First(); //Calculate Low and upper bound //pEngine.Evaluate("conf <- 0.95; zz<-qt(1-(1-conf)/2, df=" + txtDf1.Text + ")"); m_pEngine.Evaluate("conf <- 0.95; zz<-qnorm(1-(1-conf)/2)"); m_pEngine.Evaluate("SE<-(slope/dt(q, df=" + txtDf1.Text + "))*sqrt(p*(1-p)/n)"); m_pEngine.Evaluate("fit.value<-int+slope*q"); break; case "F": //sbCommand.Append("qqPlot(" + strVar1Name + ", dist='f', df1=" + txtDf1.Text + ", df2=" + txtDf2.Text + ");"); strTitle = "F Quantile"; m_pEngine.Evaluate("q <- qf(p, df1=" + txtDf1.Text + ", df2=" + txtDf2.Text + ")"); dblTransformedX = m_pEngine.Evaluate("q").AsNumeric().ToArray(); m_pEngine.Evaluate("x <- qf(c(0.25, 0.75), df1=" + txtDf1.Text + ", df2=" + txtDf2.Text + ")"); //Calculate Slope and y intercept m_pEngine.Evaluate("slope <- diff(y)/diff(x)"); m_pEngine.Evaluate("int <- y[1L] - slope * x[1L]"); dblSlope = m_pEngine.Evaluate("slope").AsNumeric().ToArray().First(); dblyInt = m_pEngine.Evaluate("int").AsNumeric().ToArray().First(); //Calculate Low and upper bound //pEngine.Evaluate("conf <- 0.95; zz<-qf(1-(1-conf)/2, df1=" + txtDf1.Text + ", df2=" + txtDf2.Text + ")"); m_pEngine.Evaluate("conf <- 0.95; zz<-qnorm(1-(1-conf)/2)"); m_pEngine.Evaluate("SE<-(slope/df(q, df1=" + txtDf1.Text + ", df2=" + txtDf2.Text + ")) *sqrt(p*(1-p)/n)"); m_pEngine.Evaluate("fit.value<-int+slope*q"); break; case "Chi-square": //sbCommand.Append("qqPlot(" + strVar1Name + ", dist='chisq', df=" + txtDf1.Text + ");"); strTitle = "Chi square Quantile"; m_pEngine.Evaluate("q <- qchisq(p, df=" + txtDf1.Text + ")"); dblTransformedX = m_pEngine.Evaluate("q").AsNumeric().ToArray(); m_pEngine.Evaluate("x <- qchisq(c(0.25, 0.75), df=" + txtDf1.Text + ")"); //Calculate Slope and y intercept m_pEngine.Evaluate("slope <- diff(y)/diff(x)"); m_pEngine.Evaluate("int <- y[1L] - slope * x[1L]"); dblSlope = m_pEngine.Evaluate("slope").AsNumeric().ToArray().First(); dblyInt = m_pEngine.Evaluate("int").AsNumeric().ToArray().First(); //Calculate Low and upper bound //pEngine.Evaluate("conf <- 0.95; zz<-qchisq(1-(1-conf)/2, df=" + txtDf1.Text + ")"); m_pEngine.Evaluate("conf <- 0.95; zz<-qnorm(1-(1-conf)/2)"); m_pEngine.Evaluate("SE<-(slope/dchisq(q, df=" + txtDf1.Text + "))*sqrt(p*(1-p)/n)"); m_pEngine.Evaluate("fit.value<-int+slope*q"); break; case "Binomial": //sbCommand.Append("qqPlot(" + strVar1Name + ", dist='binom', size=" + txtDf1.Text + ", prob=" + txtDf2.Text + ");"); strTitle = "Binomial Quantile"; m_pEngine.Evaluate("q <- qbinom(p, size=" + txtDf1.Text + ", prob=" + txtDf2.Text + ")"); dblTransformedX = m_pEngine.Evaluate("q").AsNumeric().ToArray(); m_pEngine.Evaluate("x <- qbinom(c(0.25, 0.75), size=" + txtDf1.Text + ", prob=" + txtDf2.Text + ")"); //Calculate Slope and y intercept m_pEngine.Evaluate("slope <- diff(y)/diff(x)"); m_pEngine.Evaluate("int <- y[1L] - slope * x[1L]"); dblSlope = m_pEngine.Evaluate("slope").AsNumeric().ToArray().First(); dblyInt = m_pEngine.Evaluate("int").AsNumeric().ToArray().First(); //Calculate Low and upper bound //pEngine.Evaluate("conf <- 0.95; zz<-qbinom(1-(1-conf)/2, size=" + txtDf1.Text + ", prob=" + txtDf2.Text + ")"); m_pEngine.Evaluate("conf <- 0.95; zz<-qnorm(1-(1-conf)/2)"); m_pEngine.Evaluate("SE<-(slope/dbinom(q, size=" + txtDf1.Text + ", prob=" + txtDf2.Text + ")) *sqrt(p*(1-p)/n)"); m_pEngine.Evaluate("fit.value<-int+slope*q"); break; case "Negative binomial": //sbCommand.Append("qqPlot(" + strVar1Name + ", dist='nbinom', size=" + txtDf1.Text + ", prob=" + txtDf2.Text + ");"); strTitle = "Negative Binomial Quantile"; m_pEngine.Evaluate("q <- qnbinom(p, size=" + txtDf1.Text + ", mu=" + txtDf2.Text + ")"); dblTransformedX = m_pEngine.Evaluate("q").AsNumeric().ToArray(); m_pEngine.Evaluate("x <- qnbinom(c(0.25, 0.75), size=" + txtDf1.Text + ", mu=" + txtDf2.Text + ")"); //Calculate Slope and y intercept m_pEngine.Evaluate("slope <- diff(y)/diff(x)"); m_pEngine.Evaluate("int <- y[1L] - slope * x[1L]"); dblSlope = m_pEngine.Evaluate("slope").AsNumeric().ToArray().First(); dblyInt = m_pEngine.Evaluate("int").AsNumeric().ToArray().First(); //Calculate Low and upper bound //pEngine.Evaluate("conf <- 0.95; zz<-qnbinom(1-(1-conf)/2, size=" + txtDf1.Text + ", prob=" + txtDf2.Text + ")"); m_pEngine.Evaluate("conf <- 0.95; zz<-qnorm(1-(1-conf)/2)"); m_pEngine.Evaluate("SE<-(slope/dnbinom(q, size=" + txtDf1.Text + ", mu=" + txtDf2.Text + ")) *sqrt(p*(1-p)/n)"); m_pEngine.Evaluate("fit.value<-int+slope*q"); break; case "Beta": //sbCommand.Append("qqPlot(" + strVar1Name + ", dist='beta', shape1=" + txtDf1.Text + ", shape2=" + txtDf2.Text + ");"); strTitle = "Beta Quantile"; m_pEngine.Evaluate("q <- qbeta(p, shape1=" + txtDf1.Text + ", shape2=" + txtDf2.Text + ")"); dblTransformedX = m_pEngine.Evaluate("q").AsNumeric().ToArray(); m_pEngine.Evaluate("x <- qbeta(c(0.25, 0.75), shape1=" + txtDf1.Text + ", shape2=" + txtDf2.Text + ")"); //Calculate Slope and y intercept m_pEngine.Evaluate("slope <- diff(y)/diff(x)"); m_pEngine.Evaluate("int <- y[1L] - slope * x[1L]"); dblSlope = m_pEngine.Evaluate("slope").AsNumeric().ToArray().First(); dblyInt = m_pEngine.Evaluate("int").AsNumeric().ToArray().First(); //Calculate Low and upper bound m_pEngine.Evaluate("conf <- 0.95; zz<-qnorm(1-(1-conf)/2)"); //pEngine.Evaluate("conf <- 0.95; zz<-qbeta(1-(1-conf)/2, shape1=" + txtDf1.Text + ", shape2=" + txtDf2.Text + ")"); m_pEngine.Evaluate("SE<-(slope/dbeta(q, shape1=" + txtDf1.Text + ", shape2=" + txtDf2.Text + ")) *sqrt(p*(1-p)/n)"); m_pEngine.Evaluate("fit.value<-int+slope*q"); break; case "Gamma": //sbCommand.Append("qqPlot(" + strVar1Name + ", dist='gamma', shape=" + txtDf1.Text + ");"); strTitle = "Gamma Quantile"; m_pEngine.Evaluate("q <- qgamma(p, shape=" + txtDf1.Text + ")"); dblTransformedX = m_pEngine.Evaluate("q").AsNumeric().ToArray(); m_pEngine.Evaluate("x <- qgamma(c(0.25, 0.75), shape=" + txtDf1.Text + ")"); //Calculate Slope and y intercept m_pEngine.Evaluate("slope <- diff(y)/diff(x)"); m_pEngine.Evaluate("int <- y[1L] - slope * x[1L]"); dblSlope = m_pEngine.Evaluate("slope").AsNumeric().ToArray().First(); dblyInt = m_pEngine.Evaluate("int").AsNumeric().ToArray().First(); //Calculate Low and upper bound m_pEngine.Evaluate("conf <- 0.95; zz<-qnorm(1-(1-conf)/2)"); //pEngine.Evaluate("conf <- 0.95; zz<-qgamma(1-(1-conf)/2, shape=" + txtDf1.Text + ")"); m_pEngine.Evaluate("SE<-(slope/dgamma(q, shape=" + txtDf1.Text + ")) *sqrt(p*(1-p)/n)"); m_pEngine.Evaluate("fit.value<-int+slope*q"); break; case "Poisson": //sbCommand.Append("qqPlot(" + strVar1Name + ", dist='pois', lambda=" + txtDf1.Text + ");"); strTitle = "Poisson Quantile"; m_pEngine.Evaluate("q <- qpois(p, lambda=" + txtDf1.Text + ")"); dblTransformedX = m_pEngine.Evaluate("q").AsNumeric().ToArray(); m_pEngine.Evaluate("x <- qpois(c(0.25, 0.75), lambda=" + txtDf1.Text + ")"); //Calculate Slope and y intercept m_pEngine.Evaluate("slope <- diff(y)/diff(x)"); m_pEngine.Evaluate("int <- y[1L] - slope * x[1L]"); dblSlope = m_pEngine.Evaluate("slope").AsNumeric().ToArray().First(); dblyInt = m_pEngine.Evaluate("int").AsNumeric().ToArray().First(); //Calculate Low and upper bound // pEngine.Evaluate("conf <- 0.95; zz<-qpois(1-(1-conf)/2, lambda=" + txtDf1.Text + ")"); m_pEngine.Evaluate("conf <- 0.95; zz<-qnorm(1-(1-conf)/2)"); m_pEngine.Evaluate("SE<-(slope/dpois(q, lambda=" + txtDf1.Text + ")) *sqrt(p*(1-p)/n)"); m_pEngine.Evaluate("fit.value<-int+slope*q"); break; default: //sbCommand.Append("qqPlot(" + strVar1Name + ", dist='norm');"); strTitle = "Normal Quantile"; m_pEngine.Evaluate("q <- qnorm(p)"); dblTransformedX = m_pEngine.Evaluate("q").AsNumeric().ToArray(); m_pEngine.Evaluate("x <- qnorm(c(0.25, 0.75))"); //Calculate Slope and y intercept m_pEngine.Evaluate("slope <- diff(y)/diff(x)"); m_pEngine.Evaluate("int <- y[1L] - slope * x[1L]"); dblSlope = m_pEngine.Evaluate("slope").AsNumeric().ToArray().First(); dblyInt = m_pEngine.Evaluate("int").AsNumeric().ToArray().First(); //Calculate Low and upper bound m_pEngine.Evaluate("conf <- 0.95; zz<-qnorm(1-(1-conf)/2)"); m_pEngine.Evaluate("SE<-(slope/dnorm(q))*sqrt(p*(1-p)/n)"); m_pEngine.Evaluate("fit.value<-int+slope*q"); break; } //Calculate Slope and y intercept //pEngine.Evaluate("slope <- diff(y)/diff(x)"); //double dblSlope = pEngine.Evaluate("diff(y)/diff(x)").AsNumeric().ToArray().First(); //double dblyInt = pEngine.Evaluate("y[1L] - slope * x[1L]").AsNumeric().ToArray().First(); //pSnippet.drawPlottoForm(strTitle, sbCommand.ToString()); //Calculate Upper-lower bounds double[] arrUpper = m_pEngine.Evaluate("fit.value+zz*SE").AsNumeric().ToArray(); double[] arrLower = m_pEngine.Evaluate("fit.value-zz*SE").AsNumeric().ToArray(); //QQ Plot frmQQPlotResults pfrmQQPlotResults = new frmQQPlotResults(); pfrmQQPlotResults.Text = "Quantile comparison plot of " + m_pTargetFLayer.Name; pfrmQQPlotResults.pChart.Series.Clear(); System.Drawing.Color pMarkerColor = System.Drawing.Color.Blue; var seriesPts = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "Points", Color = pMarkerColor, BorderColor = pMarkerColor, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point, MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle }; pfrmQQPlotResults.pChart.Series.Add(seriesPts); //Feature Value to Array //int i = 0; for (int j = 0; j < m_intNFeatureCount; j++) { //adblVar1[i] = Convert.ToDouble(pFeature.get_Value(intVar1Idx)); //adblVar2[i] = Convert.ToDouble(pFeature.get_Value(intVar2Idx)); //Add Pts seriesPts.Points.AddXY(dblTransformedX[j], dblSortedVariable[j]); } pfrmQQPlotResults.pChart.ChartAreas[0].AxisX.Title = strTitle; pfrmQQPlotResults.pChart.ChartAreas[0].AxisY.Title = m_strVar1Name; //Add Line var seriesLine = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "Line", Color = System.Drawing.Color.Red, //BorderColor = System.Drawing.Color.Black, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line }; pfrmQQPlotResults.pChart.Series.Add(seriesLine); seriesLine.Points.AddXY(dblTransformedX.Min(), dblTransformedX.Min() * dblSlope + dblyInt); seriesLine.Points.AddXY(dblTransformedX.Max(), dblTransformedX.Max() * dblSlope + dblyInt); //Confidence bounds is not working properly HK 042817 var upperLine = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "UpperLine", Color = System.Drawing.Color.Red, BorderDashStyle = ChartDashStyle.Dash, //BorderColor = System.Drawing.Color.Black, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line }; pfrmQQPlotResults.pChart.Series.Add(upperLine); var lowerLine = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "LowerLine", Color = System.Drawing.Color.Red, BorderDashStyle = ChartDashStyle.Dash, //BorderColor = System.Drawing.Color.Black, IsVisibleInLegend = false, IsXValueIndexed = false, ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line }; pfrmQQPlotResults.pChart.Series.Add(lowerLine); for (int j = 0; j < dblTransformedX.Length; j++) { lowerLine.Points.AddXY(dblTransformedX[j], arrLower[j]); upperLine.Points.AddXY(dblTransformedX[j], arrUpper[j]); } //pfrmTemp.dblBreaks = dblBreaks; //pfrmPtsPlot.intGraphType = 2; pfrmQQPlotResults.strDistribution = cboDistribution.Text; pfrmQQPlotResults.strDF1 = txtDf1.Text; pfrmQQPlotResults.strDF2 = txtDf2.Text; pfrmQQPlotResults.adblVar1 = dblSortedVariable; pfrmQQPlotResults.adblVar2 = dblTransformedX; pfrmQQPlotResults.strVar1Name = m_strVar1Name; pfrmQQPlotResults.m_pForm = m_pForm; pfrmQQPlotResults.m_pActiveView = m_pActiveView; pfrmQQPlotResults.m_pFLayer = m_pTargetFLayer; pfrmQQPlotResults.pMakerColor = pMarkerColor; //pfrmTemp.strFieldName = strFieldName; pfrmQQPlotResults.Show(); //this.Close(); } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }