forked from amymariemason/nlmr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGen_sim_data.R
27 lines (25 loc) · 930 Bytes
/
Gen_sim_data.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
###
#Author: Amy Mason
# Purpose: generate simulatoion data from nlmr paper
# Date: Jan 2019
##
# creating random underlying data
# We want:
# g - a binary gene
# u - an unmeasure confounder
# use these to create x (the exposure e.g. BMI) and y (the outcome e.g. blood pressure)
# errorX is the error term on X
# errorY is a random error term on Y
#In line with nlmr paper take:G~Bin(2,0.3), U~Uni(0,1), Ex~Exp(1), Ey~ N(0,1)
data$u<-runif(1000,0,1)
data$errorX<-rexp(10000,1)
data$errorY<-rnorm(10000,0,1)
data$X<-2+0.25*data$g+data$u +data$errorX
beta1<-1.5
beta2<-0.5
# generate various Y with different exposure-outcome results
data$linear.Y<-beta1*data$X+0.8*data$u+data$errorY
data$quadratic.Y<-beta1*(data$X)^2+beta2*data$X+0.8*data$u+data$errorY
data$sqrt.Y<-beta1*sqrt(data$X)+0.8*data$u+data$errorY
data$log.Y<-beta1*log(data$X)+0.8*data$u+data$errorY
data$threshold.Y<-beta1*data$X+0.8*data$u+data$errorY