Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

different calipers for different subproblems #197

Open
jwbowers opened this issue Feb 4, 2021 · 3 comments
Open

different calipers for different subproblems #197

jwbowers opened this issue Feb 4, 2021 · 3 comments
Labels

Comments

@jwbowers
Copy link
Collaborator

jwbowers commented Feb 4, 2021

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?

@benthestatistician
Copy link
Collaborator

benthestatistician commented Feb 4, 2021

  • 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 Ease/provide guidance on stitching together subclass-specific distances #65. Thoughts?

@jwbowers
Copy link
Collaborator Author

jwbowers commented Feb 5, 2021

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
Copy link
Collaborator Author

jwbowers commented Feb 5, 2021

Leaving this open just in case it is useful.

@benthestatistician benthestatistician changed the title User-style help: different calipers for different subproblems. different calipers for different subproblems Feb 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants