| To: | s-news@lists.biostat.wustl.edu |
|---|---|
| Subject: | matched logistic regression |
| From: | "Biggerstaff, Brad J." <bkb5@cdc.gov> |
| Date: | Thu, 18 Sep 2003 13:52:14 -0400 |
| Cc: | "Biggerstaff, Brad J." <bkb5@cdc.gov> |
|
Dear S-news list
folks:
A few years ago I
posted a function, mlogitreg, that is a wrapper function to coxph for doing
matched logistic regression. In that function, the matching variable was
specified using a character string, e.g., matching.var = "M". I have
written a new version of this function, now called mlr, to use the
within-formula specification of strata/matching variable as with coxph
and other functions, just to be consistent with current S use. Here the
matching variable is specified using matching(M) in the formula, as one
specifies strata(M) in coxph. The function is, as before, just a wrapper
for coxph; it's just updated to have a more modern S flavor.
I include this
updated version (written for S-Plus 6.x) in case you might find it useful.
While the returned object has the coxph class, I changed the call element
in the return object to be the call in the mlr function. (But update
doesn't work yet.) The arguments are as with coxph.
I welcome comments,
problems.
Cheers,
Brad
"mlr"<- function(formula=formula(data),
data = "" subset, na.action, control, singular.ok = T, robust =
F, model = F, x = F, y = T, ...) { # Function to do matched logistic
regression by calling coxph # # Required
arguments # # formula: # # A formula of the form Response ~
Covariates + matching(Var), where # Covariates indicates model terms and Var
is the variable indicating # the matching. # # All other arguments as with
coxph(). # # Author: # # Brad Biggerstaff,
Ph.D. # Division of Vector-Borne
Infectious Diseases # # Centers for Disease Control
and Prevention #
# +1 970.221.6473 ---
BBiggerstaff@cdc.gov # # really just use the coxph
function strata for the matching function
if(!exists("matching"))
assign("matching",strata,frame=1) m <- match.call(expand =
F) call <-
match.call() temp <- c("", "formula", "data",
"subset", "na.action") m <- m[match(temp, names(m),
nomatch = 0)] special <-
c("matching") Terms <- if(missing(data))
terms(formula, special) else terms(formula, special, data = ""> m$formula <-
Terms m[[1]] <-
as.name("model.frame") m <- eval(m,
sys.parent()) m$PseudoTime <- rep(1,
nrow(m)) # # manipulate the formula to make it
look like a call to coxph # CharFormula <-
as.character(formula(formula)) ResponseName <-
CharFormula[2] CharFormula[2] <-
paste("Surv(PseudoTime,", ResponseName, ")", sep = "", collapse =
"") rhs <-
CharFormula[3] matching.ind <-
as.vector(regMatchPos(rhs, "matching")) substring(rhs, matching.ind[1],
matching.ind[2]) <- "strata" CharFormula[3] <-
rhs CharFormula <-
paste(CharFormula[c(2, 1, 3)], collapse = "")
if(missing(control)) control <-
coxph.control(...)
if(missing(na.action)) na.action <-
get("na.exclude") names.m <-
names(m) MatchingVarNamePos <- seq(along
= names.m)[regMatch(names.m, "matching"
)] MatchingVarName <-
names.m[MatchingVarNamePos] MatchingVarName <-
unpaste(unpaste(MatchingVarName, "(")[[2]], ")")[[
1]] names(m)[MatchingVarNamePos] <-
MatchingVarName fit <-
coxph(formula(CharFormula), data = "" = "exact", control = control,
singular.ok
= singular.ok, robust = robust, model = model, x = x, y =
y) fit$call <-
call fit } Brad Biggerstaff, Ph.D.
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Call for AAAI-04 Workshop Proposals, Tomas Singliar |
|---|---|
| Next by Date: | Re: confidence ellipses, John Fox |
| Previous by Thread: | Call for AAAI-04 Workshop Proposals, Tomas Singliar |
| Next by Thread: | Generating multivariate normal, Hendry Raharjo |
| Indexes: | [Date] [Thread] [Top] [All Lists] |