internal string ForRLanguage(string listName) { const string ME_CV_RANGE = "me_CVRange"; const string ME_SD_RANGE = "MESDRange"; const string NUMERIC0 = "numeric(0)"; StringBuilder sb = new StringBuilder(); StringBuilder sbA; StringBuilder sbW; sb.AppendFormat("{0} <- list()\n", listName); // L'erreur de mesure if (!this.MEAny) { sb.AppendFormat("{0}${1} <- {2}\n", listName, ME_CV_RANGE, NUMERIC0); sb.AppendFormat("{0}${1} <- {2}\n", listName, ME_SD_RANGE, NUMERIC0); } else { sb.AppendFormat("{0}${1} <- c({2:R}, {3:R})\n", listName, ME.ThroughCV ? ME_CV_RANGE : ME_SD_RANGE, this.ME.Minimum, this.ME.Maximum); sb.AppendFormat("{0}${1} <- {2}\n", listName, ME.ThroughCV ? "MESDRange" : "me_CVRange", NUMERIC0); } sb.AppendFormat("{0}$WorkerInfoComplete <- {1}", listName, IsWorkerInfoComplete ? "T" : "F").AppendLine(); foreach (Measure.MeasureType ct in Enum.GetValues(typeof(Measure.MeasureType))) { if (ct == Measure.MeasureType.Interval) { Tuple <string, string, string> t = ForRLanguageIntervals(listName, measuresByCensoringType[ct]); sb.Append(t.Item1).Append(t.Item2).Append(t.Item3); continue; } sbA = new StringBuilder(); sbW = new StringBuilder(); sbA.AppendFormat("{0}${1}$values <-", listName, ct.ToString()); sbW.AppendFormat("{0}${1}$worker <-", listName, ct.ToString()); if (measuresByCensoringType[ct].Count == 0) { sbA.AppendFormat(" {0}\n", NUMERIC0); sbW.Append(" character(0)\n"); } else { sbA.Append("c("); sbW.Append("c("); Measure currentMeasure = measuresByCensoringType[ct][0]; sbA.AppendFormat("{0:R}", currentMeasure.A); if (currentMeasure.Worker == null) { sbW.Append("NA"); } else { sbW.AppendFormat("\"{0}\"", currentMeasure.Worker.Tag); } for (int i = 1; i < measuresByCensoringType[ct].Count; i++) { currentMeasure = measuresByCensoringType[ct][i]; sbA.AppendFormat(", {0:R}", currentMeasure.A); if (currentMeasure.Worker == null) { sbW.Append(", NA"); } else { sbW.AppendFormat(", \"{0}\"", currentMeasure.Worker.Tag); } } sbA.Append(")\n"); sbW.AppendFormat(")\n"); } sb.Append(sbA).Append(sbW); } string sbStr = sb.ToString(); return(sbStr); }
internal WorkerData(BetweenWorkerModel parent) { this.parentModel = parent; this.logNormalDistrn = this.parentModel.OutcomeIsLogNormallyDistributed; Data = parent.Data; workerDigests = new WorkerDigest[Data.NWorkers]; int i = 0; this.MeasureCountByWorker = new int[Data.NWorkers]; foreach (Worker w in Data.WorkersByOrdinal) { MeasureCountByWorker[i] = Data.MeasuresByWorker[w].Count; workerDigests[i] = new WorkerDigest(ordinal: i, mean: 0, measureCount: Data.MeasuresByWorker[w].Count); i++; } DFRecordByMeasureType.Add(Measure.MeasureType.Uncensored, new List <DfRecord>()); DFRecordByMeasureType.Add(Measure.MeasureType.GreaterThan, new List <DfRecord>()); DFRecordByMeasureType.Add(Measure.MeasureType.LessThan, new List <DfRecord>()); DFRecordByMeasureType.Add(Measure.MeasureType.Interval, new List <DfRecord>()); df = new DfRecord[Data.N]; int j = 0; Positions[(int)Measure.MeasureType.Uncensored] = new Position(j, Data.UncensoredMeasures.Length); for (i = 0; i < Data.UncensoredMeasures.Length; i++) { int workerOrdinal = Data.UncensoredMeasures[i].Worker.Ordinal; Measure m = Data.UncensoredMeasures[i]; m.WorkerDataOrdinal = j; df[j] = new DfRecord( measureOrdinal: j, genValue: this.logNormalDistrn ? Math.Log(m.A) : m.A, workerOrdinal: workerOrdinal, workerDigest: workerDigests[workerOrdinal]); DFRecordByMeasureType[Measure.MeasureType.Uncensored].Add(df[j]); j++; } Positions[(int)Measure.MeasureType.GreaterThan] = new Position(j, Data.GT.Length); for (i = 0; i < Data.GTMeasures.Length; i++) { int workerOrdinal = Data.GTMeasures[i].Worker.Ordinal; Measure m = Data.GTMeasures[i]; m.WorkerDataOrdinal = j; df[j] = new DfRecord( measureOrdinal: j, genValue: Tools.ND, workerOrdinal: workerOrdinal, workerDigest: workerDigests[workerOrdinal]); DFRecordByMeasureType[Measure.MeasureType.GreaterThan].Add(df[j]); j++; } Positions[(int)Measure.MeasureType.LessThan] = new Position(j, Data.LT.Length); for (i = 0; i < Data.LTMeasures.Length; i++) { int workerOrdinal = Data.LTMeasures[i].Worker.Ordinal; Measure m = Data.LTMeasures[i]; m.WorkerDataOrdinal = j; df[j] = new DfRecord( measureOrdinal: j, genValue: Tools.ND, workerOrdinal: workerOrdinal, workerDigest: workerDigests[workerOrdinal]); DFRecordByMeasureType[Measure.MeasureType.LessThan].Add(df[j]); j++; } Positions[(int)Measure.MeasureType.Interval] = new Position(j, Data.IntervalGT.Length); for (i = 0; i < Data.IntervalMeasures.Length; i++) { int workerOrdinal = Data.IntervalMeasures[i].Worker.Ordinal; Measure m = Data.IntervalMeasures[i]; m.WorkerDataOrdinal = j; df[j] = new DfRecord( measureOrdinal: j, genValue: Tools.ND, workerOrdinal: workerOrdinal, workerDigest: workerDigests[workerOrdinal]); DFRecordByMeasureType[Measure.MeasureType.Interval].Add(df[j]); j++; } this.WorkerIds = df.Select(rec => rec.WorkerOrdinal).ToArray(); UpdatePublicProperties(); }
private Tuple <string, string, string> ForRLanguageIntervals(string listName, List <Measure> intervals) { //RData$uncensored < -c(0.406, 0.597, 0.718312913) //RData$rightCensored < -c(0.2, 0.2, 0.2, 0.2) //RData$leftCensored < -c(0.6) //RData$intervalCensored$left < -c(RData$intervalCensored$right < -0.4, 0.4) //c(0.6, 0.6) StringBuilder sbA = new StringBuilder(); StringBuilder sbB = new StringBuilder(); StringBuilder sbW = new StringBuilder(); if (intervals.Count == 0) { sbA.AppendFormat("{0}${1}$left$values <- numeric(0)\n", listName, Measure.MeasureType.Interval); sbB.AppendFormat("{0}${1}$right$values <- numeric(0)\n", listName, Measure.MeasureType.Interval); sbW.AppendFormat("{0}${1}$worker <- character(0)\n", listName, Measure.MeasureType.Interval); } else { sbA.AppendFormat("{0}${1}$left$values <- c(", listName, Measure.MeasureType.Interval); sbB.AppendFormat("{0}${1}$right$values <- c(", listName, Measure.MeasureType.Interval); sbW.AppendFormat("{0}${1}$worker <- c(", listName, Measure.MeasureType.Interval); Measure currentMeasure = intervals[0]; sbA.AppendFormat("{0:R}", currentMeasure.A); sbB.AppendFormat("{0:R}", currentMeasure.B); if (currentMeasure.Worker == null) { sbW.Append("NA"); } else { sbW.AppendFormat("\"{0}\"", currentMeasure.Worker.Tag); } for (int i = 1; i < intervals.Count; i++) { currentMeasure = intervals[i]; sbA.AppendFormat(", {0}", currentMeasure.A); sbB.AppendFormat(", {0}", currentMeasure.B); if (currentMeasure.Worker == null) { sbW.Append(", NA"); } else { sbW.AppendFormat(", \"{0}\"", currentMeasure.Worker.Tag); } } sbA.Append(")\n"); sbB.Append(")\n"); sbW.Append(")\n"); } return(new Tuple <string, string, string>(sbA.ToString(), sbB.ToString(), sbW.ToString())); }