# R/adap.R In yags: Yet Another GEE Solver

```adap = function (struc, varmod = "f", corstr = "exch")
{
rr = lapply(struc, sapply, allcrit)
rownames(rr[]) = paste("n", rownames(rr[]), sep = ".")
rownames(rr[]) = paste("f", rownames(rr[]), sep = ".")
arr = rbind(rr[], rr[])
L = arr[c(1:3, 13:15), ]
D1 = arr[c(4:6, 16:18), ]
P = arr[c(4:6, 16:18) + 3, ]
D2 = arr[c(4:6, 16:18) + 6, ]
LPICKS = rownames(L)[apply(L, 2, which.max)]
D1PICKS = rownames(D1)[apply(D1, 2, which.min)]
D2PICKS = rownames(D2)[apply(D2, 2, which.min)]
PPICKS = rownames(P)[apply(P, 2, which.min)]
allco = function (x) sapply(x, function(x) c(ex = coef(x\$exchange), ar1 = coef(x\$ar1),
ind = coef(x\$indep)))
plist = list(L = LPICKS, D1 = D1PICKS, D2 = D2PICKS, P = PPICKS,
CON = allco(struc\$naive), COF = allco(struc\$oracle))
ainds = sapply(plist[1:4], function(x) grep("ar1", x))
einds = sapply(plist[1:4], function(x) grep("exch", x))
iinds = sapply(plist[1:4], function(x) grep("ind", x))
useN = lapply(plist[1:4], function(x) grep("^n",x))  # sapply -> lapply Mar 30 2011
useF = sapply(plist[1:4], function(x) grep("^f",x))
ncoef = ncol(plist\$CON)
# if run on all cormods gives a full vector of chosen coeffs
pullco = function( adaco, crittype = "L", cormod="ar1" ) {
if (cormod == "ar1") vindset = ainds
else if (cormod == "ex") vindset = einds
else if (cormod == "ind") vindset = iinds
if (length(vindset[[crittype]]) > 0) {
doN = intersect(vindset[[crittype]], useN[[crittype]])
if (length(doN > 0))
adaco[ doN ] = plist\$CON[cormod, doN ]
doF = intersect(vindset[[crittype]], useF[[crittype]])
if (length(doF > 0))
adaco[ doF  ] = plist\$COF[cormod, doF ]
}
}