全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
1779 8
2015-04-20

1.   [8] Make a binary infix operator called %ols% that takes thearguments x and y and returns the ordinary least squares regressioncoefficients for regressing y on x.  Inthis function x and y may any combination of vectors or matrices. Rather thanusing a built in R function, use the equation we saw in Question 2d) of thesecond assignment. This function should add a column of 1s to x so that anintercept is fit.  For examplex<-1:10; y<-2+3*x; y%ols%x returns: the vector 2, 3.


i)                  Regress ozone on temperature.  


ii)                Try replicating the model in Q1 f) by setting y to ozoneand x to a matrix where the first column contains radiation and the next twocolumns contain wind and temperature, respectively. Do this part in oneexpression.


2d)题目如下:

Assume that thereis an approximate linear relationship between Illiteracy and Murder rates.Given the design matrix defined above, we can define a simple linear modelas y=Xb+e where y (Murder) is the dependent variable, X is thedesign matrix (or matrix of independent variables), b is the vector ofparameters and e is the error term. The least squares estimate of b is:  bhat=(XtX) -1Xt y.Write an expression to calculate bhat in R. Note that Xt is thetranspose of X.


ozonetemperature 来自于下表:

QQ截图20150420195103.jpg


二维码

扫码加我 拉你入群

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

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

全部回复
2015-4-20 19:54:42
期末最后的大作业,不胜感激啊
二维码

扫码加我 拉你入群

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

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

2015-4-20 21:04:49
挺好玩的题目,自己编一个操作符。楼主肯定能做出来
二维码

扫码加我 拉你入群

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

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

2015-4-20 22:56:01
nuomin 发表于 2015-4-20 21:04
挺好玩的题目,自己编一个操作符。楼主肯定能做出来
嗯嗯,谢谢肯定,不过能指点下题目大意或者思路吗,英文能力是硬伤,理解了题目应该能解答的
二维码

扫码加我 拉你入群

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

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

2015-4-21 21:29:11
有前辈能指点一下吗
二维码

扫码加我 拉你入群

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

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

2015-4-21 22:32:12
It's about conducting a linear regression model using matrix operation. Group your data in a data frame or matrix where y (the 1st column) is the response variable and the rest of the columns are explanatory variables.
The R code
y = da[,1]
x = cbind(1, da[,2], da[,4], da[,3])
beta = solve(t(x)%*%x)%*%(t(x)%*%y) #the estimates of beta
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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