Ejemplo n.º 1
0
        public void BivariateNullAssociation()
        {
            Random rng = new Random(31415926);

            // Create a data structure to hold the results of Pearson, Spearman, and Kendall tests.
            FrameTable data = new FrameTable();

            data.AddColumn <double>("r");
            data.AddColumn <double>("ρ");
            data.AddColumn <double>("τ");

            // Create variables to hold the claimed distribution of each test statistic.
            ContinuousDistribution PRD = null;
            ContinuousDistribution SRD = null;
            ContinuousDistribution KTD = null;

            // Generate a large number of bivariate samples and conduct our three tests on each.
            ContinuousDistribution xDistribution = new LognormalDistribution();
            ContinuousDistribution yDistribution = new CauchyDistribution();

            for (int j = 0; j < 100; j++)
            {
                List <double> x = new List <double>();
                List <double> y = new List <double>();
                for (int i = 0; i < 100; i++)
                {
                    x.Add(xDistribution.GetRandomValue(rng));
                    y.Add(yDistribution.GetRandomValue(rng));
                }

                TestResult PR = Bivariate.PearsonRTest(x, y);
                TestResult SR = Bivariate.SpearmanRhoTest(x, y);
                TestResult KT = Bivariate.KendallTauTest(x, y);

                PRD = PR.Statistic.Distribution;
                SRD = SR.Statistic.Distribution;
                KTD = KT.Statistic.Distribution;

                data.AddRow(new Dictionary <string, object>()
                {
                    { "r", PR.Statistic.Value }, { "ρ", SR.Statistic.Value }, { "τ", KT.Statistic.Value }
                });
            }

            Assert.IsTrue(data["r"].As <double>().KolmogorovSmirnovTest(PRD).Probability > 0.05);
            Assert.IsTrue(data["ρ"].As <double>().KolmogorovSmirnovTest(SRD).Probability > 0.05);
            Assert.IsTrue(data["τ"].As <double>().KolmogorovSmirnovTest(KTD).Probability > 0.05);
        }
Ejemplo n.º 2
0
        public static void Association()
        {
            double[] x = new double[] { -0.58, 0.92, 1.41, 1.62, 2.72, 3.14 };
            double[] y = new double[] { 1.00, 0.00, 2.00, 16.00, 18.0, 20.0 };

            TestResult pearson = Bivariate.PearsonRTest(x, y);

            Console.WriteLine($"Pearson {pearson.Statistic.Name} = {pearson.Statistic.Value}");
            Console.WriteLine($"{pearson.Type} P = {pearson.Probability}");

            TestResult spearman = Bivariate.SpearmanRhoTest(x, y);

            Console.WriteLine($"Spearman {spearman.Statistic.Name} = {spearman.Statistic.Value}");
            Console.WriteLine($"{spearman.Type} P = {spearman.Probability}");

            TestResult kendall = Bivariate.KendallTauTest(x, y);

            Console.WriteLine($"Kendall {kendall.Statistic.Name} = {kendall.Statistic.Value}");
            Console.WriteLine($"{kendall.Type} P = {kendall.Probability}");
        }