public void SaveResult(EffectSizeResult result, string filename)
        {
            using (var streamWriter = new StreamWriter(filename))
            {
                streamWriter.WriteLine("Effektstärkeergebnisse vom {0}:", DateTime.Now);
                streamWriter.WriteLine();

                streamWriter.WriteLine("1. Variable: {0}", _cohensSettings.SelectedFirstVariable);
                streamWriter.WriteLine("2. Variable: {0}", _cohensSettings.SelectedSecondVariable);
                if (!string.IsNullOrEmpty(_cohensSettings.SelectedFilterVariable))
                {
                    streamWriter.WriteLine("Filtervariable: {0}", _cohensSettings.SelectedFilterVariable);
                    streamWriter.WriteLine("Filter: {0}", _cohensSettings.Filter);
                }

                streamWriter.Write("Gleiche Varianzen: ");
                streamWriter.WriteLine(_cohensSettings.SameVariances ? "ja" : "nein");

                streamWriter.WriteLine();

                streamWriter.WriteLine("Cohen's d: {0}", result.Result);
                streamWriter.WriteLine("Konfidenzintervall: {0} - {1}", result.ConfidenceIntervalLower,
                                       result.ConfidenceIntervalUpper);
                streamWriter.WriteLine("Mittelwert 1. Variable: {0}", result.MeanValue1);
                streamWriter.WriteLine("Mittelwert 2. Variable: {0}", result.MeanValue2);
                streamWriter.WriteLine("Standardabweichung 1. Variable: {0}", result.StandardDeviation1);
                streamWriter.WriteLine("Standardabweichung 2. Variable: {0}", result.StandardDeviation2);
            }
        }
        public EffectSizeResult CalculateEffectSize()
        {
            var result = new EffectSizeResult();

            var firstVariableValues = GetVariableValues(_cohensSettings.SelectedFirstVariable, _excelDataSet);
            var secondVariableValues = GetVariableValues(_cohensSettings.SelectedSecondVariable, _excelDataSet);
            var filterVariableValues = GetFilterVariableValues(_cohensSettings, _excelDataSet);

            RemoveEmptyVariables(firstVariableValues, secondVariableValues, filterVariableValues);

            if (filterVariableValues != null)
            {
                ApplyFilterToVariables(_cohensSettings.Filter, firstVariableValues, secondVariableValues, filterVariableValues);
            }

            result.MeanValue1 = CalculateMeanValue(firstVariableValues);
            result.MeanValue2 = CalculateMeanValue(secondVariableValues);

            var sigma = CalculateSigma(_cohensSettings.SameVariances, firstVariableValues, secondVariableValues, result);

            result.Result = (result.MeanValue1 - result.MeanValue2) / sigma;

            var correlation = CalculateCorrelation(firstVariableValues, secondVariableValues);
            var standardError = CalculateStandardError(result.Result, correlation, firstVariableValues.Count);

            result.ConfidenceIntervalLower = result.Result - standardError * 1.96;
            result.ConfidenceIntervalUpper = result.Result + standardError * 1.96;

            return result;
        }
 private void OnSaveResult(EffectSizeResult result)
 {
     _saveFileService.Filter = "Ergebnisdatei|*.txt";
     if (_saveFileService.ShowDialog() == true)
     {
         var filename = _saveFileService.FileName;
         _resultExporter.SaveResult(result, filename);
     }
 }
 public ResultVM(EffectSizeResult result)
 {
     Result = result;
 }
        private double CalculateSigma(
            bool sameVariances,
            List<double> firstVariableValues,
            List<double> secondVariableValues,
            EffectSizeResult effectSizeResult)
        {
            double sigma;

            if (sameVariances)
            {
                sigma = CalculateVariance(firstVariableValues);
                sigma = Math.Sqrt(sigma);
            }
            else
            {
                var variance1 = CalculateVariance(firstVariableValues);
                effectSizeResult.StandardDeviation1 = Math.Sqrt(variance1);
                var variance2 = CalculateVariance(secondVariableValues);
                effectSizeResult.StandardDeviation2 = Math.Sqrt(variance2);
                var summand1 = (firstVariableValues.Count - 1) * variance1;
                var summand2 = (secondVariableValues.Count - 1) * variance2;

                var sum = summand1 + summand2;

                var bla = sum / (firstVariableValues.Count + secondVariableValues.Count);
                sigma = Math.Sqrt(bla);
            }

            return sigma;
        }
 public void SaveResult(EffectSizeResult result, string filename)
 {
     // TODO: implement saving result.
 }