Beispiel #1
0
        private float CalculateLeveneValue(LeveneTestDTO leveneTestDTO)
        {
            CharacterVector namesV  = leveneTestDTO.Names;
            NumericVector   valuesV = leveneTestDTO.Values;

            _engine.Evaluate("library(car)");
            _engine.SetSymbol("namesV", namesV);
            _engine.SetSymbol("valuesV", valuesV);

            GenericVector testResult = _engine.Evaluate("levene.test(valuesV, namesV, center=mean)").AsList();
            float         p          = (float)testResult[2].AsNumeric().First();

            return(p);
        }
Beispiel #2
0
        private async Task <LeveneTestDTO> CreateGroupsForLevene(BusinessKey businessKey)
        {
            var rawData = await _oppeDBService.GetRawDataFactList(businessKey);

            if (!rawData.Any())
            {
                return(null);
            }

            var namesV = rawData.Select(l => l.Name).ToArray();
            var values = Array.ConvertAll(rawData.Select(l => l.Value).ToArray(), x => (double)x);

            LeveneTestDTO leveneTestDTO = new LeveneTestDTO
            {
                Names  = _engine.CreateCharacterVector(namesV),
                Values = _engine.CreateNumericVector(values)
            };

            return(leveneTestDTO);
        }
Beispiel #3
0
        public async Task <PValueDTO> GeneratePValueFactRecord(BusinessKey businessKey)
        {
            float leveneValue           = 0;
            float pValueUnequalVariance = 0;
            float pValueEqualVariance   = 0;
            float chiRatio = 0;
            float pValue   = 0;

            var phys = await _oppeDBService.GetRawDataFactList(businessKey);

            var   physCount = phys.Count(p => p.Name != "Peers");
            float physSum   = (float)phys.Where(p => p.Name != "Peers").Sum(p => p.Value);
            float physMean  = (float)(physCount == 0 ? 0 : physSum / physCount);

            var   peersCount = phys.Count(p => p.Name == "Peers");
            float peersSum   = (float)phys.Where(p => p.Name == "Peers").Sum(p => p.Value);
            float peersMean  = (float)(peersCount == 0 ? 0 : peersSum / peersCount);

            if (businessKey.isTTest)
            {
                LeveneTestDTO leveneTestDTO = await CreateGroupsForLevene(businessKey);

                if (leveneTestDTO == null)
                {
                    return(null);
                }
                leveneValue = CalculateLeveneValue(leveneTestDTO);

                TTestGroupsDTO tTestGroupsDto = await CreateGroupsForTTest(businessKey);

                if (tTestGroupsDto == null)
                {
                    return(null);
                }
                pValueUnequalVariance = CalculateUnequalVariance(tTestGroupsDto);
                pValueEqualVariance   = CalculateEqualVariance(tTestGroupsDto);

                pValue = leveneValue > 0.05 ? pValueEqualVariance : pValueUnequalVariance;

                if (float.IsNaN(leveneValue) || float.IsNaN(pValueUnequalVariance) || float.IsNaN(pValueEqualVariance))
                {
                    return(null);
                }
            }
            else
            {
                if (phys.Any())
                {
                    CalculateChiForPhys(phys, out chiRatio, out pValue);
                }
            }


            PValueDTO pValueDTO = new PValueDTO
            {
                CycleId               = businessKey.CycleId,
                SubGroupId            = (int)businessKey.SubGroupId,
                IndicatorId           = (int)businessKey.IndicatorId,
                PayrollId             = businessKey.PayrollId,
                PhysicianCount        = physCount,
                PhysicianSum          = physSum,
                PhysicianMean         = physMean,
                PeersCount            = peersCount,
                PeersSum              = peersSum,
                PeersMean             = peersMean,
                LeveneValue           = leveneValue,
                PValueUnequalVariance = pValueUnequalVariance,
                PValueEqualVariance   = pValueEqualVariance,
                ChiRatio              = chiRatio,
                PValue = pValue
            };

            return(pValueDTO);
        }