optmatch icon indicating copy to clipboard operation
optmatch copied to clipboard

different calipers for different subproblems

Open jwbowers opened this issue 4 years ago • 3 comments

Hi all,

I have a design with 12 subproblems. The best calipers differ by subproblems (we have more and easier to match people near Kano, Nigeria than in the Northeastern part of the country). My inspection of the code suggests that while arguments to fullmatch like min.controls can take names of of the subproblems but that caliper cannot.

I could apply calipers to each subproblem in the list created by findSubproblems(d) (where d arises from match_on and exactmatch), but then I have a list of matrices rather than an object I can offer to fullmatch.

Should this then be a two step process:

  1. mat_lst <- lapply(subproblemids,function(id){ d_lst[[id]] + caliper(d_lst[[id]],thecalipers[[id]]) })

  2. Assuming that the rownames of the original data are carried correctly from the data to d (by match_on) and then to the subproblems by findSubproblems:

## d is the original match_on, exactMatch object
newd <- d
newd[rownames(mat_lst[[1]]),colnames(mat_lst[[1]])] <- mat_lst[[1]]
thematch <- fullmatch(newd,...)

Is this right? Or is there another approach you have taken or envision which is more in line with how you manage vector-valued arguments to fullmatch?

jwbowers avatar Feb 04 '21 15:02 jwbowers

  • I think Jake's right that caliper() and caliper= do not recognize named subproblems.
  • I don't know that we have a solution for this problem at present, unfortunately. certainly no one intended for users to be mashing subproblems as Jake did here.
  • To me the most promising solution path is through #65. Thoughts?

benthestatistician avatar Feb 04 '21 15:02 benthestatistician

My current solution is to side step combining matrices by combining matched objects:

## A function that takes a data.frame of calipers (found via some process), lists of distance matrices, and group ids, and applies the calipers. Returns a distance matrix with calipers applied.
apply_caliper <- function(balobj,psdistlst,mhdistlst,id){
    pcal <- balobj$pscal[balobj$set==id]
    mcal <- balobj$mhcal[balobj$set==id]
    psdist <- psdistlst[[id]]
    mhdist <- mhdistlst[[id]]
    match_mat <- psdist + caliper(psdist,pcal) + caliper(mhdist,mcal)
    return(match_mat)
}

## Make a list of caliper-ed distance matrices
match_mat13_lst <- lapply(setnames, function(id) {
    apply_caliper(balobj=res13_bal,psdistlst = psDistRE13_lst,mhdistlst = mhDist13_lst,id=id)
})
names(match_mat13_lst) <- setnames

## Find matches within each group
matches13_lst <- lapply(setnames, function(id){
    message(id)
    fm <- fullmatch(match_mat13_lst[[id]],min.controls=1,max.controls=Inf,tol=.0001,
        data=droplevels(psdat13[psdat13$exactsets==id,]))
    return(fm)
})

## Combine the groups using the c.optmatch method
fm13 <- c(matches13_lst[[1]],matches13_lst[[2]])
## Check that this scales.
fm13a <- do.call("c",matches13_lst[1:2])
stopifnot(all.equal(fm13,fm13a))

jwbowers avatar Feb 05 '21 15:02 jwbowers

Leaving this open just in case it is useful.

jwbowers avatar Feb 05 '21 15:02 jwbowers