Skip to content

Commit 58cb38a

Browse files
committed
fixed bug in getCatVarDummyNames
1 parent e454fb7 commit 58cb38a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
## Bugs
1010

1111
- Fixed bug where model with single variable would error due to a matrix being converted to a vector in the `standardDraws()` function
12+
- Fixed bug in `getCatVarDummyNames()` - previously used string matching, which can accidentally match with other similarly-named variables.
1213

1314
# logitr 0.1.1
1415

R/modelInputs.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ addIntPars <- function(data, parNames, intNames, parTypes) {
254254
}
255255

256256
getCatVarDummyNames <- function(data, discPar) {
257-
allVars <- names(data)
258-
matches <- which(grepl(paste0(discPar, "_"), allVars))
259-
return(allVars[matches][-1])
257+
levels <- as.vector(as.matrix(unique(data[discPar])))
258+
varNames <- sort(paste(discPar, levels, sep = "_"))
259+
return(varNames[-1])
260260
}
261261

262262
getParSetup <- function(parNames, priceName, randPars, randPrice) {

0 commit comments

Comments
 (0)