# Python统计代写｜Bonus Assignment: Simulating experiments

• ALL

### Overview

Consider the following two-sample data from Real Statistics:

The results for this dataset are:

Recall from Lesson 08 that the two-sample t statistic is defined as:

where sp is the pooled standard deviation:

In order to complete the tasks below, you will need the following packages:

In [1]:
import numpy as np
from scipy import stats
from matplotlib import pyplot as plt


Task 1: Write a function called t_two_sample which (1) has two input arguments: yA and yB, and which (2) calculates the t-value for a two-sample test.

Task 2: Use your t_two_sample function to verify the t value reported for the dataset above ( t=2.177 ).

Task 3: Use scipy.stats.t.sf to verify the p value reported for the dataset above ( p=0.022 ).

Task 4: Simulate at least 1000 two-sample experiments to numerically verify the reported p value ( p=0.022 ).

Hints:

• See Lesson 09 for examples of experiment simulations.
• For each experiment, use your t_two_sample function (above) to calculate the two-sample t value.
• Also use:
• nA=nB=10 (sample size)
• μA=μB=0 (means when H0 is true)
• σA=σB=1 (true SD values)
• N≥1000 (number of experiments)
• When simulating experiments, ensure that you use the Normal distribution (np.random.randn) and NOT the Uniform distribution (np.random.rand)

E-mail: vipdue@outlook.com  微信号:vipnxx