getGRvalues: Gelman-Rubin (GR) Statistics

View source: R/haodong_functions.R

getGRvaluesR Documentation

Gelman–Rubin (GR) Statistics

Description

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

Usage

getGRvalues(X = X, Zstratum = Zstratum, NC = 2, tl = 1.02)

Arguments

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

Value

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

Author(s)

Haodong Tian for underlying code, Amy Mason for conversion to R function haodong.tian@mrc-bsu.cam.ac.uk

Examples

 #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  )
#--------------------------------------------------------------------------------------

amymariemason/SUMnlmr documentation built on July 22, 2024, 10:03 a.m.