Skip to content

Commit

Permalink
Merge pull request #212 from kgoldfeld/issue-208-improve-addCorGen
Browse files Browse the repository at this point in the history
Fixing nvars in addCorGen
  • Loading branch information
kgoldfeld authored Aug 10, 2023
2 parents c3f02af + 383b688 commit d40d33d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions R/add_correlated_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ addCorFlex <- function(dt, defs, rho = 0, tau = NULL, corstr = "cs",
#' # Long example
#'
#' def <- defData(varname = "xbase", formula = 5, variance = .4, dist = "gamma", id = "cid")
#' def <- defData(def, "nperiods", formula = 3, dist = "noZeroPoisson")
#'
#' def2 <- defDataAdd(
#' varname = "p", formula = "-3+.2*period + .3*xbase",
Expand All @@ -328,6 +327,11 @@ addCorFlex <- function(dt, defs, rho = 0, tau = NULL, corstr = "cs",
#'
#' dtLong <- addPeriods(dt, idvars = "cid", nPeriods = 3)
#' dtLong <- addColumns(def2, dtLong)
#'
#' addCorGen(
#' dtOld = dtLong, idvar = "cid", nvars = NULL, rho = .7, corstr = "cs",
#' dist = "binary", param1 = "p"
#' )
#'
#' @concept correlated
#' @export
Expand Down Expand Up @@ -468,7 +472,8 @@ addCorGen <- function(dtOld, nvars=NULL, idvar = "id", rho=NULL, corstr=NULL, co
}

dtTemp[, seq_ := 1:.N, keyby = .id]

nvars <- dtTemp[.id == 1, .N] # only permits case where number of records per id is the same

####

if (method == "copula") {
Expand Down
6 changes: 5 additions & 1 deletion man/addCorGen.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d40d33d

Please sign in to comment.