そのため、RCPP を使用して作成した関数から値を返すのに少し問題があります。NumericVector の最初の値のみを返します。問題は、それ自体で関数を呼び出し、NumericVector を out 変数に戻す場合です。私が間違ってやっていることについての意見は大歓迎です。
NumericVector advantage(double tRos, double tTat, double cRos, double cTat){
double tRosAd = 0;
double tTatAd = 0;
double ja = 0;
double rosAtt = 0;
double tatAtt = 0;
double ttlAd = 0;
NumericVector out(1);
if ((tRos >= 0 || cRos >=0) && cRos >= tRos && cTat <= tTat){
//case 1.1//
tRosAd = (cRos - tRos) * cTat * -1;
tTatAd = (tTat - cTat) * tRos;
out[0] = tRosAd;
out[1] = tTatAd;
}
else if((tRos >= 0 && cRos >= 0) && cRos <= tRos && cTat >= tTat){
//case 1.2//
out = advantage(cRos, cTat, tRos, tTat);
out[0] = out[0] * -1;
out[1] = out[1] * -1;
}
else if(tRos >= 0 && cRos <= 0 && tTat >= cTat){
//case 2.1//
tRosAd = (tRos - cRos) * cTat;
tTatAd = (tTat - cTat) * tRos;
out[0] = tRosAd;
out[1] = tTatAd;
}
else if(tRos <= 0 && cRos >= 0 && tTat <= cTat){
//case 2.2//
out = advantage(cRos, cTat, tRos, tTat);
out[0] = out[0] * -1;
out[1] = out[1] * -1;
}
else if(tRos <= 0 && cRos <= 0 && tTat >= cTat & tRos >= cRos){
//case 3.1//
tRosAd = (tRos - cRos) * cTat;
tTatAd = (tTat - cTat) * tRos;
out[0] = tRosAd;
out[1] = tTatAd;
}
else if(tRos <= 0 && cRos <= 0 && tTat <= cTat && tRos <= cRos){
//case 3.2//
out = advantage(cRos, cTat, tRos, tTat);
out[0] = out[0] * -1;
out[1] = out[1] * -1;
}
else if(tRos >= 0 && cRos >= 0 && tTat >= cTat && tRos >= cRos){
//case 4.1//
//calculate two attribution advantages//
tRosAd = (tRos - cRos) * cTat;
tTatAd = (tTat - cTat) * cRos;
//calculate total & joint advantage//
ttlAd = (tTat * tRos) - (cTat * cRos);
ja = ttlAd - (tRosAd + tTatAd);
rosAtt = tRosAd / (tRosAd / tTatAd);
tatAtt = tTatAd / (tRosAd / tTatAd);
//add joint advantage//
tRosAd = ja * rosAtt + tRosAd;
tTatAd = ja * tatAtt + tTatAd;
out[0] = tRosAd;
out[1] = tTatAd;
}
else if(tRos >= 0 && cRos >= 0 && tTat <= cTat && tRos <= cRos){
//case 4.2//
out = advantage(cRos, cTat, tRos, tTat);
out[0] = out[0] * -1;
out[1] = out[1] * -1;
}
else if(tRos <= 0 && cRos <= 0 && tTat <= cTat && tRos >= cRos){
//case 5.1//
tRosAd = (tRos - cRos) * tTat;
tTatAd = (cTat - tTat) * tRos * -1;
//calculate total and joint advantage//
ttlAd = (tTat * tRos) - (cTat * cRos);
ja = ttlAd - (tRosAd + tTatAd);
rosAtt = tRosAd / (tRosAd + tTatAd);
tatAtt = tTatAd / (tRosAd + tTatAd);
tRosAd = ja * rosAtt + tRosAd;
tTatAd = ja * tatAtt + tTatAd;
out[0] = tRosAd;
out[1] = tTatAd;
}
else if(tRos <= 0 && cRos <= 0 && tTat >= cTat && tRos <= cRos){
//case 5.2//
out = advantage(cRos, cTat, tRos, tTat);
out[0] = out[0] * -1;
out[1] = out[1] * -1;
}
return out;
}