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.
ozone 和 temperature 来自于下表: