这个作业是用R语言完成统计概率相关的问题分析

AMS 597 Spring 2021
Homework 2

1.(a)使用样本函数生成遵循多项式分布且概率为(0.1,0.2,0.4,0.3)的随机向量。
(b)仅使用随机均匀生成器(不要使用样本),生成随机
遵循多项式分布的概率为(0.1,0.2,0.4,0.3)的向量。
2.生成速率为2的100个指数分布的随机变量,并绘制其经验分布函数。
3.使用以下数据集回答问题。
(a)对美国运通进行t检验,其原假设为零
日志返回为零。
(b)使用无效假设对美国运通进行Wilcoxon符号秩检验
其对数返回的平均值为零。
(c)进行两次样本t检验,以推断辉瑞和美利坚合众国的平均对数回报率
表达是否相同。
(d)比较辉瑞和美国运通的对数收益差异。
(e)进行两次样本的Wilcoxon检验,以得出辉瑞制药的平均对数回报率是否得出结论
和美国运通卡相同或不同。
4.编写自己的函数my.t.test,该函数可以执行一个和两个样本t检验。
对于两个样本t检验,它可以执行相等和不相等的方差版本。你的
my.t.test将采用以下参数(1)向量x,(2)可选向量y
两个样本t检验,(3)替代假设的替代类型,(4)均值或均值
您正在测试亩的区别。您的函数my.t.test应该包含一个例程
使用F检验检查均方差假设。如果F检验的p值为
≤0.05,则将在不等方差假设下执行两个样本t检验。你的
函数my.t.test应该返回测试统计量stat,自由度df和pvalue p.value。您可以使用var.test()或编写自己的F测试,但不应
使用t.test()。
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.