Question: Section 1 : Preliminaries 1 a ) Simulating a Multinomial np . random. multinomial ( n , p _ array ) simulates n draws at

Section 1: Preliminaries
1a) Simulating a Multinomial
np. random. multinomial(n, p_array) simulates n draws at random with replacement from the categorical distribution p_array and returns an array of the
observed counts in all the categories.
You have seen a version of this in Data 8. The datascience function sample_proportions is just np. random. multinomial with the output converted to
proportions.
Run the cell below to draw 10 times from a population in which 20% are in Category A,70% in Category B, and 10% in Category C. The output array contains the
observed counts in Categories A, B, and C.
Confirm that it makes sense, by looking at the total count and the count in each category. Then run the cell a few times to see how the observations change.
num_draws =10
population_proportions =[0.2,0.7,0.1] # make_array (0.2,0.7,0.1) is also fine
np. randon.multinonial(num_draws, population_proportions)
array([2,7,1])
1b) Adding Rows to a Table
You know that t. with_columns can be used to add a column or columns to a table t. Sometimes it is useful to grow a table by adding rows. Start by creating the
table with just the column labels and no rows, as follows.
t=Table([' Column A', 'Column B', 'Colunn C'])
t
Column A Column B Column C
a temporary copy of t that you have to name if you want to save it. Run the two cells below and keep track of what happens to t.
t.append([1,2,3]
t has been changed
t
Column A Column B Column C
To append another row, use append again.
t.append ([4,5,6]
1c) Putting the Two Together
Create a table simulated_counts that has column labels A, B, and C. The table should have two rows. Each row should contain the observed counts in
Categories A, B, and C in 10 multinomial trials, each of which results in Category A with chance 0.2, Category B with chance 0.7, and Category C with chance 0.1 as in
Part a above. The trials in each row should be independent of those in the other row.
You should use no more than 3 lines of code.
Answer to 1c
...
a.
simulated_counts. Please help solve the last part
 Section 1: Preliminaries 1a) Simulating a Multinomial np. random. multinomial(n, p_array)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!