Question: C++ within R: HELP with error for function in C++ (within R): expected primary-expression before ',' token for the line beta[,i]=arma::inv(X.t()*X+lambda[i]*arma::eye(2,2))*X.t()*Y[,i]; and points to the

C++ within R: HELP with error for function in C++ (within R):

expected primary-expression before ',' token for the line

beta[,i]=arma::inv(X.t()*X+lambda[i]*arma::eye(2,2))*X.t()*Y[,i];

and points to the comma in beta and then also points to the comma in Y. Both were declared (as you can see below) as matrices (one inside and the other passed as parameter).

Code below:

arma::mat col_ridge_2(arma::mat Y, arma::mat X, arma::vec lambda) {

int n = Y.n_cols; arma::mat beta(2,100); //set stop condition for lambda being length of n here int i;

for (i=0;i<100;i++) {

beta[,i]=arma::inv(X.t()*X+lambda[i]*arma::eye(2,2))*X.t()*Y[,i];

} return beta;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!