关键词 > STAT6/4365
STAT 6/4365 HW 6
发布时间:2022-11-10
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
STAT 6/4365
HW 6
Use Jupyter Notebook and create a document (PDF preferred) containing your answers. The document should include your code too. Upload the document, by the deadline to the submission folder on eLC.
1. Write a function that takes an input of a vector of numbers and outputs the quartiles. The function should be called quartile. Your function may not use the quantile function, median function, or any other function that trivially solves the problem. Note that there are a number of different ways to calculate quartiles. You may use any standard method (this may require a bit of research on your part), but be sure to document what you are doing. My own solution actually involves two functions: one for the median and then one for the quartile (which uses the median). Test the function with simulated data and compare to results from the equivalent functions in Python.
2. Write your own function to perform a two-sample t-test. The t-test should be unpaired, and you may assume that the samples have equal variance. This function must have the following properties:
o The user should be able to specify a choice of alternative hypotheses by giving arguments “two-sided”, “less”, or “greater” . If no such alternative is given, then the default should be “two-sided” .
o The user should be able to specify a parameter mu indicating the true difference in means under the null hypothesis. If unspecified, the default should be mu=0.
o The result should be a dict with the labeled values of the t-statistic and the p-value.
o The form of the function should be my_ttest(x,y,mu,alternative), where x and y are the two samples being compared.
Test your function by comparing it to scipy.stats.ttest_ind for some sample data sets.
Hints:
1. You can use the function scipy.stats.t.cdf (cdf for the t-distribution) to calculate p- values.
2. You can generate random samples for testing using npr.normal