Question: please help me with some R coding questions. For each question, one or more R function(s) will be written and restore in a script file.
please help me with some R coding questions. For each question, one or more R function(s) will be written and restore in a script file. And any add-on R library cannot be used for the questions.



Introduction Suppose you want to fit a linear regression model Y = X + e where Y is a nx1 vector of response variables, X is an nxp design matrix, ,6 is a px1 coefficient vector and 6 is a nx1 vector of independent N (0, 02) random variables. Suppose in addition that you can not observe all of the elements of X directly: instead, you observe V=X+U where the elements of U are themselves independent normal random variables with zero th mean. The variance of the (i4) element of U is 71.2: note that this doeshnot depend on 1'. One way to interpret this is: the entries in t the 1' column of the design matrix are all subject to independent measurement errors, which are normally distributed with variance 2 Tj. In this situation, to fit the regression model it is natural to use the usual leastsquares procedure with the observed design matrix V in place of the true values X. It can be shown, however, that this produces biased estimates of the coefficient vector [3. A corrected estimator can be defined, however, as 13'": (V'V D)'1V'Y, th where D is a pxp diagonal matrix with j diagonal element Q} = \"Tl-2. The covariance matrix of this estimate is 02(V'V D)_1V'V(V'V D)'1 . Standard errors of the estimated parameters can then be calculated as the square roots of the diagonal elements of this covariance matrix. For this question, we will assume that the value of 0'2 is known. In this situation, to fit the regression model it is natural to use the usual leastsquares procedure with the observed design matrix V in place of the true values X. It can be shown, however, that this produces biased estimates of the coefficient vector [3. A corrected estimator can be defined, however, as 13": (V'V D)_1V'Y, th where D is a pxp diagonal matrix with j diagonal element ij = 1111.2. The covariance matrix of this estimate is 02(V'V D)'1V'V(V'V D)'l . Standard errors of the estimated parameters can then be calculated as the square roots of the diagonal elements of this covariance matrix. For this question, we will assume that the value of 0'2 is known. Yburtask Without using the R command lm ( ) or anything similar, write an R function called lm . adjusted ( ) , to implement the corrected estimator as described above. The arguments to your function should be y, a vector of responses corresponding to Y in the description above; V, a design matrix corresponding to V in the description; sigsq, the known value of 62; and tausq, a vector containing the values of the {1'12}. The default value for tausq should be a vector of zeroes. You may assume that the matrix V'V-D is invertible. Your function should return a list containing component betahat (the estimated coefficient vector) and sebetalr of estimated standard errors for the coefficients). Last modified: Saturday, 27 January 2018, 5:23 PM Write an R function called polyopt () , to find a local maximum 2 or minimum of an arbitrary polynomial h(x) = a + a1x + azx + 0 + apxp with p > 1 and ap #5 0, using the NewtonRaphson algorithm with starting value x0. Your algorithm should terminate when at least one of the following conditions is met: 0 Ih'(X,-)|
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
