# Study frequency of occurrence of alternatives in a test [closed]

There is a test with 5 alternatives A, B, C, D, E, I need to study the frequency of occurrence of these alternatives in a test of 80 questions, "n" times I can not think of a way to program it, help me please

EDIT I will try to explain this better. A teacher builds a test of 80 questions with 5 alternatives A, B, C, D, E which are randomly distributed by the person who built the test, we imagine that this person builds a very large number of tests and follows the same logic of constructing 80 questions with 5 random alternatives, I want to know the frequency of the alternatives A, B, C, D, E in the construction of a large number of tests, I want to know if there is any trend of the alternatives, as the test must be constructed many times let's say n = 1000000, here is where Mathematica enters

EDIT 2 An idea, a test of 80 questions is constructed, with 5 random alternatives each of the 80 questions, then another and another over the years, is it possible that within that large number of tests, there is an alternative A, B , C, D, E that is more likely than other

• Counts[data]/80?
– kglr
Oct 5 '18 at 0:50
• .. or PDF[MultinomialDistribution[80, {1, 1, 1, 1, 1}/5], {a, b, c, d, e}]?
– kglr
Oct 5 '18 at 1:00
• thanks for answering, could you explain a bit the code, I can not get it to work Maybe with an example Oct 5 '18 at 1:49
• An appropriate test depends on how you sampled. From what population did you select respondents? Did each respondent answer 80 questions? As far as I can tell this question is still unclear, doesn't directly involve Mathematica, and should be asked (with the sampling details) at stats.stackexchange.com.
– JimB
Oct 5 '18 at 2:34
• First, I really don't think that someone needs to know all of the statistical jargon to ask a good question. However, I don't see that both of your edits has added much clarity. Are there 5 different tests each with 80 questions? Are there a common set of 80 questions with one additional question selected from A, B, C, D, or E? Or is each question a multiple choice with 5 possible answers? You also mention "trend". Does that mean that the frequencies might be ranked A < B < C < D < E? Or does trend mean a change over time (and you've not mentioned anything about "time").
– JimB
Oct 5 '18 at 22:49

Under the not-too-implausible assumptions

(1) that the vector {na, nb, nc, nd, ne} (where na+nb+nc+nd+ne == 80) corresponding to the number of correct answers that are "A", "B", ..."E" in a test with 80 questions is a random variable with distribution dist = MultinomialDistribution[80, {pa,pb,pc,pd,pe}] for some vector {p1,p2,p3,p4,p5} such that pa+pb+pc+pd+pe == 1, and

(2) that we have a data set, data, of n = 500 5-tuples (500 independent observations from dist),

we can

(a) estimate the unknown parameters using FindDistributionParameters

(b) use DistributionFitTest to test hypothesis that no letter is favored as the correct answer, that is, we have pa == pb == pc == pd == pe == 1/5.

Examples:

SeedRandom[1]
dist1 = MultinomialDistribution[80, {1, 1, 1, 1, 1}/5];
data1 = RandomVariate[dist1, 500];

BarChart[Mean[data1]/80, ChartLabels -> CharacterRange["A", "E"]]


FindDistributionParameters[data1, MultinomialDistribution[80, {pa, pb, pc, pd, pe}]]


{pa -> 0.2006, pb -> 0.19805, pc -> 0.201625, pd -> 0.1996, pe -> 0.200125}

DistributionFitTest[data1,
MultinomialDistribution[80, {pa, pb, pc, pd, pe}],"HypothesisTestData"][
"FittedDistributionParameters", {"TestDataTable", All}, "TestConclusion"] //
Column // TeXForm


$$\begin{array}{l} \{\text{pa}\to 0.2006,\text{pb}\to 0.19805,\text{pc}\to 0.201625,\text{pd}\to 0.1996,\text{pe}\to 0.200125\} \\ \begin{array}{l|ll} \text{} & \text{Statistic} & \text{P-Value} \\ \hline \text{Pearson }\chi ^2 & 2.73603 & 0.638668 \\ \end{array} \\ \text{The null hypothesis that }\text{the data is distributed according to the }\\ \, \, \, \,\text{MultinomialDistribution}[80,\{\text{pa},\text{pb},\text{pc},\text{pd},\text{pe}\}] \text{is not rejected at the }\\ \, \, \, \,5\text{ percent level }\text{based on the }\text{Pearson }\chi ^2\text{ test.} \\ \end{array}$$

DistributionFitTest[data1, MultinomialDistribution[80, {1, 1, 1, 1, 1}/5],
"HypothesisTestData"][{"TestDataTable", All}, "TestConclusion"] //
Column // TeXForm


$$\begin{array}{l} \begin{array}{l|ll} \text{} & \text{Statistic} & \text{P-Value} \\ \hline \text{Pearson }\chi ^2 & 2.7436 & 0.642936 \\ \end{array} \\ \text{The null hypothesis that }\text{the data is distributed according to the }\\ \, \, \, \, \text{MultinomialDistribution}\left[80,\left\{\frac{1}{5},\frac{1}{5},\frac{1}{5},\frac{1}{5},\frac{1}{5}\right\}\right] \text{is not rejected at the }\\ \, \, \, \, 5\ \text{ percent level }\text{based on the }\text{Pearson }\chi ^2\text{ test.} \\ \end{array}$$

SeedRandom[1]
dist2 = MultinomialDistribution[80, {6, 1, 1, 1, 1}/10];
data2 = RandomVariate[dist2, 500];
BarChart[Mean[data2]/80, ChartLabels -> CharacterRange["A", "E"]]


FindDistributionParameters[data2, MultinomialDistribution[80, {pa, pb, pc, pd, pe}]]


{pa -> 0.6016, pb -> 0.1027, pc -> 0.098425, pd -> 0.09825, pe -> 0.099025}

DistributionFitTest[data2, MultinomialDistribution[80, {pa, pb, pc, pd, pe}],
"HypothesisTestData"]["FittedDistributionParameters", {"TestDataTable", All},
"TestConclusion"] // Column // TeXForm


$$\begin{array}{l} \{\text{pa}\to 0.6016,\text{pb}\to 0.1027,\text{pc}\to 0.098425,\text{pd}\to 0.09825,\text{pe}\to 0.099025\} \\ \begin{array}{l|ll} \text{} & \text{Statistic} & \text{P-Value} \\ \hline \text{Pearson }\chi ^2 & 2.76649 & 0.655743 \\ \end{array} \\ \text{The null hypothesis that }\text{the data is distributed according to the }\\ \, \, \,\, \text{MultinomialDistribution}[80,\{\text{pa},\text{pb},\text{pc},\text{pd},\text{pe}\}] \text{is not rejected at the }\\ \, \, \,\,5\text{ percent level }\text{based on the }\text{Pearson }\chi ^2\text{ test.} \\ \end{array}$$

DistributionFitTest[data2, MultinomialDistribution[80, {1, 1, 1, 1, 1}/5],
"HypothesisTestData"][{"TestDataTable", All}, "TestConclusion"] // Column


• When you use {pa, pb, pc, pd, pe} in DistributionFitTest and none of those values have been defined, then what is being tested is if the data comes from some multinomial distribution. If you wanted to test for equality of the proportions, then you would need to use {1, 1, 1, 1, 1}/5.
– JimB
Oct 6 '18 at 0:42
• @JimB, you are right. I tested both for data1; I forgot to copy/paste second test for data2. Thank you.
– kglr
Oct 6 '18 at 0:43