Skip to content

Commit eb3e15f

Browse files
Keith GoldfeldKeith Goldfeld
Keith Goldfeld
authored and
Keith Goldfeld
committed
Adding the latest
1 parent 3270c31 commit eb3e15f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1924
-1822
lines changed

Diff for: .gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData
4+
src/*.o
5+
src/*.so
6+
src/*.dll

Diff for: DESCRIPTION

+31-29
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
Package: simstudy
2-
Type: Package
3-
Title: Simulation of Study Data
4-
Version: 0.0.0.9000
5-
Date: 2016-01-04
6-
Authors@R: person("Keith", "Goldfeld", email = "[email protected]",
7-
role = c("aut", "cre"))
8-
Author: Keith Goldfeld [aut]
9-
Mainainer: Keith Goldfeld <[email protected]>
10-
Description: A collection of functions that allow users to generate simulated
11-
data sets in order to explore modeling techniques or better understand data
12-
generating processes. The user specifies a set of relationships between
13-
covariates, and generates data based on these specifications. The final data
14-
sets can represent data from randomized control trials, repeated measure
15-
(longitudinal) designs, and cluster randomized trials. Missingness can be
16-
generated using various mechanisms (MCAR, MAR, NMAR).
17-
Depends:
18-
R (>= 3.2.2),
19-
data.table,
20-
mvnfast
21-
License: GPL-3
22-
LazyData: TRUE
23-
Imports:
24-
data.table
25-
RoxygenNote: 5.0.1
26-
Suggests: testthat,
27-
knitr,
28-
rmarkdown
29-
VignetteBuilder: knitr
1+
Package: simstudy
2+
Type: Package
3+
Title: Simulation of Study Data
4+
Version: 0.0.0.9000
5+
Date: 2016-01-04
6+
Authors@R: person("Keith", "Goldfeld", email = "[email protected]",
7+
role = c("aut", "cre"))
8+
Author: Keith Goldfeld [aut]
9+
Mainainer: Keith Goldfeld <[email protected]>
10+
Description: A collection of functions that allow users to generate simulated
11+
data sets in order to explore modeling techniques or better understand data
12+
generating processes. The user specifies a set of relationships between
13+
covariates, and generates data based on these specifications. The final data
14+
sets can represent data from randomized control trials, repeated measure
15+
(longitudinal) designs, and cluster randomized trials. Missingness can be
16+
generated using various mechanisms (MCAR, MAR, NMAR).
17+
Depends:
18+
R (>= 3.2.2),
19+
data.table,
20+
mvnfast
21+
License: GPL-3
22+
LazyData: TRUE
23+
Imports:
24+
data.table,
25+
Rcpp
26+
RoxygenNote: 5.0.1
27+
Suggests: testthat,
28+
knitr,
29+
rmarkdown
30+
VignetteBuilder: knitr
31+
LinkingTo: Rcpp

Diff for: LICENSE

+674-674
Large diffs are not rendered by default.

Diff for: NAMESPACE

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(addColumns)
4-
export(addDefs)
54
export(addPeriods)
5+
export(defData)
66
export(genCluster)
77
export(genCorData)
88
export(genData)
99
export(genMiss)
1010
export(genObs)
11-
export(initDefs)
1211
export(mergeData)
12+
importFrom(Rcpp,sourceCpp)
13+
useDynLib(simstudy)

Diff for: R/RcppExports.R

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This file was generated by Rcpp::compileAttributes
2+
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
#' Multinomial
5+
#'
6+
vecMultinom <- function(probs) {
7+
.Call('simstudy_vecMultinom', PACKAGE = 'simstudy', probs)
8+
}
9+
10+
#' Matrix Multinomial
11+
#'
12+
#' @export
13+
matMultinom <- function(probmatrix) {
14+
.Call('simstudy_matMultinom', PACKAGE = 'simstudy', probmatrix)
15+
}
16+

Diff for: R/addColumns.R

+25-20
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
#' Add columns to existing data set
2-
#'
3-
#' @param dtDefs Name of definitions for added columns
4-
#' @param dtOld Name of data table that is to be updated
5-
#' @return An updated data.table that contains the added simulated data
6-
#' @export
7-
#'
8-
9-
addColumns <- function(dtDefs,dtOld) {
10-
11-
iter = nrow(dtDefs)
12-
n = nrow(dtOld)
13-
for (i in (1 : iter)) {
14-
dtOld <- generate(dtDefs[i,], n, dtOld)
15-
}
16-
17-
data.table::data.table(dtOld)
18-
19-
}
20-
1+
#' Add columns to existing data set
2+
#'
3+
#' @param dtDefs Name of definitions for added columns
4+
#' @param dtOld Name of data table that is to be updated
5+
#' @return An updated data.table that contains the added simulated data
6+
#' @export
7+
#'
8+
9+
addColumns <- function(dtDefs,dtOld) {
10+
11+
oldkey <- data.table::key(dtOld)
12+
13+
iter = nrow(dtDefs)
14+
n = nrow(dtOld)
15+
for (i in (1 : iter)) {
16+
dtOld <- generate(dtDefs[i,], n, dtOld)
17+
}
18+
19+
dtOld <- data.table::data.table(dtOld)
20+
data.table::setkeyv(dtOld, oldkey)
21+
22+
return(dtOld)
23+
24+
}
25+

Diff for: R/addPeriods.R

+56-56
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
#' Create longitudinal/panel data
2-
#'
3-
#' @param dtName Name of existing data table
4-
#' @param nPeriods Number of time periods for each record
5-
#' @param idvars Names of index variables (in a string vector) that will be
6-
#' repeated during each time period
7-
#' @param timevars Names of time dependent variables. Defaults to NULL.
8-
#' @param timevarName Name of new time dependent varialbe
9-
#' @return An updated data.table that that has multiple rows
10-
#' per observation in dtName
11-
#' @export
12-
#'
13-
14-
# dtName must contain id for now
15-
16-
addPeriods <- function(dtName, nPeriods, idvars = "id",
17-
timevars = NULL, timevarName = "timevar") {
18-
19-
dtX1 <- copy(dtName)
20-
21-
if (!is.null(timevars)) {
22-
dtX1[, eval(timevars) := NULL, with=TRUE]
23-
}
24-
25-
dtTimes1 <- dtX1[, .(period = (0 : (nPeriods - 1))), keyby = idvars]
26-
data.table::setkeyv(dtX1, idvars)
27-
dtTimes1 <- dtTimes1[dtX1]
28-
data.table::setkeyv(dtTimes1, c(idvars, "period"))
29-
30-
if (!is.null(timevars)) {
31-
32-
dtX2 <- copy(dtName)
33-
varX2 <- names(dtX2)[!(names(dtX2) %in% c(idvars,timevars))]
34-
35-
if (length(varX2)) {
36-
dtX2[, eval(varX2) := NULL, with=TRUE]
37-
}
38-
39-
dtTimes2 <- data.table::melt(dtX2,id.vars=idvars,
40-
value.name = timevarName,
41-
variable.name = "period",
42-
variable.factor = TRUE)
43-
44-
dtTimes2[, period := factor(period, timevars)]
45-
dtTimes2[, period := as.integer(period) - 1]
46-
data.table::setkeyv(dtTimes2, c(idvars, "period"))
47-
48-
return(dtTimes1[dtTimes2])
49-
50-
} else {
51-
52-
return(dtTimes1)
53-
54-
}
55-
56-
}
1+
#' Create longitudinal/panel data
2+
#'
3+
#' @param dtName Name of existing data table
4+
#' @param nPeriods Number of time periods for each record
5+
#' @param idvars Names of index variables (in a string vector) that will be
6+
#' repeated during each time period
7+
#' @param timevars Names of time dependent variables. Defaults to NULL.
8+
#' @param timevarName Name of new time dependent varialbe
9+
#' @return An updated data.table that that has multiple rows
10+
#' per observation in dtName
11+
#' @export
12+
#'
13+
14+
# dtName must contain id for now
15+
16+
addPeriods <- function(dtName, nPeriods, idvars = "id",
17+
timevars = NULL, timevarName = "timevar") {
18+
19+
dtX1 <- copy(dtName)
20+
21+
if (!is.null(timevars)) {
22+
dtX1[, eval(timevars) := NULL, with=TRUE]
23+
}
24+
25+
dtTimes1 <- dtX1[, .(period = (0 : (nPeriods - 1))), keyby = idvars]
26+
data.table::setkeyv(dtX1, idvars)
27+
dtTimes1 <- dtTimes1[dtX1]
28+
data.table::setkeyv(dtTimes1, c(idvars, "period"))
29+
30+
if (!is.null(timevars)) {
31+
32+
dtX2 <- copy(dtName)
33+
varX2 <- names(dtX2)[!(names(dtX2) %in% c(idvars,timevars))]
34+
35+
if (length(varX2)) {
36+
dtX2[, eval(varX2) := NULL, with=TRUE]
37+
}
38+
39+
dtTimes2 <- data.table::melt(dtX2,id.vars=idvars,
40+
value.name = timevarName,
41+
variable.name = "period",
42+
variable.factor = TRUE)
43+
44+
dtTimes2[, period := factor(period, timevars)]
45+
dtTimes2[, period := as.integer(period) - 1]
46+
data.table::setkeyv(dtTimes2, c(idvars, "period"))
47+
48+
return(dtTimes1[dtTimes2])
49+
50+
} else {
51+
52+
return(dtTimes1)
53+
54+
}
55+
56+
}

Diff for: R/addDefs.R renamed to R/defData.R

+39-41
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
1-
#' Add single row to definitions table
2-
#'
3-
#' @param dtDefs Definition data.table to be modified
4-
#' @param varName test
5-
#' @param formula test
6-
#' @param variance test
7-
#' @param dist test
8-
#' @param link test
9-
#' @param nTrt test
10-
#' @param cMethod test
11-
#' @param missType test
12-
#' @return A data.table named dtName that is an updated data defnitions table
13-
#' @export
14-
15-
addDefs <- function(dtDefs,
16-
varname = "",
17-
formula = "",
18-
variance = 0,
19-
dist = "Normal",
20-
link = "identity",
21-
nTrt = 0,
22-
cMethod = "",
23-
missType = "") {
24-
25-
dt.new <- data.table::data.table(varname,
26-
formula,
27-
variance,
28-
dist,
29-
link,
30-
nTrt,
31-
cMethod,
32-
missType)
33-
34-
l = list(dtDefs,dt.new)
35-
36-
defNew <- data.table::rbindlist(l, use.names = TRUE, fill = TRUE)
37-
attr(defNew, "id") <- attr(dtDefs, "id")
38-
39-
return(defNew)
40-
41-
}
1+
#' Add single row to definitions table
2+
#'
3+
#' @param dtDefs Definition data.table to be modified
4+
#' @param varName test
5+
#' @param formula test
6+
#' @param variance test
7+
#' @param dist test
8+
#' @param link test
9+
#' @param id test
10+
#' @return A data.table named dtName that is an updated data defnitions table
11+
#' @export
12+
13+
defData <- function(dtDefs = NULL,
14+
varname = "",
15+
formula = "",
16+
variance = 0,
17+
dist = "Normal",
18+
link = "identity",
19+
id="id") {
20+
21+
if (is.null(dtDefs)) {
22+
dtDefs <- data.table::data.table()
23+
attr(dtDefs,"id") <- id
24+
}
25+
26+
dt.new <- data.table::data.table(varname,
27+
formula,
28+
variance,
29+
dist,
30+
link)
31+
32+
l = list(dtDefs,dt.new)
33+
34+
defNew <- data.table::rbindlist(l, use.names = TRUE, fill = TRUE)
35+
attr(defNew, "id") <- attr(dtDefs, "id")
36+
37+
return(defNew)
38+
39+
}

0 commit comments

Comments
 (0)