adjlogistic <- function(formula,data,sens,spec,eps=1e-05, ...){ # Routine to do logistic regression corrected for known sens. or spec. of # the outcome. See Madger and Hughes (1997) Am. J. Epidem, 146:195-203. # # Creator: Jim Hughes # # Inputs: # formula = usual S-plus type formula for a logistic regression # data = data frame for evaluation of the formula # sens, spec = vectors giving the sensitivity and specificity of the outcome: # length should be the same as the row dimension of data # eps = stopping criteria for the EM procedure # ... = aditional arguments to model.frame # # Outputs: # result = a glm object with coefficients and variance adjusted for sens # and spec # # Modified: 3/18/03 tdata <- model.frame(formula,data, ...) keep <- match(row.names(data),row.names(tdata),nomatch=0)>0 sens <- sens[keep] ; spec<- spec[keep] result <- glm(formula,tdata,family=binomial, ...) y <- result\$y repeat{ eb <- result\$fitted.values beta <- result\$coef EY <- ifelse(y==0,(1-sens)*eb/((1-sens)*eb+spec*(1-eb)), sens*eb/(sens*eb+(1-spec)*(1-eb))) formula <- update(formula,EY ~ .) assign("EY",EY,frame=1) result <- glm(formula, tdata, family = binomial, ...) # Put in any stopping criteria you want if (sqrt(sum((result\$coef - beta)^2)) < eps) break } z <- model.matrix(formula,data=tdata) result\$var <- solve(t(z)%*%(z*(eb*(1-eb) - EY*(1-EY)))) result\$sens <- sens result\$spec <- spec result }