全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
1854 3
2010-02-03
Exercise 4
In this exercise you are required to write simple code in R, and compare three di erent ways of
programming a simple multivariate OLS regression problem.
a. Create a dataset of 100 observations with four exogenous variables and a random error term.
The exogenous variables are: x1, a constant term; x2, a vector containing random draws
from a standard normal distribution; x3, a vector containing random draws from a uniform
distribution between -10 and +10; and x4, a dummy variable that has a value of 1 for the
rst 50 observations and 0 elsewhere. The error terms are independently normally distributed
with mean zero and variance 4. Group the variables xi in a matrix X.
b. Calculate y-observed on the basis of a simple linear speci cation assuming that the true betas
are 1. Group the x variables (except for the constant) and the dependent variable in a data
array and assign names for the variables.
c. Perform a regression using the command lm().
d. Calculate the estimated betas and standard errors yourself by writing simple code based on
standard econometric textbook notation. Compare your results to the lm() output.
e. Write alternative code based on ecient usage of solve() and the crossprod() operator.
See the General Principles 1 and 2 in Bates (2004) available at:
http://www.r-project.org/doc/Rnews/Rnews 2004-1.pdf
Compare your results to the lm() output, and discuss one advantage and one disadvantage
of using the solve operator eciently.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2010-2-3 16:33:48
呵呵,这个好像不难吧。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-2-4 05:45:58
初学,好多问题搞不定
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-2-4 22:48:25
Exercise 4.a

n=100
x1 <- rep(1, n)                  #constant term
x2 <- rnorm(n, mean=0,sd=1)      #standard normal distribution
x3 <- runif(n, min=-10, max=10)  #uniform distribution
x4 <- rep(1:0, c(50,50))         #dummy variable
x5 <- rnorm(n, mean=0,sd=2)      #error term
X  <- cbind(x1,x2,x3,x4,x5)
X
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群