public static CorrelationCalculator Create(CorrelationType type) { switch (type) { case CorrelationType.Pearson: return(new PearsonCorrelationCalculator()); case CorrelationType.Kendall: return(new KendallCorrelationCalculator()); default: return(new PearsonCorrelationCalculator()); } }
public Correlation Correlation(ISeries <double> input, int period, CorrelationType corrType, int periodPctChange) { if (cacheCorrelation != null) { for (int idx = 0; idx < cacheCorrelation.Length; idx++) { if (cacheCorrelation[idx] != null && cacheCorrelation[idx].Period == period && cacheCorrelation[idx].CorrType == corrType && cacheCorrelation[idx].PeriodPctChange == periodPctChange && cacheCorrelation[idx].EqualsInput(input)) { return(cacheCorrelation[idx]); } } } return(CacheIndicator <Correlation>(new Correlation() { Period = period, CorrType = corrType, PeriodPctChange = periodPctChange }, input, ref cacheCorrelation)); }
public static double Correlation(this IList <double> datasetX, IList <double> datasetY, CorrelationType correlationType) { if (datasetX.Count != datasetY.Count) { throw new ArgumentException("Datasets should have the same dimensions"); } switch (correlationType) { case CorrelationType.Pearson: return(CalculatePearsonCorrelation(datasetX, datasetY)); case CorrelationType.Spearman: return(CalculateSpearmanRankCorrelation(datasetX, datasetY)); default: throw new ArgumentException("The specified correlation is not supported"); } }
public static Dictionary <TId, List <CorrelationType> > DetermineCorrelationSignificances(Model model, Dictionary <TId, List <double> > correlationCoefficients) { if (model == null) { throw new ArgumentNullException("model"); } if (model.Criteria == null || model.Experiments == null) { throw new InvalidOperationException(); } if (correlationCoefficients == null) { throw new ArgumentNullException("correlationCoefficients"); } int activeExperimentsCount = model.Experiments.CountActiveExperiments(); if (activeExperimentsCount < 3) { throw new InvalidOperationException(); } Dictionary <TId, List <CorrelationType> > correlationSignificances = new Dictionary <TId, List <CorrelationType> >(model.Criteria.Count); Dictionary <double, double> significanceRow = FindSignificanceRow(activeExperimentsCount - 2); foreach (KeyValuePair <TId, List <double> > correlationRow in correlationCoefficients) { correlationSignificances[correlationRow.Key] = new List <CorrelationType>(model.Criteria.Count); for (int i = 0; i < correlationRow.Value.Count; i++) { double actualCoefficient = correlationRow.Value[i]; double pValue = 0.0; foreach (KeyValuePair <double, double> significance in significanceRow) { if (significance.Value >= actualCoefficient) { pValue = significance.Key; break; } } CorrelationType correlationType = CorrelationType.Correlated; if (pValue >= 0.1) { correlationType = CorrelationType.ResultsNotSignificant; } else if (pValue < 0.1 && pValue > 0.001) { correlationType = CorrelationType.Correlated; } else if (pValue <= 0.001) { correlationType = CorrelationType.SignificantlyRelated; } correlationSignificances[correlationRow.Key].Add(correlationType); } } return(correlationSignificances); }
public Indicators.Correlation Correlation(ISeries <double> input, int period, CorrelationType corrType, int periodPctChange) { return(indicator.Correlation(input, period, corrType, periodPctChange)); }
public Correlation Correlation(int period, CorrelationType corrType, int periodPctChange) { return(Correlation(Input, period, corrType, periodPctChange)); }