fixed2Zcor.RdConstruct zcor vector (of fixed correlations) from a fixed working correlation matrix, a specification of clusters and a specifcation of waves.
fixed2Zcor(cor.fixed, id, waves)A vector which can be passed as the zcor argument to geeglm.
timeorder <- rep(1:5, 6)
tvar <- timeorder + rnorm(length(timeorder))
idvar <- rep(1:6, each=5)
uuu <- rep(rnorm(6), each=5)
yvar <- 1 + 2*tvar + uuu + rnorm(length(tvar))
simdat <- data.frame(idvar, timeorder, tvar, yvar)
head(simdat,12)
#> idvar timeorder tvar yvar
#> 1 1 1 1.334497 3.020713
#> 2 1 2 1.170648 3.655398
#> 3 1 3 2.781304 4.436412
#> 4 1 4 2.454916 3.719308
#> 5 1 5 5.233230 11.779785
#> 6 2 1 1.031070 4.263892
#> 7 2 2 2.357866 5.327582
#> 8 2 3 4.608624 11.551966
#> 9 2 4 5.429854 13.232432
#> 10 2 5 4.051660 8.179241
#> 11 3 1 2.015706 4.878890
#> 12 3 2 2.037735 5.099036
simdatPerm <- simdat[sample(nrow(simdat)),]
simdatPerm <- simdatPerm[order(simdatPerm$idvar),]
head(simdatPerm)
#> idvar timeorder tvar yvar
#> 5 1 5 5.233230 11.779785
#> 2 1 2 1.170648 3.655398
#> 1 1 1 1.334497 3.020713
#> 4 1 4 2.454916 3.719308
#> 3 1 3 2.781304 4.436412
#> 10 2 5 4.051660 8.179241
cor.fixed <- matrix(c(1 , 0.5 , 0.25, 0.125, 0.125,
0.5 , 1 , 0.25, 0.125, 0.125,
0.25 , 0.25 , 1 , 0.5 , 0.125,
0.125, 0.125, 0.5 , 1 , 0.125,
0.125, 0.125, 0.125, 0.125, 1 ), nrow=5, ncol=5)
cor.fixed
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1.000 0.500 0.250 0.125 0.125
#> [2,] 0.500 1.000 0.250 0.125 0.125
#> [3,] 0.250 0.250 1.000 0.500 0.125
#> [4,] 0.125 0.125 0.500 1.000 0.125
#> [5,] 0.125 0.125 0.125 0.125 1.000
zcor <- fixed2Zcor(cor.fixed, id=simdatPerm$idvar, waves=simdatPerm$timeorder)
zcor
#> [1] 0.125 0.125 0.125 0.125 0.500 0.125 0.250 0.125 0.250 0.500 0.125 0.125
#> [13] 0.125 0.125 0.500 0.250 0.125 0.250 0.125 0.500 0.125 0.125 0.125 0.500
#> [25] 0.125 0.500 0.250 0.125 0.125 0.250 0.125 0.125 0.250 0.500 0.125 0.500
#> [37] 0.125 0.125 0.125 0.250 0.250 0.250 0.125 0.500 0.500 0.125 0.125 0.125
#> [49] 0.125 0.125 0.125 0.125 0.500 0.250 0.125 0.125 0.125 0.125 0.500 0.250
mod4 <- geeglm(yvar~tvar, id=idvar, data=simdatPerm, corstr="fixed", zcor=zcor)
mod4
#>
#> Call:
#> geeglm(formula = yvar ~ tvar, data = simdatPerm, id = idvar,
#> zcor = zcor, corstr = "fixed")
#>
#> Coefficients:
#> (Intercept) tvar
#> 1.048262 1.969850
#>
#> Degrees of Freedom: 30 Total (i.e. Null); 28 Residual
#>
#> Scale Link: identity
#> Estimated Scale Parameters: [1] 1.523422
#>
#> Correlation: Structure = fixed Link = identity
#> Estimated Correlation Parameters:
#> alpha:1
#> 1
#>
#> Number of clusters: 6 Maximum cluster size: 5
#>