Skip to content

Commit

Permalink
one more bug fix with factor levels
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelvy committed Feb 2, 2023
1 parent 88ea38d commit d016415
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions R/encoding.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ dummyCode <- function(df, vars) {
#' result$randPars
#' head(result$X)
recodeData <- function(data, pars, randPars) {
data <- as.data.frame(data) # tibbles break things
factorLevels <- getFactorLevels(data, pars) # need to store for predicting
data <- orderedFactorsToChars(data) # ordered factors cause weird names
formula <- stats::as.formula(paste0("~ ", paste(pars, collapse = " + ")))
X <- getDesignMatrix(formula, data)
return(list(
formula = formula,
X = X,
pars = colnames(X),
factorLevels = factorLevels,
randPars = recodeRandPars(data, pars, randPars)
))
}
Expand Down
2 changes: 1 addition & 1 deletion R/modelInputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ getModelInputs <- function(
# Get the design matrix, recoding parameters that are categorical
# or have interactions
data <- as.data.frame(data) # tibbles break things
factorLevels <- getFactorLevels(data, pars) # need to store for predicting
recoded <- recodeData(data, pars, randPars)
formula <- recoded$formula
X <- recoded$X
pars <- recoded$pars
randPars <- recoded$randPars
factorLevels <- recoded$factorLevels
scalePar <- defineScalePar(data, inputs, modelSpace)
outcome <- as.matrix(data[outcome])

Expand Down

0 comments on commit d016415

Please sign in to comment.