View source: R/haodong_functions.R
getGRvalues | R Documentation |
getGRvalues calculates the the Gelman–Rubin (GR) statistics for each strata (i.e. LACE-strata) as described in Haodong's paper on doubly-ranked methods in Text S1
getGRvalues(X = X, Zstratum = Zstratum, NC = 2, tl = 1.02)
X |
vector of coarsened exposures |
Zstratum |
vector of pre-strata index column |
NC |
number of chains - a lower NC is encouraged |
tl |
threshold level, should be >1 |
max_GR is the maximum G-R statistic accross all strata
statified_strata is a list of the strata where the GR-statistic meets the threshold limit
GR_values is a table of the a and b values for each strata
Haodong Tian for underlying code, Amy Mason for conversion to R function haodong.tian@mrc-bsu.cam.ac.uk
#Toy data example------------------------------------------------------------------
N<-10000 #N is the total ssample size
Z<-rnorm( N,0,0.5 ) # instrument
U1<-rnorm(N,0,1)
U2<-rnorm(N,0,1) #U2 is confounder
h_X<-function(Z){ 0.5*Z }
X<-h_X(Z)+U2+U1
fitX<-lm( X~Z )
RR<-as.numeric(summary(fitX)$r.squared[1])
No<-1000 #No is the number of pre-strata (i.e. IV-strata)
X_<-X # true exact X
X<-round(X) #coarsened by round
dat<-cbind( Z, X, X_) # X: coarsened exposure; X_: exact exposure
dat_order<-dat[ order(dat[,1] ), ] #ordered by Z
dat_order<-cbind( dat_order , sort(rep( 1:No, N/No )))
dat_order<-as.data.frame( dat_order )
names(dat_order)<-c( 'Z_order', 'X','X_' ,'ZStratum')
getGRvalues( X=dat_order$X, Zstratum = dat_order$ZStratum, NC=2, tl = 1.02 )
#--------------------------------------------------------------------------------------
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.