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])