Skip to content

Commit

Permalink
fix strata=NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Gussenbauer - QM committed Nov 28, 2023
1 parent a1ce58e commit 06c213d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down Expand Up @@ -102,5 +102,5 @@ Collate:
'whipple.R'
'dataSets.R'
'zzz.R'
RoxygenNote: 7.2.2
RoxygenNote: 7.2.3
Encoding: UTF-8
4 changes: 3 additions & 1 deletion R/simCategorical.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
8 changes: 8 additions & 0 deletions R/specifyInput.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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)
Expand Down

0 comments on commit 06c213d

Please sign in to comment.