diff --git a/DESCRIPTION b/DESCRIPTION index cc97264..850eb85 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: simPop Type: Package Title: Simulation of Complex Synthetic Data Information -Version: 2.1.2 +Version: 2.1.3 Date: 2022-11-06 Authors@R: c( person("Matthias", "Templ", email = "matthias.templ@gmail.com", role = c("aut","cre")), @@ -102,5 +102,5 @@ Collate: 'whipple.R' 'dataSets.R' 'zzz.R' -RoxygenNote: 7.2.2 +RoxygenNote: 7.2.3 Encoding: UTF-8 diff --git a/R/simCategorical.R b/R/simCategorical.R index 5fbeb36..7cac9fe 100644 --- a/R/simCategorical.R +++ b/R/simCategorical.R @@ -65,7 +65,9 @@ generateValues <- function(dataSample, dataPop, params) { }else if ( meth %in% c("ctree","cforest") ) { probs <- predict(mod, newdata=data.table(newdata), type="prob") probs <- split(probs, seq(nrow(probs))) - probs <- do.call("rbind",probs) + if(!inherits(probs,"matrix")){ + probs <- do.call("rbind",probs) + } if(ncol(probs)==2){ probs <- probs[,2] } diff --git a/R/specifyInput.R b/R/specifyInput.R index 8f63bff..a1ca86b 100644 --- a/R/specifyInput.R +++ b/R/specifyInput.R @@ -35,6 +35,10 @@ #' inp specifyInput <- function(data, hhid, hhsize=NULL, pid=NULL, weight=NULL, strata=NULL, population=FALSE) { + + if(!(inherits(data,"data.frame") | inherits(data,"data.table"))){ + stop("data must be either a data.frame or data.table") + } if ( !inherits(hhid, "character") | length(hhid) != 1 | is.na(match(hhid, colnames(data)))) { stop("hhid must be a character defining the variable holding household ids and must be of length 1!\n") } @@ -54,6 +58,10 @@ specifyInput <- function(data, hhid, hhsize=NULL, pid=NULL, weight=NULL, if(!inherits(data[[strata]], "factor")){ stop(strata," is not a factor variable as needed for a strata variable.") } + }else{ + # initialize dummy strata used by other methods in package + strata <- paste(c("DUMMY_STRATA_",sample(c(letters,LETTERS),8,replace=TRUE)), collapse="") + df[[strata]] <- factor(1) } data <- as.data.table(data)