Exemplo n.º 1
0
        /// <summary>
        ///     Tests whether the means of two samples are different.
        /// </summary>
        /// <param name="sample1">The first sample.</param>
        /// <param name="sample2">The second sample.</param>
        /// <param name="hypothesizedDifference">The hypothesized sample difference.</param>
        /// <param name="assumeEqualVariances">True to assume equal variances, false otherwise. Default is true.</param>
        /// <param name="alternate">The alternative hypothesis (research hypothesis) to test.</param>
        public TwoSampleZTest(DescriptiveResult sample1, DescriptiveResult sample2,
                              double hypothesizedDifference = 0, TwoSampleHypothesis alternate = TwoSampleHypothesis.ValuesAreDifferent)
        {
            // References: http://en.wikipedia.org/wiki/Student's_t-test#Worked_examples

            Compute(sample1.Mean, sample2.Mean, sample1.Variance / sample1.Count, sample2.Variance / sample2.Count,
                    hypothesizedDifference, alternate);
        }
Exemplo n.º 2
0
        public static void FromDescriptiveResult(this ModelStateDictionary source, DescriptiveResult result)
        {
            if (result.Succeeded)
            {
                return;
            }

            source.AddModelError(string.Empty, string.Join("</br>", result.Errors.Select(d => d.Description)));
        }
Exemplo n.º 3
0
        public async Task <DescriptiveResult> DeleteAsync(int id)
        {
            var item = await _dbContext.CustomCommands.FirstOrDefaultAsync(d => d.Id == id);

            _dbContext.Entry(item).State = EntityState.Deleted;

            return(await _dbContext.SaveChangesAsync() > 0
                                ? DescriptiveResult.Success
                                : DescriptiveResult.Fail().With(string.Empty, "Failed to delete command"));
        }
Exemplo n.º 4
0
        public GeneralHypothesisTest(string firstLabel, DescriptiveResult sample1, string secondLabel,
                                     DescriptiveResult sample2, double hypothesizedDifference = 0,
                                     TwoSampleHypothesis alternate = TwoSampleHypothesis.ValuesAreDifferent)
        {
            int samples1 = sample1.Count;
            int samples2 = sample2.Count;

            HypothesizedDifference = Math.Abs(hypothesizedDifference);

            var s1 = new SampleInfo
            {
                Name   = firstLabel,
                Count  = sample1.Count,
                Mean   = sample1.Mean,
                StdDev = sample1.StdDev
            };

            var s2 = new SampleInfo
            {
                Name   = secondLabel,
                Count  = sample2.Count,
                Mean   = sample2.Mean,
                StdDev = sample2.StdDev
            };

            Result = new ComparisonResult
            {
                FirstSample            = s1,
                SecondSample           = s2,
                Hypothesis             = alternate,
                HypothesizedDifference = HypothesizedDifference
            };


            if (samples1 < 30 || samples2 < 30)
            {
                _tTest                    = new TwoSampleTTest(sample1, sample2, false, HypothesizedDifference, alternate);
                Result.Confidence         = _tTest.Confidence;
                Result.ObservedDifference = _tTest.ObservedDifference;
                Result.Significant        = _tTest.Significant;
                Result.Size               = _tTest.Size;
                Result.StandardError      = _tTest.StandardError;
            }
            else
            {
                _zTest                    = new TwoSampleZTest(sample1, sample2, HypothesizedDifference, alternate);
                Result.Confidence         = _zTest.Confidence;
                Result.ObservedDifference = _zTest.ObservedDifference;
                Result.Significant        = _zTest.Significant;
                Result.Size               = _zTest.Size;
                Result.StandardError      = _zTest.StandardError;
            }
        }
Exemplo n.º 5
0
        public async Task <DescriptiveResult> AddAsync(string commandName, string program, string arguments, string permissionName)
        {
            permissionName = permissionName.ToLowerInvariant();

            if (_dbContext.CustomCommands.FirstOrDefault(d => d.PermissionName == permissionName) != null)
            {
                return(DescriptiveResult.Fail(new DescriptiveError("0",
                                                                   $"a similar permission name [{permissionName}] already exists")));
            }

            _dbContext.CustomCommands.Add(new CustomCommand()
            {
                Program        = program,
                Argument       = arguments,
                PermissionName = permissionName,
                CommandName    = commandName
            });

            return(await _dbContext.SaveChangesAsync() > 0
                                ? DescriptiveResult.Success
                                : DescriptiveResult.Fail().With(string.Empty, "Save process failed."));
        }
Exemplo n.º 6
0
 public GeneralHypothesisTest(DescriptiveResult sample1, DescriptiveResult sample2,
                              double hypothesizedDifference = 0,
                              TwoSampleHypothesis alternate = TwoSampleHypothesis.ValuesAreDifferent)
     : this("first", sample1, "second", sample2, hypothesizedDifference, alternate)
 {
 }