1 | summarise.glm(lstModels, outfunc = exp, writetab = TRUE, file = "modsum.csv", sigdigits = 3, transpose = FALSE)
|
lstModels |
|
outfunc |
|
writetab |
|
file |
|
sigdigits |
|
transpose |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (lstModels, outfunc = exp, writetab = TRUE, file = "modsum.csv",
sigdigits = 3, transpose = FALSE)
{
nomods <- length(lstModels)
allCoeffs <- c()
for (i in 1:nomods) {
mod <- lstModels[[i]]
vars <- names(mod$coefficients)
novars <- length(vars)
for (j in 1:novars) {
curname <- vars[j]
var_present <- (curname %in% allCoeffs)
if (!(var_present))
allCoeffs <- c(allCoeffs, curname)
}
}
noCoeffs <- length(allCoeffs)
matPointEst <- matrix(NA, nrow = nomods, ncol = noCoeffs,
dimnames = list(1:nomods, allCoeffs))
matLB <- matrix(NA, nrow = nomods, ncol = noCoeffs, dimnames = list(1:nomods,
allCoeffs))
matUB <- matrix(NA, nrow = nomods, ncol = noCoeffs, dimnames = list(1:nomods,
allCoeffs))
vecAIC <- vector(mode = "numeric", length = nomods)
vecDEX <- vector(mode = "numeric", length = nomods)
for (i in 1:nomods) {
mod <- lstModels[[i]]
cis <- confint.default(mod)
vars <- names(mod$coefficients)
novars <- length(vars)
vecAIC[i] <- mod$aic
vecDEX[i] <- (1 - mod$deviance/mod$null.deviance) * 100
for (j in 1:novars) {
curname <- vars[j]
matPointEst[i, curname] <- mod$coefficients[curname]
matLB[i, curname] <- cis[curname, 1]
matUB[i, curname] <- cis[curname, 2]
}
}
if (writetab) {
if (transpose) {
strTable <- ""
strTable <- paste(strTable, "Parameter", sep = "")
for (i in 1:noCoeffs) strTable <- paste(strTable,
",", allCoeffs[i], ",", allCoeffs[i], sep = "")
strTable <- paste(strTable, ",AIC,DEX\n", sep = "")
strTable <- paste(strTable, "Model", sep = "")
for (i in 1:noCoeffs) strTable <- paste(strTable,
",PE,CI", sep = "")
strTable <- paste(strTable, ",AIC,DEX\n", sep = "")
for (i in 1:nomods) {
strTable <- paste(strTable, i, sep = "")
for (j in 1:noCoeffs) {
curname <- allCoeffs[j]
curPE <- signif(outfunc(matPointEst[i, curname]),
digits = sigdigits)
curLB <- signif(outfunc(matLB[i, curname]),
digits = sigdigits)
curUB <- signif(outfunc(matUB[i, curname]),
digits = sigdigits)
if (is.na(curPE)) {
strTable <- paste(strTable, ",", "-", ",",
"-", sep = "")
}
else {
strTable <- paste(strTable, ",", curPE, ",",
"(", curLB, "--", curUB, ")", sep = "")
}
}
mod <- lstModels[[i]]
curAIC <- round(mod$aic, digits = 1)
curDEX <- round((1 - mod$deviance/mod$null.deviance) *
100, digits = 1)
strTable <- paste(strTable, ",", curAIC, ",",
curDEX, "\n", sep = "")
}
}
else {
strTable <- ""
strTable <- paste(strTable, ",Model 1", sep = "")
if (nomods > 1)
for (i in 2:nomods) strTable <- paste(strTable,
",,Model ", i, sep = "")
strTable <- paste(strTable, "\n", sep = "")
if (nomods > 1)
for (i in 1:nomods) {
strTable <- paste(strTable, ",Estimate,(95% CI)",
sep = "")
}
strTable <- paste(strTable, "\n", sep = "")
for (i in 1:noCoeffs) {
curname <- allCoeffs[i]
strTable <- paste(strTable, curname, sep = "")
for (j in 1:nomods) {
curPE <- signif(outfunc(matPointEst[j, curname]),
digits = sigdigits)
curLB <- signif(outfunc(matLB[j, curname]),
digits = sigdigits)
curUB <- signif(outfunc(matUB[j, curname]),
digits = sigdigits)
if (is.na(curPE)) {
strTable <- paste(strTable, ",", "-", ",",
"-", sep = "")
}
else {
strTable <- paste(strTable, ",", curPE, ",",
"(", curLB, "--", curUB, ")", sep = "")
}
}
strTable <- paste(strTable, "\n", sep = "")
}
strTable <- paste(strTable, "AIC", sep = "")
for (i in 1:nomods) {
mod <- lstModels[[i]]
curAIC <- round(mod$aic, digits = 1)
strTable <- paste(strTable, ",", curAIC, ",",
sep = "")
}
strTable <- paste(strTable, "\n", sep = "")
strTable <- paste(strTable, "DEX", sep = "")
for (i in 1:nomods) {
mod <- lstModels[[i]]
curDEX <- round((1 - mod$deviance/mod$null.deviance) *
100, digits = 1)
strTable <- paste(strTable, ",", curDEX, ",",
sep = "")
}
strTable <- paste(strTable, "\n", sep = "")
}
cat(strTable, file = file)
}
data.frame(pe = matPointEst, lb = matLB, ub = matUB, aic = vecAIC,
dex = vecDEX)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.