STAT UN2102 Homework
STAT UN2102 Homework 4 [100 pts]
Due 11:59pm Monday, May 6th on Canvas
Your homework should be submitted on Canvas as an R Markdown file. Please submit
the knitted .pdf or .html file along with the .Rmd file. We will not (and cannot) accept
any other formats. Please clearly label the questions in your responses and support your
answers by textual explanations and the code you use to produce the result. We may print
out your homeworks. Please do not waste paper by printing the dataset or any vector over,
say, length 20.
Goals: Simulating probability distributions using the accept-reject method, simulating a
sampling distribution related to the linear regression model.
1 Reject-Accept Method
Let random variable X denote the temperature at which a certain chemical reaction takes
place. Suppose that X has probability density function
Perform the following tasks:
1. Determine the maximum of f(x). Find an envelope function e(x) by using a uniform
distribution for g(x) and setting e(x) = maxx{f(x)}.
2. Using the Accept-Reject Algorithm, write a program that simulates 1000 draws
from the probability density function f(x) from Equation 1.
3. Plot a histogram of your simulated data with the density function f overlayed in the
graph. Label your plot appropriately.
2 Regression and Empirical Size
2.1 Regression
We work with the grocery retailer dataset from Canvas. The description follows:
1
A large national grocery retailer tracks productivity and costs of its facilities closely. Consider
a data set obtained from a single distribution center for a one-year period. Each data
point for each variable represents one week of activity. The variables included are number
of cases shipped in thousands (X1), the indirect costs of labor as a percentage of total
costs (X2), a qualitative predictor called holiday that is coded 1 if the week has a holiday
and 0 otherwise (X3), and total labor hours (Y ). Consider the multiple linear regression
model
(2) Yi = β0 + β1 Xi1 + β2 Xi2 + β3 Xi3 + i, i = 1, 2, . . . , 52,
and iid~ N(0, σ2).
Perform the following tasks:
4. Read in the grocery retailer dataset. Name the dataset grocery.
5. Use the least squares equation = (XTX)
1XTY to estimate regression model (2).
To estimate the model, use the linear model function in R, i.e., use lm().
6. Use R to estimate σ2, i.e., compute MSE =1
. To perform this task,
use the residuals function.
2.2 Test for Slope
STAT UN2102作业代做、代做R Markdown file作业、代写R课程作业
Now consider investigating if the number of cases shipped (X1) is statistically related to
total labor hours (Y ). To investigate the research question, we run a t-test on the coefficient
corresponding to X1, i.e., we test the null alternative pair
(3) H0 : β1 = 0 versus HA : β1 6= 0.
To run the hypothesis testing procedure, we use the t-statistic
1 is the second element of the least squares estimator β= (XTX)
1XTY and
SE(β1) is the standard error of β?
1. The least squares estimates, estimated standard errors,
t-statistics and p-values for all coefficients β0, β1, β2, β3 are nicely organized in the standard
linear regression output displayed in Table 1. To get this output in R, use the summary()
function on your model.
Test the manager’s claim in (3) using the R functions lm() and summary().
2
Table 1: Standard Multiple Linear Regression Output
Estimate Std. Error t value Pr(> |t|) or Sig
(Intercept) β
2.3 Sampling Distribution
Under model (2) and under the null hypothesis H0 : β1 = 0, the test statistic (4) has a
student’s t-distribution with n 4 degrees of freedom, i.e.,
The goal of this section is to simulate the sampling distribution of the t-statistic.
Perform the following tasks:
5. Write a loop that simulates the sampling distribution of the t-statistic under null
hypothesis (3) with the multiple linear regression model (2). To accomplish this task:
i. Assume the true model relating Y with X1, X2, X3 is
(5) Yi = 4200 + β1Xi1 ? 15X2 + 620X3 + i, i = 1, 2, . . . , 52,i
iid~ N(0, 20500).
ii. Assuming H0 : β1 = 0 is true, simulate 10,000 draws from model (5) using the
fixed covariates X2, X3.
iii. For each iteration of the loop, fit the full model
using the simulated Y and fixed covariates X1, X2, X3.
iv. For each iteration of the loop, also compute the t-statistic from equation (4).
Store these values in a vector t.stat. Hint: Use the summary function in R and
extract the actual summary table using the code summary(model)[[4]]. Then
extract the relevant t-statistic from the table.
v. Display the first six elements of your simulated t-values.
3
7. Plot a histogram of the simulated sampling distribution. Overlay the correct t-density
on this histogram, i.e., overlay the density t(df = 52 ? 4). Plot the density in green
and set breaks=40 in the histogram. Make sure to label the plot appropriately. You
can use base R or ggplot.
8. Recall that the significance level of a testing procedure is defined as
P(Type I error) = P(Rejecting H0 when H0 is true) = α.
The significance level is often called the size of the testing procedure. Based on
significance levels α = 0.10, 0.05, 0.01, compute the sample proportion of simulated
t-values that fell in the rejection region. The proportion of simulated rejected t-values
under the null is called the empirical size of a test. The three values should be close
to the actual α levels.
因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
微信:codinghelp
STAT UN2102 Homework的更多相关文章
- bzoj 4320: ShangHai2006 Homework
4320: ShangHai2006 Homework Time Limit: 10 Sec Memory Limit: 128 MB Description 1:在人物集合 S 中加入一个新的程序员 ...
- HDU 1789 Doing Homework again(贪心)
Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...
- hdu-1789-Doing Homework again
/* Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 1789 Doing Homework again (贪心)
Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...
- Doing Homework 状态压缩DP
Doing Homework 题目抽象:给出n个task的name,deadline,need. 每个任务的罚时penalty=finish-deadline; task不可以同时做.问按怎样的 ...
- 机器学习 —— 概率图模型(Homework: Exact Inference)
在前三周的作业中,我构造了概率图模型并调用第三方的求解器对器进行了求解,最终获得了每个随机变量的分布(有向图),最大后验分布(双向图).本周作业的主要内容就是自行编写概率图模型的求解器.实际上,从根本 ...
- hdoj 1789 Doing Homework again
Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- homework做了些什么?
第一步:get_new_guid_uid_pairs_{$ymd} 参数是时间和100上的文件. 那么100上的文件是从哪里来的呢? 我们进入到100机器上,打开root权限下的cron,看到如下内容 ...
- HDU 1074 Doing Homework (dp+状态压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一 ...
随机推荐
- react 路由导航栏 withRouter
codesandbox https://codesandbox.io/s/9l6prnyxjy app.js import React, { Component, Fragment } from &q ...
- Nest.js 管道
Docs: https://docs.nestjs.com/pipes 管道将输入数据转换为所需的输出.此外,它可以处理验证,当数据不正确时可能会抛出异常. 内置的 pipe import { Arg ...
- mac shell 获取ip,自动启动文件http服务
因为工作原因,时常有文件传输需求. rz.nc.rsync都用过,各有各的好处. 但相对的,向别处推文件时总有各种麻烦,尤其是在给同事发送文件时. 然后就想到了提供http服务. 在环境变量中定义别名 ...
- aes 和 Md5 分析
高级加密标准(英语:Advanced Encryption Standard,缩写:AES). 密码的设计力求满足以下3条标准: ① 抵抗所有已知的攻击. ② 在多个平台上速度快,编码紧凑. ③ 设计 ...
- 微信小程序开发笔记03
今天基本实现了微信小程序主要功能,页面还没有进行优化,有些功能还需完善. 页面之间的信息转化部分还未实现.
- python语法_算数运算+赋值运算符+比较运算符+逻辑运算符
算术运算符 + - * / 加减乘除 5/2 = 2.5 5//2 = 2 整除,地板除 5%2= 1 取余数 2**10 指数运算 2的10次方 算术优先级 无论多少级,都使用()小括号进行优先 ...
- HTML、CSS知识点,面试开发都会需要--No.2 CSS
No.2 CSS 1.选择器类型 选择器类型包括:type.class.id. 2.引用外部css文件 使用link元素,添加rel和href属性:<link rel="styles ...
- Eclispe最常用的几个快捷键
熟练使用快捷键可以在很大程度上提高我们的工作效率,Eclipse的快捷键很多,但是常用的也就那么几个,下面说下Eclispe最常用的几个快捷键: Eclipse的快捷键组合可在Eclipse按下ctr ...
- xss脚本绕过限制的方法
第一关:第一关比较简单,直接写入标签就可以,这里不多说了,payload如下: http://sqler.win/xss/level1.php?name=test%3Csvg/onload=alert ...
- 苹果审核被拒,解析奔溃日志.txt转crash文件
1. 桌面新建一个文件夹,用来存放crash相关的东西.取名crash 2.下载苹果官方邮件里给的后缀名为 .txt 的被拒附件(这三个txt格式文件为苹果返回的崩溃日志文件),把这三个文件放在刚新建 ...