AMS 597 Spring 2021
Homework 2

1.（a）使用样本函数生成遵循多项式分布且概率为（0.1，0.2，0.4，0.3）的随机向量。
（b）仅使用随机均匀生成器（不要使用样本），生成随机

2.生成速率为2的100个指数分布的随机变量，并绘制其经验分布函数。
3.使用以下数据集回答问题。
（a）对美国运通进行t检验，其原假设为零

（b）使用无效假设对美国运通进行Wilcoxon符号秩检验

（c）进行两次样本t检验，以推断辉瑞和美利坚合众国的平均对数回报率

（d）比较辉瑞和美国运通的对数收益差异。
（e）进行两次样本的Wilcoxon检验，以得出辉瑞制药的平均对数回报率是否得出结论

4.编写自己的函数my.t.test，该函数可以执行一个和两个样本t检验。

my.t.test将采用以下参数（1）向量x，（2）可选向量y

≤0.05，则将在不等方差假设下执行两个样本t检验。你的

5. Write your own function Wilcoxon rank sum test my.wilcox.test which can perform both
exact and normal approximation test for two-sided alternative hypothesis. Your function
will compute the p-value using normal approximation if n1 and n2 ≥ 12. Otherwise, it will
compute the p-value using exact test. Your function will return the test statistics W1 and
W2, p-value p.value and a message indicating the type of test used (normal or exact).
You may assume there is no ties in the data.
6. A regression through the origin model may be used when specific knowledge about the
problem at hand suggests that the response variable is zero if and only if the predictor
variable is zero. For such problems, the model can be written as
Yi = βXi + i
;i = 1; . . . ; n
where i
’s are iid N(0, σ2
) random noise.
(a) Derive the least-squares estimate of β.
(b) Run the following R code:
set.seed(123)
x <- rnorm(50)
y <- 2*x+rnorm(50)
Use the formula you derived in part (a) above to estimate based on this data, and
draw a scatterplot of the data with the fitted line overlaid.
(c) Perform the regression through origin using the R function lm on the same data.
(d) Write your own function my.kendall to compute Kendall’s τ between two variables
and apply your function to x and y generated above.