| 1 |
## The following two functions are contributed by |
| 2 |
## Dave Atkins, PhD |
| 3 |
## Research Associate Professor |
| 4 |
## Center for the Study of Health and Risk Behaviors |
| 5 |
## Department of Psychiatry and Behavioral Science |
| 6 |
## Unversity of Washington |
| 7 |
|
| 8 |
getSummary_expcoef <- function(obj, alpha = 0.05, ...) UseMethod("getSummary_expcoef") |
| 9 |
|
| 10 |
### This function is no longer exported, because there is a more general |
| 11 |
### default method available now. |
| 12 |
getSummary_expcoef.glm <- function (obj, alpha = 0.05, ...) |
| 13 |
{ |
| 14 |
smry <- summary(obj) |
| 15 |
N <- if(length(weights(obj))) |
| 16 |
sum(weights(obj),na.rm=TRUE) |
| 17 |
else sum(smry$df[1:2]) |
| 18 |
|
| 19 |
coef <- cbind(exp(smry$coef[,1]), smry$coef[,2:4,drop=FALSE]) |
| 20 |
# NOTE: exponentiated coefficients |
| 21 |
|
| 22 |
lower <- exp(qnorm(p = alpha/2, mean = smry$coef[, 1], sd = coef[,2])) |
| 23 |
upper <- exp(qnorm(p = 1 - alpha/2, mean = smry$coef[, 1], sd = coef[,2])) |
| 24 |
# NOTE: exponentiated CI |
| 25 |
|
| 26 |
coef <- cbind(coef, lower, upper) |
| 27 |
|
| 28 |
dn <- list( |
| 29 |
rownames(coef), |
| 30 |
c("est","se","stat","p","lwr","upr"), |
| 31 |
names(obj$model)[1] |
| 32 |
) |
| 33 |
dim(coef) <- c(dim(coef)[1],dim(coef)[2],1) |
| 34 |
dimnames(coef) <- dn |
| 35 |
|
| 36 |
phi <- smry$dispersion |
| 37 |
LR <- smry$null.deviance - smry$deviance |
| 38 |
df <- smry$df.null - smry$df.residual |
| 39 |
|
| 40 |
ll <- logLik(obj) |
| 41 |
deviance <- deviance(obj) |
| 42 |
|
| 43 |
if (df > 0) { |
| 44 |
p <- pchisq(LR, df, lower.tail = FALSE) |
| 45 |
L0.pwr <- exp(-smry$null.deviance/N) |
| 46 |
Aldrich.Nelson <- LR/(LR+N) |
| 47 |
McFadden <- 1 - smry$deviance/smry$null.deviance |
| 48 |
Cox.Snell <- 1 - exp(-LR/N) |
| 49 |
Nagelkerke <- Cox.Snell/(1 - L0.pwr) |
| 50 |
} |
| 51 |
else { |
| 52 |
LR <- NA |
| 53 |
df <- NA |
| 54 |
p <- NA |
| 55 |
Aldrich.Nelson <- NA |
| 56 |
McFadden <- NA |
| 57 |
Cox.Snell <- NA |
| 58 |
Nagelkerke <- NA |
| 59 |
} |
| 60 |
|
| 61 |
AIC <- AIC(obj) |
| 62 |
BIC <- AIC(obj,k=log(N)) |
| 63 |
sumstat <- c( |
| 64 |
phi = phi, |
| 65 |
LR = LR, |
| 66 |
df = df, |
| 67 |
p = p, |
| 68 |
logLik = ll, |
| 69 |
deviance = deviance, |
| 70 |
Aldrich.Nelson = Aldrich.Nelson, |
| 71 |
McFadden = McFadden, |
| 72 |
Cox.Snell = Cox.Snell, |
| 73 |
Nagelkerke = Nagelkerke, |
| 74 |
AIC = AIC, |
| 75 |
BIC = BIC, |
| 76 |
N = N |
| 77 |
) |
| 78 |
|
| 79 |
list(coef=coef, |
| 80 |
sumstat=sumstat, |
| 81 |
contrasts=obj$contrasts, |
| 82 |
xlevels=obj$xlevels, |
| 83 |
call=obj$call) |
| 84 |
} |