Skip to content

Commit

Permalink
Re-type ComputeY as a List.
Browse files Browse the repository at this point in the history
The number of unique elements in different columns in x1 may be
different, which leads to attempting to add vectors of different length
into res. Previously, `push_back` on a DataFrame changed the DataFrame
to a list, which is being addressed in RcppCore/Rcpp#1099. This change,
combined with attempting to add vectors of different lengths, leads to
an error.
  • Loading branch information
waltersom committed Jul 9, 2020
1 parent 788a585 commit c526d4e
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/testxvalid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ std::string to_string(T value)
{
//create an output string stream
std::ostringstream os ;

//throw the value into the string stream
os << value ;

//convert the string stream into a string and return
return os.str() ;
}
using namespace Rcpp;


//' Compute the subgroup effect sizes
//'
//'
//' @param x1 the node labels for each study
//' @param y the effect size
//' @param vi the sampling variance
//' @param tau2 the residual heterogeneity
//' @keywords internal
// [[Rcpp::export(".ComputeY")]]
DataFrame ComputeY(DataFrame x1, NumericVector y,
List ComputeY(DataFrame x1, NumericVector y,
NumericVector vi, NumericVector tau2) {
int nsplit;
int i;
int j;
DataFrame res;
List res;
for (nsplit = 0; nsplit < x1.ncol(); nsplit++) {
IntegerVector Nodes = x1[nsplit];
IntegerVector uniNodes = Rcpp::sort_unique(Nodes);
IntegerVector uniNodes = Rcpp::sort_unique(Nodes);
NumericVector swyNodes;
for (i = 0; i < uniNodes.length(); i++) {
// compute the weighted sum for each node
Expand All @@ -43,21 +43,21 @@ DataFrame ComputeY(DataFrame x1, NumericVector y,
sumWY = sumWY + y[j]/(vi[j]+tau2[nsplit]);
sumW = sumW + 1/(tau2[nsplit]+vi[j]);
}

}
swyNodes.push_back(sumWY/sumW, to_string(uniNodes[i]));

}

res.push_back(swyNodes);
}

return res;

}

//' Predict effect size for the test set
//'
//'
//' @param x1 the list of subgroup means
//' @param x2 predicted subgroup membership for the test set
//' @keywords internal
Expand All @@ -77,7 +77,7 @@ NumericMatrix PredY(List x1, IntegerMatrix x2) {
} else {
res(j,i) = SubMeans[to_string(x2(j,i))];
}

//res(j,i) = x2(j,i);
}
}
Expand All @@ -86,7 +86,7 @@ NumericMatrix PredY(List x1, IntegerMatrix x2) {


//' Replace missing values by the overall weighted mean
//'
//'
//' @param x1 the two-column matrix of the indices of missing values
//' @param x2 the matrix of predicted y with missing values
//' @param y the effect size
Expand Down Expand Up @@ -115,7 +115,7 @@ NumericMatrix ReplaceNA(IntegerMatrix x1, NumericMatrix x2,
x2(x1(j,0)-1, x1(j,1)-1) = OverallWM[to_string(x1(j,1))];
}
return x2;

}


0 comments on commit c526d4e

Please sign in to comment.