示例#1
0
        /// <summary>
        /// performs an addition / subtraction or pass thru rule
        /// </summary>
        /// <returns>object</returns>
        public override object Execute()
        {
            object result = null;

            if (!this.HasRun)
            {
                // prepare IAnalysisStatisticContext information to be sent to the
                // KMSurvival
                IAnalysisStatistic KMSurvival = null;

                // connection string
                // 1 term / column name
                // 1 dependent variable /column name
                // tablname

                Dictionary <string, string> setProperties = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                if (this.Context.CurrentRead == null)
                {
                    setProperties.Add("TableName", "");
                }
                else
                {
                    setProperties.Add("TableName", this.Context.CurrentRead.Identifier);
                }
                setProperties.Add("CommandText", this.commandText);
                Dictionary <string, string> inputVariableList = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

                setProperties.Add("BLabels", "Yes;No;Missing"); // TODO: Replace Yes, No, Missing with global vars

                //ToDo: Move calls to inputVariableList.Add up into applicable function above: Rule_KMSurv or SetOption
                //
                inputVariableList.Add("time_variable", time_variable);
                inputVariableList.Add("group_variable", group_variable);

                //inputVariableList.Add("time_function", time_function);
                inputVariableList.Add("censor_variable", censor_variable);
                inputVariableList.Add("uncensored_value", uncensored_value);
                inputVariableList.Add("time_unit", time_unit);

                inputVariableList.Add("out_table", out_table);
                inputVariableList.Add("graph_type", graph_type);
                inputVariableList.Add("weight_variable", weight_variable);


                IDataSource DataSource = this.Context.GetDefaultIDataSource();

                AnalysisStatisticExecuteHost statisticHost = new AnalysisStatisticExecuteHost(this.Context, setProperties, DataSource, inputVariableList, this.Context.CurrentSelect.ToString(), this.Context.AnalysisInterpreterHost);

                KMSurvival = this.Context.GetStatistic("KaplanMeierSurvival", statisticHost);
                KMSurvival.Execute();
                this.HasRun = true;
            }

            return(result);
        }
        /// <summary>
        /// performs an addition / subtraction or pass thru rule
        /// </summary>
        /// <returns>object</returns>
        public override object Execute()
        {
            object result = null;

            if (!this.HasRun)
            {
                // prepare IAnalysisStatisticContext information to be sent to the
                // CoxPH
                IAnalysisStatistic CoxPH = null;

                // connection string
                // 1 term / column name
                // 1 dependent variable /column name
                // tablname

                Dictionary <string, string> setProperties = this.Context.GetGlobalSettingProperties();
                if (this.Context.CurrentRead == null)
                {
                    setProperties.Add("TableName", "");
                }
                else
                {
                    setProperties.Add("TableName", this.Context.CurrentRead.Identifier);
                }
                setProperties.Add("CommandText", this.commandText);
                Dictionary <string, string> inputVariableList = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

                inputVariableList.Add("time_variable", time_variable);
                StringBuilder sb = new StringBuilder();
                foreach (string s in this.CovariateList)
                {
                    sb.Append(s);
                    sb.Append(",");
                }
                if (sb.Length > 0)
                {
                    sb.Length = sb.Length - 1;
                }
                inputVariableList.Add("CovariateList", sb.ToString());
                sb.Length = 0;
                foreach (string s in this.DiscreteList)
                {
                    sb.Append(s);
                    sb.Append(",");
                }
                if (this.DiscreteList.Count > 0)
                {
                    sb.Length = sb.Length - 1;
                }

                inputVariableList.Add("DiscreteList", sb.ToString());
                inputVariableList.Add("time_function", time_function);
                inputVariableList.Add("censor_variable", censor_variable);
                inputVariableList.Add("censor_value", censor_value);
                inputVariableList.Add("time_unit", time_unit);

                inputVariableList.Add("out_table", out_table);
                inputVariableList.Add("graph_type", graph_type);
                inputVariableList.Add("weightvar", weightvar);

                sb.Length = 0;

                foreach (string s in StrataVarList)
                {
                    sb.Append(s);
                    sb.Append(",");
                }
                if (sb.Length > 0)
                {
                    sb.Length = sb.Length - 1;
                }
                inputVariableList.Add("StrataVarList", sb.ToString());

                sb.Length = 0;
                foreach (string s in GraphVariableList)
                {
                    sb.Append(s);
                    sb.Append(",");
                }
                if (sb.Length > 0)
                {
                    sb.Length = sb.Length - 1;
                }
                inputVariableList.Add("GraphVariableList", sb.ToString());

                IDataSource DataSource = this.Context.GetDefaultIDataSource();

                AnalysisStatisticExecuteHost statisticHost = new AnalysisStatisticExecuteHost(this.Context, setProperties, DataSource, inputVariableList, this.Context.CurrentSelect.ToString(), this.Context.AnalysisInterpreterHost);

                CoxPH = this.Context.GetStatistic("CoxProportionalHazards", statisticHost);
                CoxPH.Execute();
                this.HasRun = true;
            }

            return(result);
        }
示例#3
0
        /// <summary>
        /// performs an addition / subtraction or pass thru rule
        /// </summary>
        /// <returns>object</returns>
        public override object Execute()
        {
            object result = null;

            if (!this.HasRun)
            {
                // Create the AnalysisStatisticExecuteHost analysisStatisticExecuteHost = null;
                // Create dynamic reference to the Linear Regression assembly
                // call the LinearRegress.ProcessData(IAnalysisStatisticExecuteHost AnalysisStatisticExecuteHost);
                // method
                IAnalysisStatistic LinearRegress = null;

                // connection string
                // 1 term / column name
                // 1 dependent variable /column name
                // tablname

                Dictionary <string, string> setProperties = this.Context.GetGlobalSettingProperties();
                if (this.Context.CurrentRead == null)
                {
                    setProperties.Add("TableName", "");
                }
                else
                {
                    setProperties.Add("TableName", this.Context.CurrentRead.Identifier);
                }

                setProperties.Add("CommandText", this.commandText);
                Dictionary <string, string> inputVariableList = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                inputVariableList.Add(this.Identifier, "DependVar");
                bool containsDummyVariables = false;

                if (this.nointercept == false)
                {
                    setProperties.Add("Intercept", "true");
                }
                else
                {
                    setProperties.Add("Intercept", "false");
                }

                if (!string.IsNullOrEmpty(this.pvalue))
                {
                    double p       = 0.95;
                    bool   success = Double.TryParse(this.pvalue.Replace("%", string.Empty), out p);
                    if (success)
                    {
                        setProperties.Add("P", p.ToString());
                    }
                }

                Configuration config = Configuration.GetNewInstance();

                setProperties.Add("BLabels", config.Settings.RepresentationOfYes + ";" + config.Settings.RepresentationOfNo + ";" + config.Settings.RepresentationOfMissing); // TODO: Replace Yes, No, Missing with global vars

                //// Make sure dummy vars aren't split up either!
                //if(this.TermList.Contains("(") || this.TermList.Contains(")"))
                //{
                //    this.TermList = this.TermList.Replace("( ", "(");
                //    this.TermList = this.TermList.Replace(" )", ")");
                //    containsDummyVariables = true;
                //}

                //string[] terms;
                //// Make sure each interaction term isn't split up!
                //this.TermList = this.TermList.Replace(" *", "*");
                //this.TermList = this.TermList.Replace("* ", "*");
                //terms = this.TermList.Split(' ');

                //foreach (string s in terms)
                //{


                //    if (!s.Contains("*") && s.Contains("(") && s.Contains(")"))
                //    {
                //        // dummy variables (discrete terms) get added to the terms list, but this is handled in the regression code
                //        inputVariableList.Add(s.Replace("(", string.Empty).Replace(")", string.Empty), "Discrete");
                //    }
                //    else if (s.Contains("*"))
                //    {
                //        inputVariableList.Add(s, "Term");
                //    }
                //    else
                //    {
                //        inputVariableList.Add(s, "Unsorted");
                //    }
                //}

                foreach (string s in TermList)
                {
                    if (!s.Contains("*") && s.Contains("(") && s.Contains(")"))
                    {
                        // dummy variables (discrete terms) get added to the terms list, but this is handled in the regression code
                        inputVariableList.Add(s.Replace("(", string.Empty).Replace(")", string.Empty), "Discrete");
                    }
                    else if (s.Contains("*"))
                    {
                        inputVariableList.Add(s, "Term");
                    }
                    else
                    {
                        inputVariableList.Add(s, "Unsorted");
                    }
                }

                if (!string.IsNullOrEmpty(this.WeightVar))
                {
                    // Make sure our weight variable isn't a term or the dependent variable. This shouldn't occur through the UI, but the user can still type something like this in manually
                    if (inputVariableList.ContainsKey(this.WeightVar))
                    {
                        Dictionary <string, string> args = new Dictionary <string, string>();
                        args.Add("COMMANDNAME", CommandNames.REGRESS);
                        args.Add("COMMANDTEXT", commandText.Trim());
                        args.Add("HTMLRESULTS", "<br clear=\"all\" /><p align=\"left\"><b><tlt>Weight variable cannot be a term or dependent variable</tlt></b></p>");

                        this.Context.AnalysisCheckCodeInterface.Display(args);

                        return(result);
                    }
                    inputVariableList.Add(this.WeightVar, "WeightVar");
                }

                IDataSource DataSource = this.Context.GetDefaultIDataSource();

                AnalysisStatisticExecuteHost statisticHost = new AnalysisStatisticExecuteHost(this.Context, setProperties, DataSource, inputVariableList, this.Context.CurrentSelect.ToString(), this.Context.AnalysisInterpreterHost);

                LinearRegress = this.Context.GetStatistic("LinearRegression", statisticHost);
                LinearRegress.Execute();
                this.HasRun = true;
            }

            return(result);
        }
        /// <summary>
        /// performs an addition / subtraction or pass thru rule
        /// </summary>
        /// <returns>object</returns>
        public override object Execute()
        {
            object result = null;

            if (!this.HasRun)
            {
                IAnalysisStatistic LogisticRegress = null;

                //View view = null;

                //if (Context.CurrentProject != null)
                //{
                //    view = Context.CurrentProject.GetViewByName(Context.CurrentRead.Identifier);
                //}

                // connection string
                // 1 term / column name
                // 1 dependent variable /column name
                // tablname

                Dictionary <string, string> setProperties = this.Context.GetGlobalSettingProperties();
                if (this.Context.CurrentRead == null)
                {
                    setProperties.Add("TableName", "");
                }
                else
                {
                    setProperties.Add("TableName", this.Context.CurrentRead.Identifier);
                }
                setProperties.Add("CommandText", this.commandText);
                Dictionary <string, string> inputVariableList = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                inputVariableList.Add(this.Identifier, "DependVar");

                if (this.nointercept == false)
                {
                    setProperties.Add("Intercept", "true");
                    inputVariableList.Add("true", "Intercept");
                }
                else
                {
                    setProperties.Add("Intercept", "false");
                    inputVariableList.Add("false", "Intercept");
                }

                if (!string.IsNullOrEmpty(this.pvalue))
                {
                    double p       = 0.95;
                    bool   success = Double.TryParse(this.pvalue.Replace("%", string.Empty), out p);
                    if (success)
                    {
                        setProperties.Add("P", p.ToString());
                        inputVariableList.Add(p.ToString(), "P");
                    }
                }

                // Make sure dummy vars aren't split up either!
                if (this.TermList.Contains("(") || this.TermList.Contains(")"))
                {
                    this.TermList = this.TermList.Replace("( ", "(");
                    this.TermList = this.TermList.Replace(" )", ")");
                }

                string[] terms;
                // Make sure each interaction term isn't split up!
                this.TermList = this.TermList.Replace(" *", "*");
                this.TermList = this.TermList.Replace("* ", "*");
                terms         = this.TermList.Split(' ');

                foreach (string s in terms)
                {
                    if (!s.Contains("*"))
                    {
                        if ((s.Contains("(") && s.Contains(")")))// || (view != null && view.Fields.Contains(s) && view.Fields[s] is Epi.Fields.YesNoField))
                        {
                            inputVariableList.Add(s.Replace("(", string.Empty).Replace(")", string.Empty), "Discrete");
                        }
                        else
                        {
                            inputVariableList.Add(s, "Unsorted");
                        }
                    }
                    else
                    {
                        inputVariableList.Add(s, "Term");
                    }
                }

                if (!string.IsNullOrEmpty(this.WeightVar))
                {
                    // Make sure our weight variable isn't a term or the dependent variable. This shouldn't occur through the UI, but the user can still type something like this in manually
                    if (inputVariableList.ContainsKey(this.WeightVar))
                    {
                        Dictionary <string, string> args = new Dictionary <string, string>();
                        args.Add("COMMANDNAME", CommandNames.LOGISTIC);
                        args.Add("COMMANDTEXT", commandText.Trim());
                        args.Add("HTMLRESULTS", "<br clear=\"all\" /><p align=\"left\"><b><tlt>Weight variable cannot be a term or dependent variable</tlt></b></p>");

                        this.Context.AnalysisCheckCodeInterface.Display(args);

                        return(result);
                    }
                    inputVariableList.Add(this.WeightVar, "WeightVar");
                }

                if (!string.IsNullOrEmpty(this.MatchVar))
                {
                    // Make sure our weight variable isn't a term or the dependent variable. This shouldn't occur through the UI, but the user can still type something like this in manually
                    if (inputVariableList.ContainsKey(this.MatchVar))
                    {
                        Dictionary <string, string> args = new Dictionary <string, string>();
                        args.Add("COMMANDNAME", CommandNames.LOGISTIC);
                        args.Add("COMMANDTEXT", commandText.Trim());
                        args.Add("HTMLRESULTS", "<br clear=\"all\" /><p align=\"left\"><b><tlt>Match variable cannot be a term or dependent variable</tlt></b></p>");

                        this.Context.AnalysisCheckCodeInterface.Display(args);

                        return(result);
                    }
                    inputVariableList.Add(this.MatchVar, "MatchVar");
                }

                IDataSource DataSource = this.Context.GetDefaultIDataSource();

                AnalysisStatisticExecuteHost statisticHost = new AnalysisStatisticExecuteHost(this.Context, setProperties, DataSource, inputVariableList, this.Context.CurrentSelect.ToString(), this.Context.AnalysisInterpreterHost);

                LogisticRegress = this.Context.GetStatistic("LogisticRegression", statisticHost);
                LogisticRegress.Execute();

                this.HasRun = true;
            }

            return(result);
        }
        public override object Execute()
        {
            object result = null;

            if (false == hasRun)
            {
                IAnalysisStatistic          summarizePlugin   = null;
                Dictionary <string, string> setProperties     = Context.GetGlobalSettingProperties();
                Dictionary <string, string> inputVariableList = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                StringBuilder stringBuilder = new StringBuilder();

                foreach (string aggregate in aggregateList)
                {
                    stringBuilder.Append(aggregate);
                    stringBuilder.Append(",");
                }

                stringBuilder.Length = stringBuilder.Length - 1;

                inputVariableList.Add("AggregateList", stringBuilder.ToString());
                stringBuilder.Length = 0;
                bool HasAggregateElements = false;

                foreach (KeyValuePair <string, string> aggregatePair in aggregateElement)
                {
                    stringBuilder.Append(aggregatePair.Key);
                    stringBuilder.Append("=");
                    stringBuilder.Append(aggregatePair.Value);
                    stringBuilder.Append(",");
                    HasAggregateElements = true;
                }

                if (HasAggregateElements)
                {
                    stringBuilder.Length = stringBuilder.Length - 1;
                }

                inputVariableList.Add("AggregateElementList", stringBuilder.ToString());

                if (strataVariableList.Count > 0)
                {
                    stringBuilder.Length = 0;

                    foreach (string strataVariable in strataVariableList)
                    {
                        stringBuilder.Append(strataVariable);
                        stringBuilder.Append(",");
                    }

                    stringBuilder.Length = stringBuilder.Length - 1;
                    inputVariableList.Add("StratvarList", stringBuilder.ToString());
                }

                if (participatingVariableList.Count > 0)
                {
                    stringBuilder.Length = 0;

                    foreach (string participatingVariable in participatingVariableList)
                    {
                        stringBuilder.Append(participatingVariable);
                        stringBuilder.Append(",");
                    }

                    stringBuilder.Length = stringBuilder.Length - 1;
                    inputVariableList.Add("ParticipatingVariableList", stringBuilder.ToString());
                }

                inputVariableList.Add("OutTable", outTableName);
                inputVariableList.Add("WeightVar", weightVariable);
                inputVariableList.Add("commandText", commandText);

                if (Context.CurrentRead == null)
                {
                    inputVariableList.Add("TableName", "");
                }
                else
                {
                    inputVariableList.Add("TableName", Context.CurrentRead.Identifier);
                }

                EpiInfo.Plugin.IDataSource   DataSource    = Context.GetDefaultIDataSource();
                AnalysisStatisticExecuteHost statisticHost = new AnalysisStatisticExecuteHost(Context, setProperties, DataSource, inputVariableList, Context.CurrentSelect.ToString(), Context.AnalysisInterpreterHost);
                summarizePlugin = Context.GetStatistic("Summarize", statisticHost);
                summarizePlugin.Execute();
                summarizePlugin = null;

                hasRun = true;
            }
            return(result);
        }