示例#1
0
    protected void PlaceAnovaTable(OneWayAnova anova, string dv, string iv, int numdigits)
    {
        var t = anova.Table;

        ASPxGridView gv = new ASPxGridView();

        gv.SettingsText.Title      = String.Format("ANOVA: <b>{0}</b> by {1}", dv, iv);
        gv.Settings.ShowTitlePanel = true;

        gv.DataSource = anova.Table;
        gv.DataBind();


        List <string> keepAsInt = new List <string> {
            "DegreesOfFreedom"
        };

        foreach (GridViewDataColumn col in gv.Columns)
        {
            string name = col.FieldName;


            if (keepAsInt.Contains(name))
            {
                col.PropertiesEdit.DisplayFormatString = String.Format("F0");
            }
            else
            {
                col.PropertiesEdit.DisplayFormatString = String.Format("F{0}", numdigits);
            }

            string caption = name;
            if (name == "DegreesOfFreedom")
            {
                caption = "DF";
            }
            else if (name == "SumOfSquares")
            {
                caption = "SS";
            }
            else if (name == "MeanSquares")
            {
                caption = "MS";
            }
            else if (name == "Significance")
            {
                caption = "p-value";
            }
            else if (name == "Statistic")
            {
                caption = "F";
            }

            col.Caption = caption;
        }

        //panel.Controls.Add(gv);
    }
示例#2
0
        protected override void EndProcessing()
        {
            var groups = _data.GroupBy(CategoryName);
            var test   = new OneWayAnova(groups.ToDoubleJaggedArrayOf(ValueName));

            test.FTest.Size = Size;

            WriteObject(test.Table);
        }
示例#3
0
        public void OneWayAnovaConstructorTest2()
        {
            // Test for unequal sample sizes

            double[][] samples =
            {
                new double[] {  6,  8,  4,  5 },
                new double[] {  8, 12,  9,11, 6, 8 },
                new double[] { 13,  9, 11,8, 12 },
            };


            double mean1 = samples[0].Mean();
            double dev1  = samples[0].StandardDeviation();

            double mean2 = samples[1].Mean();
            double dev2  = samples[1].StandardDeviation();

            double mean3 = samples[2].Mean();
            double dev3  = samples[2].StandardDeviation();


            OneWayAnova anova = new OneWayAnova(samples);



            Assert.AreEqual(anova.Table.Count, 3);
            Assert.AreEqual("Between-Groups", anova.Table[0].Source);
            Assert.AreEqual(53.383333333333326, anova.Table[0].SumOfSquares); // Sb
            Assert.AreEqual(2, anova.Table[0].DegreesOfFreedom);              // df
            Assert.AreEqual(26.691666666666663, anova.Table[0].MeanSquares);  // MSb
            Assert.AreEqual(6.4124124124124107, anova.Table[0].Statistic);
            Assert.AreEqual(0.012757639347451104, anova.Table[0].Significance.PValue);
            Assert.IsFalse(double.IsNaN(anova.Table[0].Significance.PValue));

            Assert.AreEqual("Within-Groups", anova.Table[1].Source);
            Assert.AreEqual(49.95000000000001, anova.Table[1].SumOfSquares); // Sw
            Assert.AreEqual(12, anova.Table[1].DegreesOfFreedom);            // df
            Assert.AreEqual(4.1625000000000005, anova.Table[1].MeanSquares); // MSw
            Assert.IsNull(anova.Table[1].Statistic);
            Assert.IsNull(anova.Table[1].Significance);

            Assert.AreEqual("Total", anova.Table[2].Source);
            Assert.AreEqual(103.33333333333334, anova.Table[2].SumOfSquares); // Sw
            Assert.AreEqual(14, anova.Table[2].DegreesOfFreedom);             // df
            Assert.IsNull(anova.Table[2].Statistic);
            Assert.IsNull(anova.Table[2].Significance);
        }
示例#4
0
        public void OneWayAnovaConstructorTest()
        {
            // Example from http://en.wikipedia.org/wiki/F_test

            double[][] samples =
            {
                new double[] {  6,  8,  4,  5, 3,  4 },
                new double[] {  8, 12,  9, 11, 6,  8 },
                new double[] { 13,  9, 11,  8, 7, 12 },
            };


            OneWayAnova target = new OneWayAnova(samples);

            Assert.AreEqual(target.Table.Count, 3);
            Assert.AreEqual("Between-Groups", target.Table[0].Source);
            Assert.AreEqual(84, target.Table[0].SumOfSquares);    // Sb
            Assert.AreEqual(2, target.Table[0].DegreesOfFreedom); // df
            Assert.AreEqual(42, target.Table[0].MeanSquares);     // MSb
            Assert.AreEqual(9.264705882352942, target.Table[0].Statistic);
            Assert.AreEqual(0.0023987773293928649, target.Table[0].Significance.PValue);

            Assert.AreEqual("Within-Groups", target.Table[1].Source);
            Assert.AreEqual(68, target.Table[1].SumOfSquares);                // Sw
            Assert.AreEqual(15, target.Table[1].DegreesOfFreedom);            // df
            Assert.AreEqual(4.5333333333333332, target.Table[1].MeanSquares); // MSw
            Assert.IsNull(target.Table[1].Statistic);
            Assert.IsNull(target.Table[1].Significance);

            Assert.AreEqual("Total", target.Table[2].Source);
            Assert.AreEqual(152, target.Table[2].SumOfSquares);    // Sw
            Assert.AreEqual(53, target.Table[2].DegreesOfFreedom); // df
            // Assert.IsNull(target.Table[2].MeanSquares); // MSw
            Assert.IsNull(target.Table[2].Statistic);
            Assert.IsNull(target.Table[2].Significance);
        }
示例#5
0
        public void OneWayAnovaConstructorTest()
        {
            // The following is the same example given in Wikipedia's page for the
            // F-Test [1]. Suppose one would like to test the effect of three levels
            // of a fertilizer on plant growth.

            // To achieve this goal, an experimenter has divided a set of 18 plants on
            // three groups, 6 plants each. Each group has received different levels of
            // the fertilizer under question.

            // After some months, the experimenter registers the growth for each plant.

            double[][] samples =
            {
                new double[] {  6,  8,  4,  5, 3,  4 },  // records for the first group
                new double[] {  8, 12,  9, 11, 6,  8 },  // records for the second group
                new double[] { 13,  9, 11,  8, 7, 12 },  // records for the third group
            };

            // Now, he would like to test whether the different fertilizer levels has
            // indeed caused any effect in plant growth. In other words, he would like
            // to test if the three groups are indeed significantly different.

            // To do it, he runs an ANOVA test:

            OneWayAnova anova = new OneWayAnova(samples);

            // After the Anova object has been created, one can display its findings
            // in the form of a standard ANOVA table by binding anova.Table to a
            // DataGridView or any other display object supporting data binding. To
            // illustrate, we could use Accord.NET's DataGridBox to inspect the
            // table's contents.

            // Accord.Controls.DataGridBox.Show(anova.Table);

            // The p-level for the analysis is about 0.002, meaning the test is
            // significant at the 5% significance level. The experimenter would
            // thus reject the null hypothesis, concluding there is a strong
            // evidence that the three groups are indeed different. Assuming the
            // experiment was correctly controlled, this would be an indication
            // that the fertilizer does indeed affect plant growth.

            // [1] http://en.wikipedia.org/wiki/F_test


            Assert.AreEqual(anova.Table.Count, 3);
            Assert.AreEqual("Between-Groups", anova.Table[0].Source);
            Assert.AreEqual(84, anova.Table[0].SumOfSquares);    // Sb
            Assert.AreEqual(2, anova.Table[0].DegreesOfFreedom); // df
            Assert.AreEqual(42, anova.Table[0].MeanSquares);     // MSb
            Assert.AreEqual(9.264705882352942, anova.Table[0].Statistic);
            Assert.AreEqual(0.0023987773293928649, anova.Table[0].Significance.PValue, 1e-16);
            Assert.IsFalse(double.IsNaN(anova.Table[0].Significance.PValue));

            Assert.AreEqual("Within-Groups", anova.Table[1].Source);
            Assert.AreEqual(68, anova.Table[1].SumOfSquares);                // Sw
            Assert.AreEqual(15, anova.Table[1].DegreesOfFreedom);            // df
            Assert.AreEqual(4.5333333333333332, anova.Table[1].MeanSquares); // MSw
            Assert.IsNull(anova.Table[1].Statistic);
            Assert.IsNull(anova.Table[1].Significance);

            Assert.AreEqual("Total", anova.Table[2].Source);
            Assert.AreEqual(152, anova.Table[2].SumOfSquares);    // Sw
            Assert.AreEqual(17, anova.Table[2].DegreesOfFreedom); // df
            Assert.IsNull(anova.Table[2].Statistic);
            Assert.IsNull(anova.Table[2].Significance);
        }
示例#6
0
 protected void PlaceAnovaTable(OneWayAnova anova, string dv, string iv)
 {
     PlaceAnovaTable(anova, dv, iv, 4);
 }
示例#7
0
        static void Main(string[] args)
        {
            DataTable meta_table = createMetaTable();
            DataTable distractors_video_table            = createDistractorVideoTable();
            DataTable distractors_game_table             = createDistractorGameTable();
            DataTable deaths_table                       = createDeathsTable();
            var       QuestionnaireScores                = new List <double>();
            var       video_sound_distractor_percentages = new List <double>();
            var       video_image_distractor_percentages = new List <double>();
            var       sound_distractor_percentages       = new List <double>();
            var       image_distractor_percentages       = new List <double>();
            var       avgdistractors                     = new List <double>();
            var       aps       = new List <double>();
            var       summs     = new List <double>();
            var       exptype   = new List <double>();
            var       skill_lvl = new List <double>();
            var       death_remembered_percentages = new List <double>();

            var underskill_scores = new List <double>();
            var overskill_scores  = new List <double>();
            var matched_scores    = new List <double>();

            var focused_scores  = new List <double>();
            var average_scores  = new List <double>();
            var detached_scores = new List <double>();

            var bronze_scores   = new List <double>();
            var goldplus_scores = new List <double>();

            var bps = new List <double[]>();

            int participantID = 0;

            foreach (String uname in usernames)
            {
                participantID++;
                Experiment exp1 = new Experiment(uname);
                Console.Out.WriteLine("User: "******"Skill Level: " + exp1.skill_level);
                Console.Out.WriteLine("Play Style: " + exp1.style);
                Console.Out.WriteLine("Experiment Type: " + exp1.exp_type);
                Console.Out.WriteLine("Questionnaire Score: " + exp1.questionnaire_score);
                Console.Out.WriteLine("number of distractors: ");
                Console.Out.WriteLine(exp1.video_image_distractor_no + " " + exp1.video_sound_distractor_no + " " + exp1.game_sound_distractor_no + " " + exp1.game_image_distractor_no);
                Console.Out.WriteLine("distractor remembering percentages:");
                Console.Out.WriteLine("video sound distractors: " + exp1.video_sound_distractor_proc);
                Console.Out.WriteLine("video image distractors: " + exp1.video_image_distractor_proc);
                Console.Out.WriteLine("game sound distractors: " + exp1.game_sound_distractor_proc);
                Console.Out.WriteLine("game image distractors: " + exp1.game_image_distractor_proc);
                Console.Out.WriteLine("");
                Console.Out.WriteLine("");
                QuestionnaireScores.Add(exp1.questionnaire_score);
                video_sound_distractor_percentages.Add(exp1.video_sound_distractor_proc);
                video_image_distractor_percentages.Add(exp1.video_image_distractor_proc);
                sound_distractor_percentages.Add(exp1.game_sound_distractor_proc);
                image_distractor_percentages.Add(exp1.game_image_distractor_proc);
                death_remembered_percentages.Add(exp1.death_remember_proc);
                double video_avg_proc = (exp1.video_sound_distractor_proc + exp1.video_image_distractor_proc) / 2;
                double avg_proc       = (exp1.game_sound_distractor_proc + exp1.game_image_distractor_proc) / 2;
                avgdistractors.Add(avg_proc);
                aps.Add(exp1.moves_per_sec);
                summs.Add(exp1.summ_no);
                exptype.Add((int)exp1.exp_type);
                skill_lvl.Add((int)exp1.skill_level);
                if (exp1.exp_type == Experiment_Types.UnderSkill)
                {
                    underskill_scores.Add(exp1.questionnaire_score);
                }
                else if (exp1.exp_type == Experiment_Types.Matched)
                {
                    matched_scores.Add(exp1.questionnaire_score);
                }
                else if (exp1.exp_type == Experiment_Types.OverSkill)
                {
                    overskill_scores.Add(exp1.questionnaire_score);
                }

                if (exp1.style == PlayStyle.Focused)
                {
                    focused_scores.Add(exp1.questionnaire_score);
                }
                else if (exp1.style == PlayStyle.Average)
                {
                    average_scores.Add(exp1.questionnaire_score);
                }
                else if (exp1.style == PlayStyle.Detached)
                {
                    detached_scores.Add(exp1.questionnaire_score);
                }

                if (exp1.skill_level == Ranks.Bronze)
                {
                    bronze_scores.Add(exp1.questionnaire_score);
                }
                else
                {
                    goldplus_scores.Add(exp1.questionnaire_score);
                }

                foreach (var item in exp1.game_bandpower)
                {
                    bps.Add(item);
                }

                foreach (var item in exp1.video_bandpower)
                {
                    bps.Add(item);
                }
                // KMeans tr = new KMeans(4);
                // tr.Learn(exp1.game_bandpower);

                // Console.Write(tr.ToString());

                // Console.ReadKey();

                meta_table.Rows.Add(participantID, exp1.skill_level, exp1.style, exp1.exp_type, exp1.questionnaire_score);
                deaths_table.Rows.Add(participantID, exp1.death_no, exp1.actual_death_no, exp1.death_remember_proc);
                distractors_video_table.Rows.Add(participantID, exp1.video_sound_distractor_proc, exp1.video_image_distractor_proc, video_avg_proc);
                distractors_game_table.Rows.Add(participantID, exp1.game_sound_distractor_proc, exp1.game_image_distractor_proc, avg_proc);
            }

            var test = new PearsonCorrelation();

            test.Similarity(QuestionnaireScores.ToArray(), sound_distractor_percentages.ToArray());
            Console.Out.WriteLine("accord.net similarity value: ");
            Console.Out.WriteLine(test.Similarity(QuestionnaireScores.ToArray(), sound_distractor_percentages.ToArray()));

            Console.Out.WriteLine("");
            Console.Out.WriteLine("correlation questionnaire - sound distractor rememberabce");
            Console.Out.WriteLine(Correlation.Pearson(QuestionnaireScores, sound_distractor_percentages));
            Console.Out.WriteLine("");
            Console.Out.WriteLine("correlation questionnaire - image distractor rememberabce");
            Console.Out.WriteLine(Correlation.Pearson(QuestionnaireScores, image_distractor_percentages));
            Console.Out.WriteLine("");
            Console.Out.WriteLine("correlation questionnaire - overall distractor rememberabce");
            Console.Out.WriteLine(Correlation.Pearson(QuestionnaireScores, avgdistractors));
            Console.Out.WriteLine("");
            Console.Out.WriteLine("correlation questionnaire - moves per second");
            Console.Out.WriteLine(Correlation.Pearson(QuestionnaireScores, aps));
            Console.Out.WriteLine("");
            Console.Out.WriteLine("correlation questionnaire - number of summ spells");
            Console.Out.WriteLine(Correlation.Pearson(QuestionnaireScores, summs));
            Console.Out.WriteLine("");

            Console.Out.WriteLine("");
            Console.Out.WriteLine("correlation questionnaire - skill");
            Console.Out.WriteLine(Correlation.Pearson(QuestionnaireScores, skill_lvl));
            Console.Out.WriteLine("");
            Console.Out.WriteLine("correlation questionnaire - death rememberabce");
            Console.Out.WriteLine(Correlation.Pearson(QuestionnaireScores, death_remembered_percentages));
            Console.Out.WriteLine("");


            var scatter_values = new List <double>();

            scatter_values.AddRange(video_sound_distractor_percentages);
            scatter_values.AddRange(sound_distractor_percentages);

            double[][] samples = { underskill_scores.ToArray(),
                                   matched_scores.ToArray(),
                                   overskill_scores.ToArray() };

            OneWayAnova anova = new OneWayAnova(samples);

            // DataGridBox.Show(anova.Table);
            //Console.ReadKey();
            double[][] style_samples = { focused_scores.ToArray(),
                                         detached_scores.ToArray(),
                                         average_scores.ToArray() };

            OneWayAnova style_anova = new OneWayAnova(style_samples);

            // DataGridBox.Show(style_anova.Table);
            // Console.ReadKey();
            double[][] skill_samples = { bronze_scores.ToArray(),
                                         goldplus_scores.ToArray() };

            OneWayAnova skill_anova = new OneWayAnova(skill_samples);
            //DataGridBox.Show(skill_anova.Table);
            //Console.ReadKey();

            String meta_table_file = "D:\\Projects\\Conference Paper\\Tables\\meta_table.xml";
            String distractors_video_table_file = "D:\\Projects\\Conference Paper\\Tables\\distractors_video_table.xml";
            String distractors_game_table_file  = "D:\\Projects\\Conference Paper\\Tables\\distractors_game_table.xml";
            String deaths_table_file            = "D:\\Projects\\Conference Paper\\Tables\\deaths_table.xml";

            StreamWriter metaStreamWriter             = new StreamWriter(meta_table_file);
            StreamWriter distractorsVideoStreamWriter = new StreamWriter(distractors_video_table_file);
            StreamWriter distractorsGameStreamWriter  = new StreamWriter(distractors_game_table_file);
            StreamWriter deathsStreamWriter           = new StreamWriter(deaths_table_file);

            meta_table.WriteXml(metaStreamWriter);
            distractors_video_table.WriteXml(distractorsVideoStreamWriter);
            distractors_game_table.WriteXml(distractorsGameStreamWriter);
            deaths_table.WriteXml(deathsStreamWriter);

            Console.ReadKey();
        }