From d016415e85bee87c53eee659f7335bd8136f3ab8 Mon Sep 17 00:00:00 2001 From: John Helveston Date: Thu, 2 Feb 2023 11:24:08 -0500 Subject: [PATCH] one more bug fix with factor levels --- R/encoding.R | 3 +++ R/modelInputs.R | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/R/encoding.R b/R/encoding.R index 5328491..34138b5 100644 --- a/R/encoding.R +++ b/R/encoding.R @@ -53,6 +53,8 @@ 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) @@ -60,6 +62,7 @@ recodeData <- function(data, pars, randPars) { formula = formula, X = X, pars = colnames(X), + factorLevels = factorLevels, randPars = recodeRandPars(data, pars, randPars) )) } diff --git a/R/modelInputs.R b/R/modelInputs.R index cd571ee..2d9e51a 100644 --- a/R/modelInputs.R +++ b/R/modelInputs.R @@ -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])