diff --git a/dev/CODE_OF_CONDUCT.html b/dev/CODE_OF_CONDUCT.html index e1c4a810..a8766246 100644 --- a/dev/CODE_OF_CONDUCT.html +++ b/dev/CODE_OF_CONDUCT.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/CONTRIBUTING.html b/dev/CONTRIBUTING.html index 323b8b0f..49bf85a7 100644 --- a/dev/CONTRIBUTING.html +++ b/dev/CONTRIBUTING.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/LICENSE-text.html b/dev/LICENSE-text.html index adc7ba03..42c3ddf7 100644 --- a/dev/LICENSE-text.html +++ b/dev/LICENSE-text.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/SUPPORT.html b/dev/SUPPORT.html index dcc6f135..5f6012c0 100644 --- a/dev/SUPPORT.html +++ b/dev/SUPPORT.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/articles/clustered.html b/dev/articles/clustered.html index 02bb651f..0d8591d7 100644 --- a/dev/articles/clustered.html +++ b/dev/articles/clustered.html @@ -65,6 +65,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/articles/corelationmat.html b/dev/articles/corelationmat.html index 0da4b905..6717698f 100644 --- a/dev/articles/corelationmat.html +++ b/dev/articles/corelationmat.html @@ -65,6 +65,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • @@ -1095,18 +1098,18 @@

    Varying correlation matrices by
    ##    site period n
     ## 1:    1      0 4
     ## 2:    1      1 2
    -## 3:    1      2 2
    +## 3:    1      2 3
     ## 4:    3      0 3
    -## 5:    3      1 2
    +## 5:    3      1 3
     ## 6:    3      2 3
    -## 7:    7      0 4
    -## 8:    7      1 4
    -## 9:    7      2 4
    +## 7: 7 0 3 +## 8: 7 1 2 +## 9: 7 2 3

    The sites will also have unique decay rates:

     r <- round(rbeta(10, 6, 2), 2)
     r[c(1, 3, 7)]
    -
    ## [1] 0.76 0.94 0.87
    +
    ## [1] 0.66 0.85 0.81

    Here are the correlation matrices for these three sites:

     N <- dd[, .N, keyby = .(site, period)][, N]
    @@ -1115,41 +1118,39 @@ 

    Varying correlation matrices by lapply(R, function(x) round(x,2))[c(1, 3, 7)]

    ## [[1]]
    -##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
    -## [1,] 1.00 0.60 0.60 0.60 0.46 0.46 0.35 0.35
    -## [2,] 0.60 1.00 0.60 0.60 0.46 0.46 0.35 0.35
    -## [3,] 0.60 0.60 1.00 0.60 0.46 0.46 0.35 0.35
    -## [4,] 0.60 0.60 0.60 1.00 0.46 0.46 0.35 0.35
    -## [5,] 0.46 0.46 0.46 0.46 1.00 0.60 0.46 0.46
    -## [6,] 0.46 0.46 0.46 0.46 0.60 1.00 0.46 0.46
    -## [7,] 0.35 0.35 0.35 0.35 0.46 0.46 1.00 0.60
    -## [8,] 0.35 0.35 0.35 0.35 0.46 0.46 0.60 1.00
    +##       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
    +##  [1,] 1.00 0.60 0.60 0.60  0.4  0.4 0.26 0.26 0.26
    +##  [2,] 0.60 1.00 0.60 0.60  0.4  0.4 0.26 0.26 0.26
    +##  [3,] 0.60 0.60 1.00 0.60  0.4  0.4 0.26 0.26 0.26
    +##  [4,] 0.60 0.60 0.60 1.00  0.4  0.4 0.26 0.26 0.26
    +##  [5,] 0.40 0.40 0.40 0.40  1.0  0.6 0.40 0.40 0.40
    +##  [6,] 0.40 0.40 0.40 0.40  0.6  1.0 0.40 0.40 0.40
    +##  [7,] 0.26 0.26 0.26 0.26  0.4  0.4 1.00 0.60 0.60
    +##  [8,] 0.26 0.26 0.26 0.26  0.4  0.4 0.60 1.00 0.60
    +##  [9,] 0.26 0.26 0.26 0.26  0.4  0.4 0.60 0.60 1.00
     ## 
     ## [[2]]
    -##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
    -## [1,] 1.00 0.60 0.60 0.56 0.56 0.53 0.53 0.53
    -## [2,] 0.60 1.00 0.60 0.56 0.56 0.53 0.53 0.53
    -## [3,] 0.60 0.60 1.00 0.56 0.56 0.53 0.53 0.53
    -## [4,] 0.56 0.56 0.56 1.00 0.60 0.56 0.56 0.56
    -## [5,] 0.56 0.56 0.56 0.60 1.00 0.56 0.56 0.56
    -## [6,] 0.53 0.53 0.53 0.56 0.56 1.00 0.60 0.60
    -## [7,] 0.53 0.53 0.53 0.56 0.56 0.60 1.00 0.60
    -## [8,] 0.53 0.53 0.53 0.56 0.56 0.60 0.60 1.00
    +##       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
    +##  [1,] 1.00 0.60 0.60 0.51 0.51 0.51 0.43 0.43 0.43
    +##  [2,] 0.60 1.00 0.60 0.51 0.51 0.51 0.43 0.43 0.43
    +##  [3,] 0.60 0.60 1.00 0.51 0.51 0.51 0.43 0.43 0.43
    +##  [4,] 0.51 0.51 0.51 1.00 0.60 0.60 0.51 0.51 0.51
    +##  [5,] 0.51 0.51 0.51 0.60 1.00 0.60 0.51 0.51 0.51
    +##  [6,] 0.51 0.51 0.51 0.60 0.60 1.00 0.51 0.51 0.51
    +##  [7,] 0.43 0.43 0.43 0.51 0.51 0.51 1.00 0.60 0.60
    +##  [8,] 0.43 0.43 0.43 0.51 0.51 0.51 0.60 1.00 0.60
    +##  [9,] 0.43 0.43 0.43 0.51 0.51 0.51 0.60 0.60 1.00
     ## 
     ## [[3]]
    -##       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
    -##  [1,] 1.00 0.60 0.60 0.60 0.52 0.52 0.52 0.52 0.45  0.45  0.45  0.45
    -##  [2,] 0.60 1.00 0.60 0.60 0.52 0.52 0.52 0.52 0.45  0.45  0.45  0.45
    -##  [3,] 0.60 0.60 1.00 0.60 0.52 0.52 0.52 0.52 0.45  0.45  0.45  0.45
    -##  [4,] 0.60 0.60 0.60 1.00 0.52 0.52 0.52 0.52 0.45  0.45  0.45  0.45
    -##  [5,] 0.52 0.52 0.52 0.52 1.00 0.60 0.60 0.60 0.52  0.52  0.52  0.52
    -##  [6,] 0.52 0.52 0.52 0.52 0.60 1.00 0.60 0.60 0.52  0.52  0.52  0.52
    -##  [7,] 0.52 0.52 0.52 0.52 0.60 0.60 1.00 0.60 0.52  0.52  0.52  0.52
    -##  [8,] 0.52 0.52 0.52 0.52 0.60 0.60 0.60 1.00 0.52  0.52  0.52  0.52
    -##  [9,] 0.45 0.45 0.45 0.45 0.52 0.52 0.52 0.52 1.00  0.60  0.60  0.60
    -## [10,] 0.45 0.45 0.45 0.45 0.52 0.52 0.52 0.52 0.60  1.00  0.60  0.60
    -## [11,] 0.45 0.45 0.45 0.45 0.52 0.52 0.52 0.52 0.60  0.60  1.00  0.60
    -## [12,] 0.45 0.45 0.45 0.45 0.52 0.52 0.52 0.52 0.60  0.60  0.60  1.00
    +## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] +## [1,] 1.00 0.60 0.60 0.49 0.49 0.39 0.39 0.39 +## [2,] 0.60 1.00 0.60 0.49 0.49 0.39 0.39 0.39 +## [3,] 0.60 0.60 1.00 0.49 0.49 0.39 0.39 0.39 +## [4,] 0.49 0.49 0.49 1.00 0.60 0.49 0.49 0.49 +## [5,] 0.49 0.49 0.49 0.60 1.00 0.49 0.49 0.49 +## [6,] 0.39 0.39 0.39 0.49 0.49 1.00 0.60 0.60 +## [7,] 0.39 0.39 0.39 0.49 0.49 0.60 1.00 0.60 +## [8,] 0.39 0.39 0.39 0.49 0.49 0.60 0.60 1.00

    And here is code to generate the empirical correlation matrices for the three sites, based on 5000 replications of the data:

    diff --git a/dev/articles/correlated.html b/dev/articles/correlated.html
    index 70d5d127..e5541fcc 100644
    --- a/dev/articles/correlated.html
    +++ b/dev/articles/correlated.html
    @@ -65,6 +65,9 @@
         
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/articles/double_dot_extension.html b/dev/articles/double_dot_extension.html index 595d30f3..d3a5f755 100644 --- a/dev/articles/double_dot_extension.html +++ b/dev/articles/double_dot_extension.html @@ -65,6 +65,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • @@ -340,17 +343,20 @@

    Using non-scalar double- d1 <- defData(d1, varname = "b", formula = ".5;.5", variance = "1;2", dist = "categorical") d1 <- defData(d1, varname = "outcome", formula = "..effect[a, b]", dist="nonrandom")

    -dx <- genData(8, d1)
    +dx <- genData(1000, d1)
     dx
    -
    ##    id a b outcome
    -## 1:  1 2 2       7
    -## 2:  2 2 2       7
    -## 3:  3 2 1       4
    -## 4:  4 2 1       4
    -## 5:  5 1 1       0
    -## 6:  6 2 2       7
    -## 7:  7 2 1       4
    -## 8:  8 1 2       5
    +
    ##         id a b outcome
    +##    1:    1 2 2       7
    +##    2:    2 2 1       4
    +##    3:    3 2 1       4
    +##    4:    4 2 2       7
    +##    5:    5 1 2       5
    +##   ---                 
    +##  996:  996 2 2       7
    +##  997:  997 2 2       7
    +##  998:  998 1 1       0
    +##  999:  999 2 2       7
    +## 1000: 1000 1 2       5

    It is possible to generate normally distributed data based on these means:

    @@ -358,11 +364,6 @@ 

    Using non-scalar double- dx <- genData(1000, d1)

    The plot shows the individual values as well as the mean values by intervention arm:

    -
    ## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
    -##  Please use `linewidth` instead.
    -## This warning is displayed once every 8 hours.
    -## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
    -## generated.

    diff --git a/dev/articles/double_dot_extension_files/figure-html/unnamed-chunk-18-1.png b/dev/articles/double_dot_extension_files/figure-html/unnamed-chunk-18-1.png index eadfee20..e62c7cf1 100644 Binary files a/dev/articles/double_dot_extension_files/figure-html/unnamed-chunk-18-1.png and b/dev/articles/double_dot_extension_files/figure-html/unnamed-chunk-18-1.png differ diff --git a/dev/articles/index.html b/dev/articles/index.html index 7ecff4fa..92866f60 100644 --- a/dev/articles/index.html +++ b/dev/articles/index.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • @@ -98,6 +101,8 @@

    All vignettes

    Dynamic Data Definition
    +
    Simulating data from logistic model with specified characterstics
    +
    Longitudinal Data
    Missing Data
    diff --git a/dev/articles/logisticCoefs.html b/dev/articles/logisticCoefs.html new file mode 100644 index 00000000..fdfc991a --- /dev/null +++ b/dev/articles/logisticCoefs.html @@ -0,0 +1,423 @@ + + + + + + + +Simulating data from logistic model with specified characterstics • simstudy + + + + + + + + + + + + + +
    +
    + + + + +
    +
    + + + + +

    In simstudy, there are at least two ways to define a +binary data generating process. The first is to operate on the scale of +the proportion or probability using the identity link. This +allows users to characterize a data generating process that reflects +assumptions about risk ratios and risk differences when comparing two +groups defined by an exposure or treatment. However, this process can +become challenging when introducing other covariates, because it can be +difficult to constrain the probabilities so that they fall between 0 and +1.

    +

    Alternatively, the second approach works on the log-odds scale and +uses the logit link, and is much more amenable to accomodating +covariates. Unfortunately, this comes at the price of being able to +easily generate specific risk ratios and risk differences, because all +parameters are log-odds ratios. If we are interested in the controlling +overall probability in a population with a set of covariates that each +have a certain distribution and particular association with an outcome, +the overall (marginal) proportion will vary across different +distributions and associations.

    +

    Here we start with the simplest case where we have a target marginal +proportion or prevalence, and illustrate data generation with three +other target statistics: risk ratios, risk +differences, and AUCs.

    +
    +

    Prevalence +

    +

    In this first example, we start with one set of assumptions for four +covariates \(x_1 \sim N(0, 1)\), \(x_2 \sim N(0, 1)\), \(b_1 \sim Bin(0.3)\), and \(b_2 \sim Bin(0.7)\), and generate the +outcome y with the following data generating process:

    +

    \[ \text{logit}(y) = 0.15*x1 + 0.25*x2 + +0.10*b1 + 0.30*b2\]

    +
    +coefs1 <- c(0.15, 0.25, 0.10, 0.30)
    +
    +d1 <- defData(varname = "x1", formula = 0, variance = 1)
    +d1 <- defData(d1, varname = "x2", formula = 0, variance = 1)
    +d1 <- defData(d1, varname = "b1", formula = 0.3, dist = "binary")
    +d1 <- defData(d1, varname = "b2", formula = 0.7, dist = "binary")
    +
    +d1a <- defData(d1, varname = "y", 
    +  formula = "t(..coefs1) %*% c(x1, x2, b1, b2)",
    +  dist = "binary", link = "logit")
    +
    +set.seed(48392)
    +
    +dd <- genData(500000, d1a)
    +dd
    +
    ##             id    x1     x2 b1 b2 y
    +##      1:      1  0.29  0.390  0  1 1
    +##      2:      2  0.76 -0.925  0  0 0
    +##      3:      3 -1.47  0.939  0  0 1
    +##      4:      4  1.92  0.560  0  1 1
    +##      5:      5  1.40 -0.238  0  1 0
    +##     ---                            
    +## 499996: 499996 -0.32  0.367  0  0 0
    +## 499997: 499997 -1.08  2.152  0  0 0
    +## 499998: 499998 -1.10  0.380  1  0 0
    +## 499999: 499999  0.56 -1.042  0  1 0
    +## 500000: 500000  0.52  0.076  0  1 1
    +

    The overall proportion of \(y=1\) in +this case is

    +
    +dd[, mean(y)]
    +
    ## [1] 0.56
    +

    If we have a desired marginal proportion of 0.40, then we can add an +intercept of -0.66 to the data generating process:

    +

    \[ \text{logit}(y) = -0.66 + 0.15*x1 + +0.25 *x2 + 0.10*b1 + 0.30*b2\]

    +

    The simulation now gives us the desired target:

    +
    +d1a <- defData(d1, varname = "y", 
    +  formula = "t(c(-0.66,..coefs1)) %*% c(1, x1, x2, b1, b2)",
    +  dist = "binary", link = "logit")
    +
    +genData(500000, d1a)[, mean(y)]
    +
    ## [1] 0.4
    +

    If we change the distribution of the covariates, so that \(x_1 \sim N(1, 1)\), \(x_2 \sim N(2, 1)\), \(b_1 \sim Bin(0.5)\), and \(b_2 \sim Bin(0.8)\), and the strength of +the association of these covariates with the outcome so that

    +

    \[ \text{logit}(y) = 0.20*x1 + 0.35 *x2 + +0.20*b1 + 0.45*b2,\]

    +

    the marginal proportion/prevalence (assuming no intercept term) also +changes, going from 0.56 to 0.84:

    +
    +coefs2 <- c(0.20, 0.35, 0.20, 0.45)
    +
    +d2 <- defData(varname = "x1", formula = 1, variance = 1)
    +d2 <- defData(d2, varname = "x2", formula = 3, variance = 1)
    +d2 <- defData(d2, varname = "b1", formula = 0.5, dist = "binary")
    +d2 <- defData(d2, varname = "b2", formula = 0.8, dist = "binary")
    +
    +d2a <- defData(d2, varname = "y", 
    +  formula = "t(..coefs2) %*% c(x1, x2, b1, b2)",
    +  dist = "binary", link = "logit")
    +
    +genData(500000, d2a)[, mean(y)]
    +
    ## [1] 0.84
    +

    But under this new distribution, adding an intercept of -2.14 yields +the desired target.

    +

    \[ \text{logit}(y) = -2.14 + 0.20*x1 + +0.35 *x2 + 0.20*b1 + 0.45*b2 \]

    +
    +d2a <- defData(d2, varname = "y", 
    +  formula = "t(c(-2.14,..coefs2)) %*% c(1, x1, x2, b1, b2)",
    +  dist = "binary", link = "logit")
    +
    +genData(500000, d1a)[, mean(y)]
    +
    ## [1] 0.4
    +
    +

    Finding the intercept +

    +

    Where did those two intercepts come from? A paper by Peter Austin describes an iterative +bisection procedure that takes a distribution of covariates and a set of +coefficients to identify the intercept coefficient that yields the +target marginal proportion or prevalence. This algorithm has been +implemented in simstudy through the function +logisticCoefs. (If you want the details for the algorithm, +take a look at the paper. Here, I will demonstrate the application.)

    +

    The intercept is provided by a simple call to +logisticCoefs. Here are the calls for the two sets of +definitions in definition tables d1 and d2.

    +
    +logisticCoefs(defCovar = d1, coefs = coefs1, popPrev = 0.40)
    +
    ##    B0    x1    x2    b1    b2 
    +## -0.66  0.15  0.25  0.10  0.30
    +
    +logisticCoefs(defCovar = d2, coefs = coefs2, popPrev = 0.40)
    +
    ##    B0    x1    x2    b1    b2 
    +## -2.14  0.20  0.35  0.20  0.45
    +
    +
    +
    +

    Risk ratios +

    +

    Just as the prevalance depends on the distribution of covariates and +their association with the outcome, risk ratios comparing the outcome +probabilities for two groups also depend on the additional covariates. +The risk ratio comparing treatment (\(A +=1\) to control (\(A=0\)) is

    +

    \[RR = \frac{P(y=1 | A = 1)}{P(y=1 | A = +0)}\] In the data generation process we use a log-odds ratio of +-0.40 (odds ratio of approximately 0.67) in both cases, but we get +different risk ratios (0.82 vs. 0.90).

    +
    +d1a <- defData(d1, varname = "rx", formula = "1;1", dist = "trtAssign")
    +d1a <- defData(d1a, varname = "y",
    +  formula = "t(c(-0.40, ..coefs1)) %*% c(rx, x1, x2, b1, b2)",
    +  dist = "binary", link = "logit"
    +)
    +
    +dd <- genData(500000, d1a)
    +dd[rx==1, mean(y)]/dd[rx==0, mean(y)]
    +
    ## [1] 0.83
    +
    +d2a <- defData(d2, varname = "rx", formula = "1;1", dist = "trtAssign")
    +d2a <- defData(d2a, varname = "y",
    +  formula = "t(c(-0.40, ..coefs2)) %*% c(rx, x1, x2, b1, b2)",
    +  dist = "binary", link = "logit"
    +)
    +
    +dd <- genData(500000, d2a)
    +dd[rx==1, mean(y)]/dd[rx==0, mean(y)]
    +
    ## [1] 0.93
    +

    By specifying both a population prevalence and a target risk ratio in +the call to logisticCoefs, we can get the necessary +parameters. When specifying the target risk ratio, it is required to be +between 0 and 1/popPrev. A risk ratio cannot be negative, and the +probability of the outcome under treatment cannot exceed 1 (which will +happen if the risk ratio is greater than 1/popPrev).

    +
    +C1 <- logisticCoefs(d1, coefs1, popPrev = 0.40, rr = 0.85)
    +C1
    +
    ##    B0     A    x1    x2    b1    b2 
    +## -0.66 -0.26  0.15  0.25  0.10  0.30
    +

    If we use \(C_1\) in the data +generation process, we will get a data set with the desired target +prevalence and risk ratio:

    +
    +d1a <- defData(d1, varname = "rx", formula = "1;1", dist = "trtAssign")
    +d1a <- defData(d1a, varname = "y",
    +  formula = "t(..C1) %*% c(1, rx, x1, x2, b1, b2)",
    +  dist = "binary", link = "logit"
    +)
    +
    +dd <- genData(500000, d1a)
    +

    Here are the prevalence and risk ratio:

    +
    +dd[rx==0, mean(y)]
    +
    ## [1] 0.4
    +
    +dd[rx==1, mean(y)]/dd[rx==0, mean(y)]
    +
    ## [1] 0.85
    +

    You can do the same for the second set of assumptions.

    +
    +
    +

    Risk differences +

    +

    Risk differences have the same set of issues, and are handled in the +same way. The risk difference is defined as

    +

    \[ RD = P(y=1 | A = 1) - P(y=1 | A = +0)\]

    +

    To get the coefficients related to a population prevalence of 0.40 +and risk difference of -0.15 (so that the proportion in the exposure arm +is 0.25), we use the rd argument:

    +
    +C1 <- logisticCoefs(d1, coefs1, popPrev = 0.40, rd = -0.15)
    +C1
    +
    ##    B0     A    x1    x2    b1    b2 
    +## -0.66 -0.71  0.15  0.25  0.10  0.30
    +

    Again, using \(C_1\) in the data +generation process, we will get a data set with the desired target +prevalence and risk difference:

    +
    +d1a <- defData(d1, varname = "rx", formula = "1;1", dist = "trtAssign")
    +d1a <- defData(d1a, varname = "y",
    +  formula = "t(..C1) %*% c(1, rx, x1, x2, b1, b2)",
    +  dist = "binary", link = "logit"
    +)
    +
    +dd <- genData(500000, d1a)
    +
    +dd[rx==0, mean(y)]
    +
    ## [1] 0.4
    +
    +dd[rx==1, mean(y)] - dd[rx==0, mean(y)]
    +
    ## [1] -0.15
    +
    +
    +

    AUC +

    +

    The AUC is another commonly used statistic to evaulate a logistic +model. We can use logisticCoefs to find the parameters that +will allow us to generate data from a model with a specific AUC. To get +the coefficients related to a population prevalence of 0.40 and an AUC +of 0.85, we use the auc argument (the auc must be +between 0.5 and 1):

    +
    +C1 <- logisticCoefs(d1, coefs1, popPrev = 0.40, auc = 0.85)
    +C1
    +
    ##    B0    x1    x2    b1    b2 
    +## -2.09  0.89  1.48  0.59  1.78
    +

    Again, using \(C_1\) in the data +generation process, we will get a data set with the desired target +prevalence and the AUC (calculated here using the lrm +function in the rms package:

    +
    +d1a <- defData(d1, varname = "y",
    +  formula = "t(..C1) %*% c(1, x1, x2, b1, b2)",
    +  dist = "binary", link = "logit"
    +)
    +
    +dd <- genData(500000, d1a)
    +
    +dd[, mean(y)]
    +
    ## [1] 0.4
    +
    +fit <- rms::lrm(y ~ x1 + x2 + b1 + b2, data = dd)
    +fit$stats["C"]
    +
    ##    C 
    +## 0.86
    +

    +

    +

    References:

    +

    Austin, Peter C. “The iterative bisection procedure: a useful tool +for determining parameter values in data-generating processes in Monte +Carlo simulations.” BMC Medical Research Methodology 23, no. 1 (2023): +1-10.

    + + +
    +
    + + + +
    + + + + +
    + + + + + + + + diff --git a/dev/articles/longitudinal.html b/dev/articles/longitudinal.html index d88a028d..169b3c14 100644 --- a/dev/articles/longitudinal.html +++ b/dev/articles/longitudinal.html @@ -65,6 +65,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/articles/missing.html b/dev/articles/missing.html index b918fc12..9122d48d 100644 --- a/dev/articles/missing.html +++ b/dev/articles/missing.html @@ -65,6 +65,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • @@ -178,24 +181,24 @@

    Missing Data

    ## 5: 5 1 1 0 1 0 ## --- ## 996: 996 0 0 0 1 0 -## 997: 997 1 0 0 1 0 -## 998: 998 0 1 0 1 0 +## 997: 997 1 0 1 1 0 +## 998: 998 0 0 0 1 0 ## 999: 999 0 0 0 1 0 ## 1000: 1000 0 0 0 1 0
     dtObs
    -
    ##         id m  u       x1         x2         x3
    -##    1:    1 0 NA 21.57022 17.8409320 19.3776659
    -##    2:    2 1 NA 22.45516 19.7657768 18.9571816
    -##    3:    3 1 NA       NA 20.0228080 20.4701953
    -##    4:    4 1 NA       NA 20.0519908 23.0250625
    -##    5:    5 1 NA       NA         NA 20.3956892
    +
    ##         id m  u         x1        x2        x3
    +##    1:    1 1 NA 18.9361265 17.885697 19.254580
    +##    2:    2 0 NA -0.3032213 -1.359335  2.313597
    +##    3:    3 1 NA         NA 39.748202 39.829287
    +##    4:    4 1 NA         NA 18.835516 19.857468
    +##    5:    5 1 NA         NA        NA 41.212529
     ##   ---                                         
    -##  996:  996 1 NA 20.32037 20.3843003 17.9600725
    -##  997:  997 0 NA       NA -0.6202465  0.3317878
    -##  998:  998 1 NA 21.19199         NA 16.6785657
    -##  999:  999 1 NA 19.82385 19.6601089 22.0630420
    -## 1000: 1000 1 NA 38.92186 42.9372445 37.4961738
    +## 996: 996 0 NA 21.2893997 19.816068 21.048983 +## 997: 997 0 NA NA 19.105992 NA +## 998: 998 0 NA 1.2360994 -2.947338 1.037609 +## 999: 999 0 NA 17.3002879 21.239352 18.597798 +## 1000: 1000 1 NA 40.5050171 40.186471 39.383540

    The impacts of the various data mechanisms on estimation can be seen with a simple calculation of means using both the “true” data set without missing data as a comparison for the “observed” data set. Since @@ -223,9 +226,9 @@

    Missing Data

    showDif(meanAct, meanObs)
    ##              x1   x2   x3
    -## Actual     20.6 20.5 20.5
    -## Observed   20.5 19.1 18.9
    -## Difference  0.1  1.4  1.6
    +## Actual 20.5 20.4 20.5 +## Observed 20.4 18.9 18.9 +## Difference 0.1 1.5 1.6

    After adjusting for the measured covariate m, the bias for the estimate of the mean of x2 is mitigated, but not for x3, since u is not observed:

    @@ -237,17 +240,17 @@

    Missing Data

    showDif(meanActm[m == 0, .(x1, x2, x3)], meanObsm[m == 0, .(x1, x2, x3)])
    ##              x1   x2   x3
    -## Actual     10.3 10.2 10.2
    -## Observed   10.2 10.4  8.6
    -## Difference  0.1 -0.2  1.6
    +## Actual 10.2 10.2 10.2 +## Observed 10.3 10.1 9.0 +## Difference -0.1 0.1 1.2
     # compare observed and actual when m = 1
     
     showDif(meanActm[m == 1, .(x1, x2, x3)], meanObsm[m == 1, .(x1, x2, x3)])
    ##              x1   x2   x3
    -## Actual     30.6 30.4 30.6
    -## Observed   30.7 30.5 29.0
    -## Difference -0.1 -0.1  1.6
    +## Actual 30.6 30.4 30.7 +## Observed 30.3 30.7 29.0 +## Difference 0.3 -0.3 1.7

    Longitudinal data with missingness

    diff --git a/dev/articles/ordinal.html b/dev/articles/ordinal.html index 00074653..66e961c2 100644 --- a/dev/articles/ordinal.html +++ b/dev/articles/ordinal.html @@ -65,6 +65,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/articles/simstudy.html b/dev/articles/simstudy.html index 605f7757..42fc52c3 100644 --- a/dev/articles/simstudy.html +++ b/dev/articles/simstudy.html @@ -65,6 +65,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/articles/spline.html b/dev/articles/spline.html index 10e056e2..0d826a7f 100644 --- a/dev/articles/spline.html +++ b/dev/articles/spline.html @@ -65,6 +65,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/articles/survival.html b/dev/articles/survival.html index 7b5be45a..7f8b3fe8 100644 --- a/dev/articles/survival.html +++ b/dev/articles/survival.html @@ -65,6 +65,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/articles/treat_and_exposure.html b/dev/articles/treat_and_exposure.html index f561154d..d0ae3912 100644 --- a/dev/articles/treat_and_exposure.html +++ b/dev/articles/treat_and_exposure.html @@ -65,6 +65,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • @@ -152,17 +155,17 @@

    Assigned treatmentstudy1

    ##      cid male over65  baseDBP rxGrp
    -##   1:   1    0      0 66.72311     1
    -##   2:   2    0      0 70.24825     3
    -##   3:   3    0      0 64.82704     3
    -##   4:   4    1      0 54.48131     1
    -##   5:   5    1      0 81.27965     3
    +##   1:   1    1      0 65.68068     1
    +##   2:   2    0      0 73.27155     2
    +##   3:   3    0      0 76.77130     2
    +##   4:   4    1      0 72.58889     3
    +##   5:   5    0      0 69.46232     2
     ##  ---                               
    -## 326: 326    1      1 69.74081     2
    -## 327: 327    1      0 84.62739     3
    -## 328: 328    1      0 72.14023     3
    -## 329: 329    1      0 72.85896     3
    -## 330: 330    1      0 70.80602     3
    +## 326: 326 1 0 75.90014 1 +## 327: 327 0 0 73.85968 3 +## 328: 328 0 0 70.80436 2 +## 329: 329 0 0 53.63268 1 +## 330: 330 0 0 65.40682 3

    Balanced treatment assignment (without stratification)

     study2 <- trtAssign(dtstudy, n = 3, balanced = TRUE, grpName = "rxGrp")
    @@ -194,30 +197,30 @@

    Assigned tre dtstudy <- genData(330, def) dtstudy
    ##      cid male over65 rx        y
    -##   1:   1    0      1  0 31.62968
    -##   2:   2    1      1  1 39.46643
    -##   3:   3    1      0  0 31.54437
    -##   4:   4    0      0  1 38.13068
    -##   5:   5    0      0  1 22.90007
    +##   1:   1    1      0  0 26.27656
    +##   2:   2    1      1  1 40.39218
    +##   3:   3    1      0  0 23.84090
    +##   4:   4    1      1  0 34.63347
    +##   5:   5    0      0  0 20.67332
     ##  ---                            
    -## 326: 326    1      0  1 32.72379
    -## 327: 327    1      0  1 29.96777
    -## 328: 328    0      0  0 11.67538
    -## 329: 329    1      0  1 30.46859
    -## 330: 330    0      0  1 32.55906
    +## 326: 326 0 0 1 40.02070 +## 327: 327 1 1 0 42.10206 +## 328: 328 1 1 0 42.69091 +## 329: 329 0 0 1 19.85681 +## 330: 330 1 0 1 29.69225

    Here are the counts and average outcomes for each gender, age, and treatment combination:

     dtstudy[, .(n = .N, avg = round(mean(y), 1)), keyby = .(male, over65, rx)]
    ##    male over65 rx  n  avg
    -## 1:    0      0  0 69 19.9
    -## 2:    0      0  1 69 29.5
    -## 3:    0      1  0 12 30.8
    -## 4:    0      1  1 12 38.4
    -## 5:    1      0  0 59 24.8
    -## 6:    1      0  1 59 36.0
    -## 7:    1      1  0 25 34.9
    -## 8:    1      1  1 25 45.1
    +## 1: 0 0 0 72 18.3 +## 2: 0 0 1 71 30.6 +## 3: 0 1 0 15 32.9 +## 4: 0 1 1 16 41.8 +## 5: 1 0 0 56 25.1 +## 6: 1 0 1 56 35.5 +## 7: 1 1 0 22 33.4 +## 8: 1 1 1 22 45.8

    Observed treatment diff --git a/dev/articles/treat_and_exposure_files/figure-html/unnamed-chunk-10-1.png b/dev/articles/treat_and_exposure_files/figure-html/unnamed-chunk-10-1.png index f1b76d1d..f49d176f 100644 Binary files a/dev/articles/treat_and_exposure_files/figure-html/unnamed-chunk-10-1.png and b/dev/articles/treat_and_exposure_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/dev/articles/treat_and_exposure_files/figure-html/unnamed-chunk-12-1.png b/dev/articles/treat_and_exposure_files/figure-html/unnamed-chunk-12-1.png index 134a809e..a4480538 100644 Binary files a/dev/articles/treat_and_exposure_files/figure-html/unnamed-chunk-12-1.png and b/dev/articles/treat_and_exposure_files/figure-html/unnamed-chunk-12-1.png differ diff --git a/dev/articles/treat_and_exposure_files/figure-html/unnamed-chunk-6-1.png b/dev/articles/treat_and_exposure_files/figure-html/unnamed-chunk-6-1.png index 6e11b0b8..19ab8874 100644 Binary files a/dev/articles/treat_and_exposure_files/figure-html/unnamed-chunk-6-1.png and b/dev/articles/treat_and_exposure_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/dev/authors.html b/dev/authors.html index 3b1242c4..018e335c 100644 --- a/dev/authors.html +++ b/dev/authors.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/index.html b/dev/index.html index eae92815..5f5add18 100644 --- a/dev/index.html +++ b/dev/index.html @@ -65,6 +65,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/news/index.html b/dev/news/index.html index b4ca431e..31096a7a 100644 --- a/dev/news/index.html +++ b/dev/news/index.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • @@ -89,6 +92,14 @@

    Changelog

    +
    +

    New features

    +
    • Function logisticCoefs determines the intercept and treatmen/exposure parameter for a data generating process (based on a logistic regression model) that has a specific target population prevalence of a binary outcome, and an option to target a risk ratio, risk difference, or AUC.
    • +
    +
    +

    Major fix

    +
    • Data generation speed has been improved for very large data sets with many variables.
    • +
    diff --git a/dev/pkgdown.yml b/dev/pkgdown.yml index 07d26222..c7333ed4 100644 --- a/dev/pkgdown.yml +++ b/dev/pkgdown.yml @@ -6,6 +6,7 @@ articles: corelationmat: corelationmat.html correlated: correlated.html double_dot_extension: double_dot_extension.html + logisticCoefs: logisticCoefs.html longitudinal: longitudinal.html missing: missing.html ordinal: ordinal.html @@ -13,5 +14,5 @@ articles: spline: spline.html survival: survival.html treat_and_exposure: treat_and_exposure.html -last_built: 2023-06-06T16:29Z +last_built: 2023-06-16T14:47Z diff --git a/dev/reference/addColumns.html b/dev/reference/addColumns.html index 2dead909..038b8b3d 100644 --- a/dev/reference/addColumns.html +++ b/dev/reference/addColumns.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • @@ -139,16 +142,16 @@

    Examples

    dt <- addColumns(def2, dt) dt #> idnum xNr xUni y1 y2 -#> 1: 1 7 19.77519 12.127445 0 -#> 2: 2 7 10.25355 9.585016 0 -#> 3: 3 7 11.50730 9.902337 1 -#> 4: 4 7 16.11763 8.013333 1 -#> 5: 5 7 13.24324 11.138120 0 -#> 6: 6 7 14.17467 9.050218 0 -#> 7: 7 7 14.22460 11.077808 0 -#> 8: 8 7 15.68954 8.934533 1 -#> 9: 9 7 16.98865 10.114972 1 -#> 10: 10 7 16.56864 8.763078 1 +#> 1: 1 7 19.86661 9.809267 0 +#> 2: 2 7 11.49860 12.245914 0 +#> 3: 3 7 15.70662 11.937422 0 +#> 4: 4 7 12.06378 8.553814 0 +#> 5: 5 7 16.76965 10.411291 1 +#> 6: 6 7 11.07966 10.508007 1 +#> 7: 7 7 13.74720 9.993135 1 +#> 8: 8 7 12.50105 10.577383 0 +#> 9: 9 7 15.85960 11.470825 0 +#> 10: 10 7 16.67648 9.133191 0
    diff --git a/dev/reference/addCompRisk.html b/dev/reference/addCompRisk.html index 7a8363ec..fd58fe08 100644 --- a/dev/reference/addCompRisk.html +++ b/dev/reference/addCompRisk.html @@ -1,5 +1,5 @@ -Generating single competing risk survival varible — addCompRisk • simstudyGenerating single competing risk survival variable — addCompRisk • simstudy @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • @@ -83,13 +86,13 @@
    -

    Generating single competing risk survival varible

    +

    Generating single competing risk survival variable

    @@ -170,17 +173,17 @@

    Examples

    addCompRisk(dd, c("reinc","death", "censor"), timeName = "time", censorName = "censor", keepEvents = FALSE) -#> id x1 x2 time event type -#> 1: 1 1 1 11.059 1 death -#> 2: 2 0 0 13.400 0 reinc -#> 3: 3 0 0 5.789 1 death -#> 4: 4 1 1 24.062 0 reinc -#> 5: 5 0 1 12.414 1 death -#> 6: 6 1 1 25.269 1 death -#> 7: 7 1 0 20.788 1 death -#> 8: 8 0 1 16.256 1 death -#> 9: 9 0 1 12.555 1 death -#> 10: 10 0 1 17.968 0 reinc +#> id x1 x2 time event type +#> 1: 1 1 0 21.091 1 reinc +#> 2: 2 1 1 7.145 1 reinc +#> 3: 3 0 0 20.549 2 death +#> 4: 4 1 0 20.919 1 reinc +#> 5: 5 1 1 17.112 2 death +#> 6: 6 1 0 20.722 2 death +#> 7: 7 1 1 4.044 2 death +#> 8: 8 1 1 7.642 0 censor +#> 9: 9 0 0 13.386 0 censor +#> 10: 10 1 1 4.955 2 death
    diff --git a/dev/reference/addCondition-1.png b/dev/reference/addCondition-1.png index bd5c9275..523daa7e 100644 Binary files a/dev/reference/addCondition-1.png and b/dev/reference/addCondition-1.png differ diff --git a/dev/reference/addCondition.html b/dev/reference/addCondition.html index 2109fba4..127f6ef1 100644 --- a/dev/reference/addCondition.html +++ b/dev/reference/addCondition.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/addCorData.html b/dev/reference/addCorData.html index fc7b8d7e..7e503e75 100644 --- a/dev/reference/addCorData.html +++ b/dev/reference/addCorData.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • @@ -176,29 +179,29 @@

    Examples

    rho = .7, corstr = "cs" ) dtAdd -#> myID xUni xNorm V1 V2 V3 -#> 1: 1 16.76895 32.59501 4.085658 8.711057 17.90749 -#> 2: 2 19.49947 34.61665 2.283458 8.946570 13.02386 -#> 3: 3 19.04379 32.85605 1.612831 3.229573 11.47516 -#> 4: 4 18.92928 35.31883 2.522701 6.802303 12.02146 -#> 5: 5 18.55993 39.02851 1.909222 7.228421 14.03043 -#> --- -#> 246: 246 12.28024 23.35406 3.108757 8.160088 16.30125 -#> 247: 247 11.72010 24.93940 3.681857 6.551933 15.35067 -#> 248: 248 18.40408 33.99754 1.990739 8.636358 13.71233 -#> 249: 249 11.96329 25.42146 4.247991 9.144226 14.46889 -#> 250: 250 15.21991 29.86339 4.115358 9.214027 17.52878 +#> myID xUni xNorm V1 V2 V3 +#> 1: 1 17.95661 32.54301 3.313414 7.212918 15.01587 +#> 2: 2 12.00886 23.92937 3.882947 8.471799 14.35276 +#> 3: 3 14.04347 28.34766 2.432766 8.396424 12.44341 +#> 4: 4 14.77774 29.28248 1.945070 7.403755 13.94964 +#> 5: 5 13.52062 26.88314 3.607590 6.923766 15.87514 +#> --- +#> 246: 246 15.93900 32.47159 3.015867 8.673155 13.65394 +#> 247: 247 14.69141 30.34699 3.856043 10.518124 16.29388 +#> 248: 248 17.56281 29.77698 4.279660 11.374829 17.30741 +#> 249: 249 14.37553 27.77826 2.823699 6.358117 12.11985 +#> 250: 250 11.95165 28.71428 5.216236 9.706980 21.01525 round(var(dtAdd[, .(V1, V2, V3)]), 3) #> V1 V2 V3 -#> V1 0.955 1.227 2.096 -#> V2 1.227 3.623 3.885 -#> V3 2.096 3.885 8.888 +#> V1 0.921 1.123 1.914 +#> V2 1.123 3.463 3.592 +#> V3 1.914 3.592 8.482 round(cor(dtAdd[, .(V1, V2, V3)]), 2) #> V1 V2 V3 -#> V1 1.00 0.66 0.72 -#> V2 0.66 1.00 0.68 -#> V3 0.72 0.68 1.00 +#> V1 1.00 0.63 0.68 +#> V2 0.63 1.00 0.66 +#> V3 0.68 0.66 1.00 dtAdd <- addCorData(dt, "myID", mu = mu, sigma = sigma, @@ -206,9 +209,9 @@

    Examples

    ) round(cor(dtAdd[, .(V1, V2, V3)]), 2) #> V1 V2 V3 -#> V1 1.00 0.70 0.47 -#> V2 0.70 1.00 0.68 -#> V3 0.47 0.68 1.00 +#> V1 1.00 0.68 0.47 +#> V2 0.68 1.00 0.69 +#> V3 0.47 0.69 1.00 corMat <- matrix(c(1, .2, .8, .2, 1, .6, .8, .6, 1), nrow = 3) @@ -218,9 +221,9 @@

    Examples

    ) round(cor(dtAdd[, .(V1, V2, V3)]), 2) #> V1 V2 V3 -#> V1 1.00 0.13 0.80 -#> V2 0.13 1.00 0.54 -#> V3 0.80 0.54 1.00 +#> V1 1.00 0.17 0.79 +#> V2 0.17 1.00 0.58 +#> V3 0.79 0.58 1.00
    diff --git a/dev/reference/addCorFlex.html b/dev/reference/addCorFlex.html index b56ded84..b2ff7f40 100644 --- a/dev/reference/addCorFlex.html +++ b/dev/reference/addCorFlex.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • @@ -195,63 +198,63 @@

    Examples

    print(cor(di[idClust == i, list(A, B, C, D)])) } #> A B C D -#> A 1.0000000 0.3406562 0.2495626 0.2554243 -#> B 0.3406562 1.0000000 0.3398297 0.4784836 -#> C 0.2495626 0.3398297 1.0000000 0.3167690 -#> D 0.2554243 0.4784836 0.3167690 1.0000000 -#> A B C D -#> A 1.00000000 0.2485535 0.3780640 0.05100379 -#> B 0.24855346 1.0000000 0.3311455 0.22076053 -#> C 0.37806401 0.3311455 1.0000000 0.26893525 -#> D 0.05100379 0.2207605 0.2689352 1.00000000 -#> A B C D -#> A 1.0000000 0.3835578 0.3884835 0.3927248 -#> B 0.3835578 1.0000000 0.4349660 0.5778788 -#> C 0.3884835 0.4349660 1.0000000 0.4943901 -#> D 0.3927248 0.5778788 0.4943901 1.0000000 +#> A 1.0000000 0.4286875 0.3297979 0.2347647 +#> B 0.4286875 1.0000000 0.2004366 0.3897232 +#> C 0.3297979 0.2004366 1.0000000 0.2569380 +#> D 0.2347647 0.3897232 0.2569380 1.0000000 +#> A B C D +#> A 1.000000000 0.2469078 0.4215374 0.008593497 +#> B 0.246907764 1.0000000 0.6061375 0.435897490 +#> C 0.421537408 0.6061375 1.0000000 0.414279116 +#> D 0.008593497 0.4358975 0.4142791 1.000000000 #> A B C D -#> A 1.0000000 0.2971884 0.4203225 0.5474606 -#> B 0.2971884 1.0000000 0.3336864 0.2578099 -#> C 0.4203225 0.3336864 1.0000000 0.4372210 -#> D 0.5474606 0.2578099 0.4372210 1.0000000 +#> A 1.0000000 0.5197699 0.3874457 0.4339078 +#> B 0.5197699 1.0000000 0.5296502 0.4542076 +#> C 0.3874457 0.5296502 1.0000000 0.5224635 +#> D 0.4339078 0.4542076 0.5224635 1.0000000 #> A B C D -#> A 1.0000000 0.2356170 0.4640510 0.5503669 -#> B 0.2356170 1.0000000 0.4896065 0.4483039 -#> C 0.4640510 0.4896065 1.0000000 0.5575444 -#> D 0.5503669 0.4483039 0.5575444 1.0000000 +#> A 1.0000000 0.4333561 0.6089613 0.4664374 +#> B 0.4333561 1.0000000 0.4916776 0.5531181 +#> C 0.6089613 0.4916776 1.0000000 0.3630633 +#> D 0.4664374 0.5531181 0.3630633 1.0000000 #> A B C D -#> A 1.0000000 0.3750797 0.4733852 0.3695352 -#> B 0.3750797 1.0000000 0.3815429 0.4148739 -#> C 0.4733852 0.3815429 1.0000000 0.4355969 -#> D 0.3695352 0.4148739 0.4355969 1.0000000 +#> A 1.0000000 0.4389587 0.3305654 0.3407185 +#> B 0.4389587 1.0000000 0.1882755 0.3591182 +#> C 0.3305654 0.1882755 1.0000000 0.5175346 +#> D 0.3407185 0.3591182 0.5175346 1.0000000 +#> A B C D +#> A 1.00000000 -0.02356498 0.2878693 0.3795695 +#> B -0.02356498 1.00000000 0.2002829 0.2880845 +#> C 0.28786926 0.20028289 1.0000000 0.1596746 +#> D 0.37956948 0.28808447 0.1596746 1.0000000 #> A B C D -#> A 1.0000000 0.2672245 0.3068318 0.4097004 -#> B 0.2672245 1.0000000 0.1792928 0.5399817 -#> C 0.3068318 0.1792928 1.0000000 0.3704618 -#> D 0.4097004 0.5399817 0.3704618 1.0000000 +#> A 1.0000000 0.3245598 0.4249850 0.4635660 +#> B 0.3245598 1.0000000 0.4420268 0.3517828 +#> C 0.4249850 0.4420268 1.0000000 0.4934050 +#> D 0.4635660 0.3517828 0.4934050 1.0000000 #> A B C D -#> A 1.0000000 0.3981507 0.4721447 0.4164991 -#> B 0.3981507 1.0000000 0.4990947 0.4643299 -#> C 0.4721447 0.4990947 1.0000000 0.4055073 -#> D 0.4164991 0.4643299 0.4055073 1.0000000 +#> A 1.0000000 0.5406002 0.1722469 0.3500954 +#> B 0.5406002 1.0000000 0.4066897 0.3756615 +#> C 0.1722469 0.4066897 1.0000000 0.2934906 +#> D 0.3500954 0.3756615 0.2934906 1.0000000 #> A B C D -#> A 1.0000000 0.5660632 0.5780797 0.2497885 -#> B 0.5660632 1.0000000 0.4944815 0.4466131 -#> C 0.5780797 0.4944815 1.0000000 0.2114349 -#> D 0.2497885 0.4466131 0.2114349 1.0000000 +#> A 1.0000000 0.2209653 0.4439960 0.4594370 +#> B 0.2209653 1.0000000 0.3999685 0.3989203 +#> C 0.4439960 0.3999685 1.0000000 0.3344698 +#> D 0.4594370 0.3989203 0.3344698 1.0000000 #> A B C D -#> A 1.0000000 0.3140088 0.3248843 0.4577602 -#> B 0.3140088 1.0000000 0.2616308 0.3146415 -#> C 0.3248843 0.2616308 1.0000000 0.1257582 -#> D 0.4577602 0.3146415 0.1257582 1.0000000 +#> A 1.0000000 0.3149325 0.4666405 0.3883964 +#> B 0.3149325 1.0000000 0.2010666 0.3356168 +#> C 0.4666405 0.2010666 1.0000000 0.5085276 +#> D 0.3883964 0.3356168 0.5085276 1.0000000 # Check global correlations - should not be as correlated cor(di[, list(A, B, C, D)]) -#> A B C D -#> A 1.00000000 0.05756453 -0.07253847 0.3187693 -#> B 0.05756453 1.00000000 0.10629546 0.4970023 -#> C -0.07253847 0.10629546 1.00000000 0.0437867 -#> D 0.31876935 0.49700229 0.04378670 1.0000000 +#> A B C D +#> A 1.00000000 -0.04198754 0.2574572 0.4056920 +#> B -0.04198754 1.00000000 0.3198121 -0.2539433 +#> C 0.25745718 0.31981207 1.0000000 0.5076336 +#> D 0.40569198 -0.25394326 0.5076336 1.0000000 diff --git a/dev/reference/addCorGen.html b/dev/reference/addCorGen.html index b2eb67a4..effcde08 100644 --- a/dev/reference/addCorGen.html +++ b/dev/reference/addCorGen.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • @@ -204,108 +207,108 @@

    Examples

    dtOld = dt, idvar = "cid", nvars = 3, rho = .7, corstr = "cs", dist = "poisson", param1 = "lambda" ) -#> cid xbase lambda V1 V2 V3 -#> 1: 1 3.4094338 2.318553 2 3 4 -#> 2: 2 4.3205701 2.539728 4 4 4 -#> 3: 3 1.5115581 1.917756 1 3 4 -#> 4: 4 3.3610479 2.307362 3 2 3 -#> 5: 5 4.3143978 2.538161 3 3 2 -#> 6: 6 9.5840047 4.299078 6 5 5 -#> 7: 7 5.4586679 2.845864 3 5 4 -#> 8: 8 0.8735171 1.799217 0 1 0 -#> 9: 9 3.6513524 2.375327 4 3 4 -#> 10: 10 4.4338858 2.568671 1 1 1 -#> 11: 11 2.8321725 2.188502 0 3 1 -#> 12: 12 2.0704586 2.027991 1 1 2 -#> 13: 13 5.4199592 2.834870 2 3 5 -#> 14: 14 2.5085289 2.118806 1 3 2 -#> 15: 15 5.3271270 2.808675 4 5 3 -#> 16: 16 9.3886520 4.215909 4 6 4 -#> 17: 17 5.8162043 2.949455 4 5 4 -#> 18: 18 3.8117082 2.413724 1 0 0 -#> 19: 19 4.4753317 2.579339 2 1 3 -#> 20: 20 9.7653371 4.377745 5 3 4 -#> 21: 21 1.0583979 1.832791 3 4 3 -#> 22: 22 14.2134379 6.830131 9 7 7 -#> 23: 23 4.8661637 2.682144 6 6 4 -#> 24: 24 9.6228939 4.315829 5 5 8 -#> 25: 25 1.1853512 1.856207 1 0 0 -#> 26: 26 2.8891579 2.201009 5 4 5 -#> 27: 27 4.6121543 2.614873 2 4 2 -#> 28: 28 2.4641674 2.109428 1 1 1 -#> 29: 29 1.3611947 1.889136 2 1 1 -#> 30: 30 0.3610781 1.709341 2 2 3 -#> 31: 31 5.0892229 2.742644 1 2 1 -#> 32: 32 2.7761360 2.176273 4 3 3 -#> 33: 33 1.2756937 1.873052 1 0 0 -#> 34: 34 1.0834498 1.837388 2 1 0 -#> 35: 35 2.6209688 2.142765 4 3 3 -#> 36: 36 0.9234207 1.808218 1 1 0 -#> 37: 37 3.1722282 2.264203 0 0 1 -#> 38: 38 11.3312510 5.119850 7 8 7 -#> 39: 39 4.7175394 2.642575 2 4 2 -#> 40: 40 1.6187080 1.938415 0 0 2 -#> 41: 41 1.3986995 1.896234 2 1 1 -#> 42: 42 9.6774368 4.339433 0 0 0 -#> 43: 43 6.8831493 3.281547 7 3 3 -#> 44: 44 4.9060027 2.692850 7 6 6 -#> 45: 45 5.6907223 2.912676 5 5 5 -#> 46: 46 0.7885944 1.784003 0 0 0 -#> 47: 47 2.2880766 2.072608 2 1 1 -#> 48: 48 9.0446404 4.073343 2 2 3 -#> 49: 49 5.7377532 2.926407 2 2 3 -#> 50: 50 1.6000527 1.934803 2 2 2 -#> 51: 51 4.5675434 2.603234 2 4 4 -#> 52: 52 4.5902866 2.609161 2 1 1 -#> 53: 53 2.7012180 2.160029 5 7 4 -#> 54: 54 4.8222140 2.670382 3 3 4 -#> 55: 55 2.8847482 2.200038 4 2 5 -#> 56: 56 4.7863225 2.660814 2 2 1 -#> 57: 57 1.8060185 1.975066 1 3 1 -#> 58: 58 2.6095997 2.140330 3 2 3 -#> 59: 59 2.4707688 2.110821 5 6 3 -#> 60: 60 1.5330876 1.921889 3 4 1 -#> 61: 61 5.2935561 2.799261 5 4 4 -#> 62: 62 8.4051509 3.821011 3 4 2 -#> 63: 63 1.3597355 1.888860 1 1 1 -#> 64: 64 1.7225548 1.958650 2 1 1 -#> 65: 65 4.8931382 2.689388 1 2 2 -#> 66: 66 4.0627835 2.475094 3 1 1 -#> 67: 67 2.8022831 2.181970 2 2 4 -#> 68: 68 7.8142636 3.601773 3 3 4 -#> 69: 69 1.7765191 1.969248 2 3 4 -#> 70: 70 2.4438905 2.105155 0 1 1 -#> 71: 71 1.1230543 1.844679 2 3 1 -#> 72: 72 7.5323149 3.501640 6 3 3 -#> 73: 73 7.2219261 3.394623 3 1 3 -#> 74: 74 7.0877792 3.349389 1 3 1 -#> 75: 75 9.8732858 4.425258 7 4 5 -#> 76: 76 7.0358355 3.332036 2 4 3 -#> 77: 77 8.3124283 3.785745 3 5 4 -#> 78: 78 6.1794470 3.058561 1 2 4 -#> 79: 79 3.0947057 2.246718 1 1 1 -#> 80: 80 6.4046239 3.128214 3 2 2 -#> 81: 81 6.0149109 3.008649 3 3 2 -#> 82: 82 1.6337468 1.941333 7 2 4 -#> 83: 83 5.2561957 2.788823 2 2 3 -#> 84: 84 2.1189323 2.037846 1 1 2 -#> 85: 85 0.5597910 1.743647 3 4 3 -#> 86: 86 2.0641053 2.026703 1 1 2 -#> 87: 87 6.8990315 3.286763 1 2 2 -#> 88: 88 3.5857042 2.359785 0 2 1 -#> 89: 89 5.9644946 2.993519 2 2 3 -#> 90: 90 8.8304086 3.987007 4 4 2 -#> 91: 91 4.1456056 2.495678 2 3 3 -#> 92: 92 5.8402484 2.956555 3 6 3 -#> 93: 93 4.0341027 2.468005 4 5 5 -#> 94: 94 6.0262396 3.012059 1 2 1 -#> 95: 95 6.4167423 3.132008 5 5 4 -#> 96: 96 6.1817612 3.059269 3 1 2 -#> 97: 97 3.9864354 2.456269 6 4 6 -#> 98: 98 3.7262284 2.393180 2 1 1 -#> 99: 99 10.7648633 4.837927 4 7 2 -#> 100: 100 8.2873786 3.776274 5 5 5 -#> cid xbase lambda V1 V2 V3 +#> cid xbase lambda V1 V2 V3 +#> 1: 1 4.011436 2.462417 1 2 5 +#> 2: 2 8.428646 3.829999 3 3 4 +#> 3: 3 2.489232 2.114722 3 4 4 +#> 4: 4 8.572591 3.885529 2 2 1 +#> 5: 5 8.324969 3.790496 3 2 3 +#> 6: 6 1.171242 1.853590 2 2 3 +#> 7: 7 2.080005 2.029928 1 1 2 +#> 8: 8 4.706431 2.639642 0 1 0 +#> 9: 9 8.450644 3.838434 4 4 4 +#> 10: 10 4.283009 2.530207 1 2 1 +#> 11: 11 8.368432 3.807007 4 2 4 +#> 12: 12 3.366053 2.308517 2 1 3 +#> 13: 13 11.157589 5.031705 4 5 6 +#> 14: 14 4.305168 2.535819 2 1 3 +#> 15: 15 3.585776 2.359802 3 3 3 +#> 16: 16 2.388765 2.093582 0 0 0 +#> 17: 17 7.350617 3.438591 2 2 1 +#> 18: 18 5.046456 2.730939 2 2 4 +#> 19: 19 2.822952 2.186485 5 5 3 +#> 20: 20 5.655354 2.902393 2 2 2 +#> 21: 21 11.535734 5.225620 7 6 7 +#> 22: 22 5.077100 2.739321 2 4 2 +#> 23: 23 2.316007 2.078405 2 3 2 +#> 24: 24 3.075632 2.242437 2 2 3 +#> 25: 25 6.387841 3.122969 2 3 2 +#> 26: 26 13.274401 6.217949 7 9 10 +#> 27: 27 3.807493 2.412707 4 2 3 +#> 28: 28 4.923015 2.697435 5 2 4 +#> 29: 29 3.328250 2.299807 2 2 3 +#> 30: 30 5.837247 2.955668 3 3 2 +#> 31: 31 7.055706 3.338664 2 2 1 +#> 32: 32 1.566527 1.928327 3 6 5 +#> 33: 33 4.017819 2.463990 5 6 3 +#> 34: 34 1.515077 1.918431 2 0 1 +#> 35: 35 1.874329 1.988604 1 1 0 +#> 36: 36 3.111651 2.250529 0 2 3 +#> 37: 37 5.198627 2.772814 3 2 4 +#> 38: 38 2.375636 2.090835 2 4 3 +#> 39: 39 3.722932 2.392391 2 2 1 +#> 40: 40 3.977413 2.454054 1 2 2 +#> 41: 41 4.686227 2.634314 1 0 2 +#> 42: 42 3.205793 2.271816 3 1 1 +#> 43: 43 2.642529 2.147389 1 1 1 +#> 44: 44 3.437511 2.325072 2 3 4 +#> 45: 45 2.841980 2.190649 3 3 4 +#> 46: 46 6.481946 3.152496 3 3 4 +#> 47: 47 4.150008 2.496777 4 4 4 +#> 48: 48 11.225877 5.066183 7 5 7 +#> 49: 49 3.590104 2.360823 2 1 2 +#> 50: 50 3.042534 2.235027 2 2 3 +#> 51: 51 3.294647 2.292091 2 2 3 +#> 52: 52 1.624699 1.939577 3 2 4 +#> 53: 53 2.348286 2.085124 4 3 3 +#> 54: 54 4.954290 2.705885 2 4 3 +#> 55: 55 5.538630 2.868711 1 0 1 +#> 56: 56 5.606321 2.888196 0 0 1 +#> 57: 57 2.605689 2.139493 1 0 1 +#> 58: 58 4.346589 2.546345 1 3 2 +#> 59: 59 3.350912 2.305024 5 4 3 +#> 60: 60 1.168177 1.853022 2 0 1 +#> 61: 61 4.275685 2.528354 3 4 3 +#> 62: 62 4.281689 2.529873 5 5 3 +#> 63: 63 5.090669 2.743040 5 5 6 +#> 64: 64 8.076270 3.697389 6 5 4 +#> 65: 65 5.832956 2.954400 3 1 1 +#> 66: 66 3.672025 2.380243 4 5 5 +#> 67: 67 7.694308 3.558826 3 2 3 +#> 68: 68 2.560804 2.129911 0 0 0 +#> 69: 69 4.983781 2.713877 7 5 4 +#> 70: 70 4.802971 2.665248 2 2 2 +#> 71: 71 2.006444 2.015051 1 1 0 +#> 72: 72 5.902628 2.975056 9 8 7 +#> 73: 73 8.086293 3.701097 6 7 5 +#> 74: 74 5.557074 2.874007 3 3 3 +#> 75: 75 2.205741 2.055613 1 2 1 +#> 76: 76 9.564178 4.290562 6 3 6 +#> 77: 77 4.626451 2.618614 2 1 2 +#> 78: 78 1.940035 2.001713 2 2 1 +#> 79: 79 4.956950 2.706605 2 1 3 +#> 80: 80 11.007787 4.956891 8 5 5 +#> 81: 81 4.430759 2.567868 2 1 1 +#> 82: 82 3.076396 2.242608 4 3 3 +#> 83: 83 5.882472 2.969065 2 2 1 +#> 84: 84 6.660641 3.209336 3 3 3 +#> 85: 85 3.602634 2.363783 2 3 2 +#> 86: 86 6.671896 3.212950 6 7 7 +#> 87: 87 5.289981 2.798261 0 0 1 +#> 88: 88 7.783629 3.590756 2 2 1 +#> 89: 89 2.756380 2.171977 2 3 4 +#> 90: 90 9.232222 4.150473 3 4 2 +#> 91: 91 6.294883 3.094073 2 2 3 +#> 92: 92 1.910178 1.995746 4 3 4 +#> 93: 93 1.371105 1.891009 2 1 2 +#> 94: 94 2.690735 2.157766 2 0 1 +#> 95: 95 10.543166 4.731851 1 1 3 +#> 96: 96 9.742460 4.367741 2 1 2 +#> 97: 97 3.119730 2.252347 2 2 5 +#> 98: 98 4.327010 2.541364 5 4 4 +#> 99: 99 10.393026 4.661338 5 4 6 +#> 100: 100 7.789054 3.592705 4 2 2 +#> cid xbase lambda V1 V2 V3 # Long example diff --git a/dev/reference/addMarkov.html b/dev/reference/addMarkov.html index 11f552cf..d78eceea 100644 --- a/dev/reference/addMarkov.html +++ b/dev/reference/addMarkov.html @@ -47,6 +47,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/addMultiFac.html b/dev/reference/addMultiFac.html index a664a278..2962f7d3 100644 --- a/dev/reference/addMultiFac.html +++ b/dev/reference/addMultiFac.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • @@ -139,18 +142,18 @@

    Examples

    DT <- genData(360, defD) DT <- addMultiFac(DT, nFactors = 3, levels = c(2, 3, 3), colNames = c("A", "B", "C")) DT -#> id x A B C -#> 1: 1 -0.31215079 1 2 3 -#> 2: 2 -0.21354424 1 3 3 -#> 3: 3 1.04041592 2 1 2 -#> 4: 4 -0.46483693 1 3 3 -#> 5: 5 0.17092930 2 1 2 -#> --- -#> 356: 356 -0.06047427 2 1 2 -#> 357: 357 -0.91227685 1 1 1 -#> 358: 358 -0.38668095 1 1 3 -#> 359: 359 0.91642033 2 2 3 -#> 360: 360 1.13539478 1 3 1 +#> id x A B C +#> 1: 1 0.7463632 2 2 1 +#> 2: 2 -1.4032972 1 1 2 +#> 3: 3 -0.4359190 2 3 2 +#> 4: 4 -1.2726915 1 2 2 +#> 5: 5 0.2410753 1 1 3 +#> --- +#> 356: 356 -1.8271667 1 2 1 +#> 357: 357 -0.4022704 2 3 2 +#> 358: 358 -0.4346730 1 3 3 +#> 359: 359 -1.0089664 2 1 3 +#> 360: 360 0.7636342 2 1 2 DT[, .N, keyby = .(A, B, C)] #> A B C N #> 1: 1 1 1 20 @@ -177,13 +180,13 @@

    Examples

    DT[, .N, keyby = .(Var1, Var2, Var3)] #> Var1 Var2 Var3 N #> 1: 0 0 0 37 -#> 2: 0 0 1 37 -#> 3: 0 1 0 38 +#> 2: 0 0 1 38 +#> 3: 0 1 0 37 #> 4: 0 1 1 38 -#> 5: 1 0 0 37 +#> 5: 1 0 0 38 #> 6: 1 0 1 37 #> 7: 1 1 0 38 -#> 8: 1 1 1 38 +#> 8: 1 1 1 37 diff --git a/dev/reference/addPeriods.html b/dev/reference/addPeriods.html index 3f387c3c..5dc840ac 100644 --- a/dev/reference/addPeriods.html +++ b/dev/reference/addPeriods.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • @@ -153,11 +156,11 @@

    Examples

    dtTrial <- genData(5, tdef) dtTrial #> id T Y0 Y1 Y2 -#> 1: 1 0 10.602532 16.01595 20.26540 -#> 2: 2 0 8.761621 12.84098 17.36761 -#> 3: 3 1 10.632761 21.20437 24.29927 -#> 4: 4 1 9.760414 20.53569 25.07561 -#> 5: 5 1 10.539279 19.68567 25.80316 +#> 1: 1 1 10.099804 19.95882 25.30015 +#> 2: 2 1 9.114251 20.01162 22.55616 +#> 3: 3 0 11.080168 16.07542 18.82528 +#> 4: 4 0 7.941049 11.65252 17.73128 +#> 5: 5 0 10.360406 13.25476 22.03741 dtTime <- addPeriods(dtTrial, nPeriods = 3, idvars = "id", @@ -165,21 +168,21 @@

    Examples

    ) dtTime #> id period T Y timeID -#> 1: 1 0 0 10.602532 1 -#> 2: 1 1 0 16.015946 2 -#> 3: 1 2 0 20.265401 3 -#> 4: 2 0 0 8.761621 4 -#> 5: 2 1 0 12.840982 5 -#> 6: 2 2 0 17.367610 6 -#> 7: 3 0 1 10.632761 7 -#> 8: 3 1 1 21.204366 8 -#> 9: 3 2 1 24.299274 9 -#> 10: 4 0 1 9.760414 10 -#> 11: 4 1 1 20.535685 11 -#> 12: 4 2 1 25.075607 12 -#> 13: 5 0 1 10.539279 13 -#> 14: 5 1 1 19.685672 14 -#> 15: 5 2 1 25.803162 15 +#> 1: 1 0 1 10.099804 1 +#> 2: 1 1 1 19.958817 2 +#> 3: 1 2 1 25.300149 3 +#> 4: 2 0 1 9.114251 4 +#> 5: 2 1 1 20.011619 5 +#> 6: 2 2 1 22.556164 6 +#> 7: 3 0 0 11.080168 7 +#> 8: 3 1 0 16.075421 8 +#> 9: 3 2 0 18.825278 9 +#> 10: 4 0 0 7.941049 10 +#> 11: 4 1 0 11.652521 11 +#> 12: 4 2 0 17.731278 12 +#> 13: 5 0 0 10.360406 13 +#> 14: 5 1 0 13.254757 14 +#> 15: 5 2 0 22.037411 15 # Varying # of periods and intervals - need to have variables # called nCount and mInterval @@ -192,22 +195,26 @@

    Examples

    dt <- genData(200, def) dt[id %in% c(8, 121)] #> id xbase nCount mInterval vInterval -#> 1: 8 21.07535 6 34.37963 0.07 -#> 2: 121 19.22680 4 29.45772 0.07 +#> 1: 8 21.36395 4 28.78482 0.07 +#> 2: 121 18.48159 10 30.47625 0.07 dtPeriod <- addPeriods(dt) dtPeriod[id %in% c(8, 121)] # View individuals 8 and 121 only #> id period xbase time timeID -#> 1: 8 0 21.07535 0 48 -#> 2: 8 1 21.07535 36 49 -#> 3: 8 2 21.07535 71 50 -#> 4: 8 3 21.07535 100 51 -#> 5: 8 4 21.07535 128 52 -#> 6: 8 5 21.07535 162 53 -#> 7: 121 0 19.22680 0 747 -#> 8: 121 1 19.22680 27 748 -#> 9: 121 2 19.22680 58 749 -#> 10: 121 3 19.22680 81 750 +#> 1: 8 0 21.36395 0 44 +#> 2: 8 1 21.36395 24 45 +#> 3: 8 2 21.36395 48 46 +#> 4: 8 3 21.36395 73 47 +#> 5: 121 0 18.48159 0 748 +#> 6: 121 1 18.48159 23 749 +#> 7: 121 2 18.48159 55 750 +#> 8: 121 3 18.48159 101 751 +#> 9: 121 4 18.48159 124 752 +#> 10: 121 5 18.48159 157 753 +#> 11: 121 6 18.48159 187 754 +#> 12: 121 7 18.48159 210 755 +#> 13: 121 8 18.48159 233 756 +#> 14: 121 9 18.48159 255 757 diff --git a/dev/reference/addSynthetic.html b/dev/reference/addSynthetic.html index 2b968c1a..f6461a42 100644 --- a/dev/reference/addSynthetic.html +++ b/dev/reference/addSynthetic.html @@ -47,6 +47,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/betaGetShapes.html b/dev/reference/betaGetShapes.html index 7f93f4ce..0aebf82a 100644 --- a/dev/reference/betaGetShapes.html +++ b/dev/reference/betaGetShapes.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/blockDecayMat.html b/dev/reference/blockDecayMat.html index 7762fba3..0b9c2036 100644 --- a/dev/reference/blockDecayMat.html +++ b/dev/reference/blockDecayMat.html @@ -50,6 +50,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/blockExchangeMat.html b/dev/reference/blockExchangeMat.html index 6a37135e..5f9bb7f4 100644 --- a/dev/reference/blockExchangeMat.html +++ b/dev/reference/blockExchangeMat.html @@ -50,6 +50,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/catProbs.html b/dev/reference/catProbs.html index 90184c32..a26ab14f 100644 --- a/dev/reference/catProbs.html +++ b/dev/reference/catProbs.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/defCondition.html b/dev/reference/defCondition.html index eea6e419..5b4f06f4 100644 --- a/dev/reference/defCondition.html +++ b/dev/reference/defCondition.html @@ -47,6 +47,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/defData.html b/dev/reference/defData.html index da7bce1c..341fbc5b 100644 --- a/dev/reference/defData.html +++ b/dev/reference/defData.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/defDataAdd.html b/dev/reference/defDataAdd.html index 61242d90..429664ca 100644 --- a/dev/reference/defDataAdd.html +++ b/dev/reference/defDataAdd.html @@ -47,6 +47,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/defMiss.html b/dev/reference/defMiss.html index c0ebc3d0..976ddd10 100644 --- a/dev/reference/defMiss.html +++ b/dev/reference/defMiss.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/defRead.html b/dev/reference/defRead.html index a5a21f4c..d4b3b2f9 100644 --- a/dev/reference/defRead.html +++ b/dev/reference/defRead.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/defReadAdd.html b/dev/reference/defReadAdd.html index 682075a8..e67c6aea 100644 --- a/dev/reference/defReadAdd.html +++ b/dev/reference/defReadAdd.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/defReadCond.html b/dev/reference/defReadCond.html index aedb7c6d..398cb1f6 100644 --- a/dev/reference/defReadCond.html +++ b/dev/reference/defReadCond.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/defRepeat.html b/dev/reference/defRepeat.html index 84a881c4..0bfa4145 100644 --- a/dev/reference/defRepeat.html +++ b/dev/reference/defRepeat.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/defRepeatAdd.html b/dev/reference/defRepeatAdd.html index 121e81e3..23a96bd2 100644 --- a/dev/reference/defRepeatAdd.html +++ b/dev/reference/defRepeatAdd.html @@ -47,6 +47,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/defSurv.html b/dev/reference/defSurv.html index 33cd9b01..ff2184eb 100644 --- a/dev/reference/defSurv.html +++ b/dev/reference/defSurv.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/delColumns.html b/dev/reference/delColumns.html index 980c80bc..bf98eecf 100644 --- a/dev/reference/delColumns.html +++ b/dev/reference/delColumns.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/distributions.html b/dev/reference/distributions.html index db454fe7..105c0910 100644 --- a/dev/reference/distributions.html +++ b/dev/reference/distributions.html @@ -47,6 +47,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/gammaGetShapeRate.html b/dev/reference/gammaGetShapeRate.html index 958c87a5..3f13a30c 100644 --- a/dev/reference/gammaGetShapeRate.html +++ b/dev/reference/gammaGetShapeRate.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genCatFormula.html b/dev/reference/genCatFormula.html index 75a03edf..ef3288ce 100644 --- a/dev/reference/genCatFormula.html +++ b/dev/reference/genCatFormula.html @@ -47,6 +47,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genCluster.html b/dev/reference/genCluster.html index 61d48dc4..6e396d77 100644 --- a/dev/reference/genCluster.html +++ b/dev/reference/genCluster.html @@ -48,6 +48,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genCorData.html b/dev/reference/genCorData.html index 48d44324..ce134545 100644 --- a/dev/reference/genCorData.html +++ b/dev/reference/genCorData.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genCorFlex.html b/dev/reference/genCorFlex.html index 7e87bd65..e3057e9f 100644 --- a/dev/reference/genCorFlex.html +++ b/dev/reference/genCorFlex.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genCorGen.html b/dev/reference/genCorGen.html index 5c8cefb1..6979ed36 100644 --- a/dev/reference/genCorGen.html +++ b/dev/reference/genCorGen.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genCorMat.html b/dev/reference/genCorMat.html index 802a59c0..a55ff4c2 100644 --- a/dev/reference/genCorMat.html +++ b/dev/reference/genCorMat.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genCorOrdCat.html b/dev/reference/genCorOrdCat.html index 982281d5..572608aa 100644 --- a/dev/reference/genCorOrdCat.html +++ b/dev/reference/genCorOrdCat.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genData.html b/dev/reference/genData.html index 223ce95a..4d206446 100644 --- a/dev/reference/genData.html +++ b/dev/reference/genData.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genDummy.html b/dev/reference/genDummy.html index c1abbf97..d7f9dc78 100644 --- a/dev/reference/genDummy.html +++ b/dev/reference/genDummy.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genFactor.html b/dev/reference/genFactor.html index 39804390..e33d93c7 100644 --- a/dev/reference/genFactor.html +++ b/dev/reference/genFactor.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genFormula.html b/dev/reference/genFormula.html index 76cacb8a..2a1d2c89 100644 --- a/dev/reference/genFormula.html +++ b/dev/reference/genFormula.html @@ -47,6 +47,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genMarkov.html b/dev/reference/genMarkov.html index 44665baa..cedd34af 100644 --- a/dev/reference/genMarkov.html +++ b/dev/reference/genMarkov.html @@ -47,6 +47,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genMiss.html b/dev/reference/genMiss.html index 913ab95c..444dc4a4 100644 --- a/dev/reference/genMiss.html +++ b/dev/reference/genMiss.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genMixFormula.html b/dev/reference/genMixFormula.html index b095bc42..6ec0d5d3 100644 --- a/dev/reference/genMixFormula.html +++ b/dev/reference/genMixFormula.html @@ -47,6 +47,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genMultiFac.html b/dev/reference/genMultiFac.html index 9506d6d3..e26f407b 100644 --- a/dev/reference/genMultiFac.html +++ b/dev/reference/genMultiFac.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genNthEvent.html b/dev/reference/genNthEvent.html index d8d64c6d..5cdb6206 100644 --- a/dev/reference/genNthEvent.html +++ b/dev/reference/genNthEvent.html @@ -47,6 +47,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genObs.html b/dev/reference/genObs.html index 293914e2..61e75e09 100644 --- a/dev/reference/genObs.html +++ b/dev/reference/genObs.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genOrdCat.html b/dev/reference/genOrdCat.html index be806f05..0e23a4bd 100644 --- a/dev/reference/genOrdCat.html +++ b/dev/reference/genOrdCat.html @@ -47,6 +47,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genSpline.html b/dev/reference/genSpline.html index 45488b09..0414f312 100644 --- a/dev/reference/genSpline.html +++ b/dev/reference/genSpline.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genSurv.html b/dev/reference/genSurv.html index f99ef37b..9b8de4a2 100644 --- a/dev/reference/genSurv.html +++ b/dev/reference/genSurv.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/genSynthetic.html b/dev/reference/genSynthetic.html index 1d9d23dd..224aa004 100644 --- a/dev/reference/genSynthetic.html +++ b/dev/reference/genSynthetic.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/iccRE.html b/dev/reference/iccRE.html index cdeffaba..87d6e8eb 100644 --- a/dev/reference/iccRE.html +++ b/dev/reference/iccRE.html @@ -47,6 +47,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/index.html b/dev/reference/index.html index b20484ca..c4a4d70b 100644 --- a/dev/reference/index.html +++ b/dev/reference/index.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • @@ -313,7 +316,7 @@

    Utility

    addCompRisk()

    -

    Generating single competing risk survival varible

    +

    Generating single competing risk survival variable

    betaGetShapes()

    @@ -338,6 +341,10 @@

    Utility iccRE()

    Generate variance for random effects that produce desired intra-class coefficients (ICCs) for clustered data.

    + +

    logisticCoefs()

    + +

    Determine intercept, treatment/exposure and covariate coefficients that can be used for binary data generation with a logit link and a set of covariates

    mergeData()

    diff --git a/dev/reference/logisticCoefs.html b/dev/reference/logisticCoefs.html new file mode 100644 index 00000000..f92d197a --- /dev/null +++ b/dev/reference/logisticCoefs.html @@ -0,0 +1,228 @@ + +Determine intercept, treatment/exposure and covariate coefficients that can be used for binary data generation with a logit link and a set of covariates — logisticCoefs • simstudy + + +
    +
    + + + +
    +
    + + +
    +

    This is an implementation of an iterative bisection procedure +that can be used to determine coefficient values for a target population +prevalence as well as a target risk ratio, risk difference, or AUC. These +coefficients can be used in a subsequent data generation process to simulate +data with these desire characteristics.

    +
    + +
    +
    logisticCoefs(
    +  defCovar,
    +  coefs,
    +  popPrev,
    +  rr = NULL,
    +  rd = NULL,
    +  auc = NULL,
    +  tolerance = 0.001,
    +  sampleSize = 5e+05,
    +  trtName = "A"
    +)
    +
    + +
    +

    Arguments

    +
    defCovar
    +

    A definition table for the covariates in the underlying +population. This tables specifies the distribution of the covariates.

    + + +
    coefs
    +

    A vector of coefficients that reflect the relationship between +each of the covariates and the log-odds of the outcome.

    + + +
    popPrev
    +

    The target population prevalence of the outcome. +A value between 0 and 1.

    + + +
    rr
    +

    The target risk ratio, which must be a value between 0 and +1/popPrev. Defaults to NULL.

    + + +
    rd
    +

    The target risk difference, which must be between +-(popPrev) and (1 - popPrev). Defaults to NULL

    + + +
    auc
    +

    The target AUC, which must be a value between 0.5 and 1.0 . +Defaults to NULL.

    + + +
    tolerance
    +

    The minimum stopping distance between the adjusted low and high +endpoints. Defaults to 0.001.

    + + +
    sampleSize
    +

    The number of units to generate for the bisection algorithm. +The default is 5e+05. To get a reliable estimate, the value +should be no smaller than 1e+05.

    + + +
    trtName
    +

    If either a risk ratio or risk difference is the target statistic, +a treatment/exposure variable name can be provided. Defaults to "A".

    + +
    +
    +

    Value

    + + +

    A vector of parameters including the intercept and covariate +coefficients for the logistic model data generating process.

    +
    +
    +

    Details

    +

    If no specific target statistic is specified, then only the intercept +is returned along with the original coefficients. Only one target statistic (risk ratio, risk +difference or AUC) can be specified with a single function call; in all three cases, a target +prevalence is still required.

    +
    +
    +

    References

    +

    Austin, Peter C. "The iterative bisection procedure: a useful +tool for determining parameter values in data-generating processes in +Monte Carlo simulations." BMC Medical Research Methodology 23, +no. 1 (2023): 1-10.

    +
    + +
    +

    Examples

    +
    if (FALSE) {
    +d1 <- defData(varname = "x1", formula = 0, variance = 1)
    +d1 <- defData(d1, varname = "b1", formula = 0.5, dist = "binary")
    +
    +coefs <- log(c(1.2, 0.8))
    +
    +logisticCoefs(d1, coefs, popPrev = 0.20) 
    +logisticCoefs(d1, coefs, popPrev = 0.20, rr = 1.50, trtName = "rx") 
    +logisticCoefs(d1, coefs, popPrev = 0.20, rd = 0.30, trtName = "rx")
    +logisticCoefs(d1, coefs, popPrev = 0.20, auc = 0.80)
    +}
    +
    +
    +
    + +
    + + +
    + + + + + + + + diff --git a/dev/reference/mergeData.html b/dev/reference/mergeData.html index 2541badf..af5dfb59 100644 --- a/dev/reference/mergeData.html +++ b/dev/reference/mergeData.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/negbinomGetSizeProb.html b/dev/reference/negbinomGetSizeProb.html index 7f9e0630..c9f4e4da 100644 --- a/dev/reference/negbinomGetSizeProb.html +++ b/dev/reference/negbinomGetSizeProb.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/simstudy-deprecated.html b/dev/reference/simstudy-deprecated.html index 3705c547..69188b9a 100644 --- a/dev/reference/simstudy-deprecated.html +++ b/dev/reference/simstudy-deprecated.html @@ -47,6 +47,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/simstudy-package.html b/dev/reference/simstudy-package.html index ebcaa127..088dfbdf 100644 --- a/dev/reference/simstudy-package.html +++ b/dev/reference/simstudy-package.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/survGetParams.html b/dev/reference/survGetParams.html index 67576f4d..9d34f5f3 100644 --- a/dev/reference/survGetParams.html +++ b/dev/reference/survGetParams.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/survParamPlot.html b/dev/reference/survParamPlot.html index c1f14dbd..c68ae7a3 100644 --- a/dev/reference/survParamPlot.html +++ b/dev/reference/survParamPlot.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/trimData.html b/dev/reference/trimData.html index 38d6002c..183171d9 100644 --- a/dev/reference/trimData.html +++ b/dev/reference/trimData.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/trtAssign.html b/dev/reference/trtAssign.html index cbd64dce..8322f633 100644 --- a/dev/reference/trtAssign.html +++ b/dev/reference/trtAssign.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/trtObserve.html b/dev/reference/trtObserve.html index 89707b1b..92a576d8 100644 --- a/dev/reference/trtObserve.html +++ b/dev/reference/trtObserve.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/trtStepWedge.html b/dev/reference/trtStepWedge.html index 73f6d178..1c2e6f80 100644 --- a/dev/reference/trtStepWedge.html +++ b/dev/reference/trtStepWedge.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/updateDef.html b/dev/reference/updateDef.html index 02756e5e..1e6a1563 100644 --- a/dev/reference/updateDef.html +++ b/dev/reference/updateDef.html @@ -48,6 +48,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/updateDefAdd.html b/dev/reference/updateDefAdd.html index 4f3b8681..0cfd6b9e 100644 --- a/dev/reference/updateDefAdd.html +++ b/dev/reference/updateDefAdd.html @@ -48,6 +48,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/viewBasis.html b/dev/reference/viewBasis.html index 10dccf42..968ad9b5 100644 --- a/dev/reference/viewBasis.html +++ b/dev/reference/viewBasis.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/reference/viewSplines.html b/dev/reference/viewSplines.html index 8bdafa93..984da2cc 100644 --- a/dev/reference/viewSplines.html +++ b/dev/reference/viewSplines.html @@ -46,6 +46,9 @@
  • Dynamic Data Definition
  • +
  • + Simulating data from logistic model with specified characterstics +
  • Longitudinal Data
  • diff --git a/dev/sitemap.xml b/dev/sitemap.xml index 6ba5e2ce..dfe82de0 100644 --- a/dev/sitemap.xml +++ b/dev/sitemap.xml @@ -27,6 +27,9 @@ /articles/index.html + + /articles/logisticCoefs.html + /articles/longitudinal.html @@ -207,6 +210,9 @@ /reference/index.html + + /reference/logisticCoefs.html + /reference/mergeData.html