sandwich
calculates the covariance structure between timepoints given matrices yCov
, D
,V
and correctionmatrix
. This is done to be able to account for missingness in the Data.
sandwich(
yCov,
D,
V,
correctionmatrix,
missing = rep(0, dim(yCov)[[2]]),
missingtype = c("none", "monotone", "intermittened")
)
i
patiens. see 'Details'.
As of this version this matrix is needed to correct some calculations. see 'Details' to see for more details and how to correctly select matrices.
vector which denotes the probability to experience a dropout at each timepoint. If missingtype
is "none"
then all entries are 0.
String which describes the type of missingness occuring in the data. none
if no missingnes occured, "monotone"
if missing was monotone and "intermittened"
if the missingness was independent across all timepoints.
sandwich
returns the robust covariance estimator of regression coefficients which are implicitly defined by D
.
yCov
is either empirical or the estimated covariance-matrix between timepoints which is needed to calculate the sandwich estimator. This matrix can either be generated by estimating the empirical covariance matrix using existing data or by using function gen_cov_cor
to calculate a estimation for the covariance.
D
denotes the estimation of
Liang Kung-Yee, Zeger Scott L. (1986); Jung Sin-Ho, Ahn Chul (2003); Wachtlin Daniel Kieser Meinhard (2013)
# NOT RUN {
#Let's assume we wish to calculate the robust variance estimator for equation
#\eqn{y_{it}=\beta_0+\beta_1*I_{treat}+\beta_2*t+\beta_3*I _{treat}*t+\epsilon_{it}}.
#Furthermore we use the identitiy matrix as the working covariance matrix.
#The chance to get treatment is 60 percent and the observed timerange ranges from 0:5.
ycov = gen_cov_cor(var = 3,rho = 0.25,theta = 1,Time = 0:5,cov = TRUE)
D = matrix(c(1,0.6,0,0,
1,0.6,1,0.6,
1,0.6,2,1.2,
1,0.6,3,1.8,
1,0.6,4,2.4,
1,0.6,5,3.0),nrow=4)
D=t(D)
V=diag(1,length(0:5))
#We correct entries where E(D_i %*% D_i) is unequal to E(D_i)%*%E(D_i) (D %*% D).
correctionmatrix=matrix(c(1,1,1,1,1,1/0.6,1,1/0.6,1,1,1,1,1,1/0.6,1,1/0.6),nrow=4)
missingtype = "none"
robust=sandwich(yCov=ycov,D=D,V=V,missingtype=missingtype,correctionmatrix=correctionmatrix)
robust
# }
Run the code above in your browser using DataLab