fix: Use "choice" from the profile

I was using the "choice" variable directly, which is referred to by
different names in different profiles. The profile is supposed to be
agnostic about any variable name in the instrument, so this was a bug.
This commit is contained in:
Brian Albert Monroe 2021-07-07 13:49:37 +02:00
parent 56968e62f2
commit 5184a1383d
Signed by: bam
GPG Key ID: ACB52939BF87F222
2 changed files with 6 additions and 2 deletions

View File

@ -1,6 +1,6 @@
Package: rcguts
Title: Backend Functions for R Choice Packages
Version: 0.19.0
Version: 0.19.1
Authors@R: person('Brian Albert', 'Monroe', email = 'brianalbertmonroe@gmail.com', role = c('aut', 'cre'))
Description: This package provides some backend functions that are shared by the R Choice family of pacakes. In particular, likelihood functions written in c++.
Depends: R (>= 3.4.1)

View File

@ -185,8 +185,12 @@ arma::mat calc_likelihood(arma::mat pmat, DataFrame inst, List ftypes, List ft_i
arma::vec mlgeneral(arma::mat pmat, DataFrame inst, List ftypes, List ft_index, List profile) {
// Get the likelihoods for the options
arma::mat likelihoods = calc_likelihood(pmat, inst, ftypes, ft_index, profile);
// Grab the choice index from the profile
arma::uword choice_i = profile["choice"];
// Adjust from 1 base vectors to 0 base
choice_i -= 1;
// Grab the choice vector
arma::uvec choice = inst["choice"];
arma::uvec choice = inst[choice_i];
// Generate the final likelihood vector
arma::vec like(likelihoods.n_rows);
// Select the likelihood corresponding to the choice