+1 678 648 4277 

R Code is programming language software which is used for the graphics of statistical analysis. Students from different countries have accessed our services for their profit. They save their time from homework and project writing as the Assignmentpedia team do it for them within the mentioned time limit. The answers are appropriate and applicable for students to score good in their curriculum. Students have been using our services for the best possible results. Our experts who are extremely efficient and skilled provide you with the assignment solutions which are plagiarism free and in the referencing style of your choice (namely APA, ASA, MLA, Chicago, etc.)

Disclaimer: Please look at the sample solution given below which has been preparedfor your reference and has not been used in any of our assignment solutions.           

 R Programming Sample Assignment


Implement reduced rank regression as a simple R function.
SOLUTION
The R code is displayed below.
------------------------------------------------------------------------------------------------------------------------------------------
ReducedRankRegression <- function(Xraw,Y,Rank) {
# This code implements a two-stage reduced-rank estimation.
# First, we estimate the covariance matrix Sigma of the residuals
# via OLS. Second, we engage reduced-rank regression supplying Sigma
# as an input.
Xraw <- as.matrix(Xraw);
Y <- as.matrix(Y);
# STAGE 1
N <- dim(Y)[1];
q <- dim(Y)[2];
X <- cbind(rep(1,N), Xraw);
OlsRank <- dim(X)[2];
EffectiveRank <- Rank + 1;
Bols <- t( solve( t(X)%*%X ) %*% t(X)%*%Y );
Sigma <- matrix(0,q,q);
Sxx <- matrix(0,q+1,q+1);
Sxy <- matrix(0,q+1,q);
Syy <- matrix(0,q,q);
for(t in 1:N) {
Sxx <- Sxx + X[t,]%*%t(X[t,]);
Sxy <- Sxy + X[t,]%*%t(Y[t,]);
Syy <- Syy + Y[t,]%*%t(Y[t,]);
Resid <- Y[t,] - Bols%*%X[t,];
Sigma <- Sigma + Resid%*%t(Resid);
}
Sxx <- Sxx / N;
Sxy <- Sxy / N;
Syx <- t(Sxy);
Syy <- Syy / N;
Sigma <- Sigma / (N-OlsRank);
# STAGE 2
Gamma <- solve(Sigma);
HalfGamma <- chol(Gamma);
H <- HalfGamma%*%Syx%*%solve(Sxx)%*%Sxy%*%HalfGamma;
SVDoutput <- svd(H);
RelevEigenVectors <- SVDoutput$u[,1:EffectiveRank];
MiddleSum <- matrix(0,q,q);
for(j in 1:EffectiveRank) {
MiddleSum <- MiddleSum +
RelevEigenVectors[,j]%*%t(RelevEigenVectors[,j]);
} B <- solve(HalfGamma)%*%MiddleSum%*%HalfGamma %*%
Syx%*%solve(Sxx);
list(B=B, Sigma=Sigma, Bols=Bols);
}