| 1 |
## AER::ivreg |
| 2 |
|
| 3 |
getSummary.ivreg <- function(obj, alpha = 0.05, ...) { |
| 4 |
## extract summary object |
| 5 |
s <- summary(obj) |
| 6 |
|
| 7 |
## coefficient matrix and confidence interval |
| 8 |
cf <- cbind(s$coefficients, confint(obj, level = 1 - alpha)) |
| 9 |
colnames(cf) <- c("est", "se", "stat", "p", "lwr", "upr") |
| 10 |
|
| 11 |
# Patch ME 20.08.2017 |
| 12 |
dn <- c( |
| 13 |
dimnames(cf), |
| 14 |
names(obj$model)[1] |
| 15 |
) |
| 16 |
dim(cf) <- c(dim(cf)[1],dim(cf)[2],1) |
| 17 |
dimnames(cf) <- dn |
| 18 |
|
| 19 |
## further summary statistics |
| 20 |
sstat <- c("sigma" = s$sigma, |
| 21 |
"r.squared" = s$r.squared, "adj.r.squared" = s$adj.r.squared, |
| 22 |
"Wald" = s$waldtest[1], "numdf" = s$waldtest[3], "dendf" = s$waldtest[4], |
| 23 |
"p" = s$waldtest[2], "N" = nobs(obj)) |
| 24 |
|
| 25 |
## return everything |
| 26 |
return(list( |
| 27 |
coef = cf, |
| 28 |
sumstat = sstat, |
| 29 |
contrasts = obj$contrasts, |
| 30 |
xlevels = obj$xlevels, |
| 31 |
call = obj$call |
| 32 |
)) |
| 33 |
} |
| 34 |
|
| 35 |
setSummaryTemplate("ivreg" = c( |
| 36 |
"R-squared" = "($r.squared:f#)", |
| 37 |
"adj. R-squared" = "($adj.r.squared:f#)", |
| 38 |
"sigma" = "($sigma:#)", |
| 39 |
"Wald" = "($Wald:f#)", |
| 40 |
"p" = "($p:f#)", |
| 41 |
"N" = "($N:d)" |
| 42 |
)) |
| 43 |
.SummaryStats$ivreg <- c("adj. R-squared","N") |
| 44 |
|
| 45 |
## AER::tobit |
| 46 |
|
| 47 |
getSummary.tobit <- function(obj, alpha = 0.05, ...) { |
| 48 |
## extract summary object |
| 49 |
s <- summary(obj) |
| 50 |
|
| 51 |
## coefficient matrix and confidence interval |
| 52 |
## compute confidence interval manually to include Log(scale) |
| 53 |
cf <- cbind(s$coefficients, |
| 54 |
s$coefficients[, 1] + qnorm(alpha/2) * s$coefficients[, 2], |
| 55 |
s$coefficients[, 1] + qnorm(1 - alpha/2) * s$coefficients[, 2]) |
| 56 |
colnames(cf) <- c("est", "se", "stat", "p", "lwr", "upr") |
| 57 |
|
| 58 |
## Improvement by ME: deal with log-scale parameter |
| 59 |
sp.row <- match("Log(scale)",rownames(cf)) |
| 60 |
sp <- cf[sp.row,,drop=FALSE] |
| 61 |
cf <- cf[-sp.row,,drop=FALSE] |
| 62 |
|
| 63 |
# Patch ME 20.08.2017 |
| 64 |
dn <- c( |
| 65 |
dimnames(cf), |
| 66 |
rownames(attr(obj$terms,"factors"))[1] |
| 67 |
) |
| 68 |
dim(cf) <- c(dim(cf)[1],dim(cf)[2],1) |
| 69 |
dimnames(cf) <- dn |
| 70 |
|
| 71 |
## further summary statistics |
| 72 |
sstat <- c( |
| 73 |
"scale" = s$scale, |
| 74 |
"Wald" = s$wald, |
| 75 |
"numdf" = sum(s$df) - s$idf, |
| 76 |
"p" = pchisq(s$wald, sum(s$df) - s$idf, lower.tail = FALSE), |
| 77 |
"N" = nobs(obj), |
| 78 |
"logLik" = as.vector(logLik(obj)), |
| 79 |
"AIC" = AIC(obj), |
| 80 |
"BIC" = BIC(obj)) |
| 81 |
|
| 82 |
## return everything |
| 83 |
return(list( |
| 84 |
coef=cf, |
| 85 |
scale=sp, |
| 86 |
sumstat = sstat, |
| 87 |
contrasts = obj$contrasts, |
| 88 |
xlevels = obj$xlevels, |
| 89 |
call = obj$call |
| 90 |
)) |
| 91 |
} |
| 92 |
|
| 93 |
setSummaryTemplate("tobit" = c( |
| 94 |
"Scale" = "($scale:#)", |
| 95 |
"Wald" = "($Wald:f#)", |
| 96 |
"p" = "($p:f#)", |
| 97 |
"Log-likelihood" = "($logLik:f#)", |
| 98 |
"AIC" = "($AIC:f#)", |
| 99 |
"BIC" = "($BIC:f#)", |
| 100 |
"N" = "($N:d)" |
| 101 |
)) |
| 102 |
|
| 103 |
## pscl:::hurdle, pscl:::zeroinfl |
| 104 |
|
| 105 |
getSummary.hurdle <- getSummary.zeroinfl <- function(obj, alpha = 0.05, ...) { |
| 106 |
## extract coefficient summary |
| 107 |
cf <- summary(obj)$coefficients |
| 108 |
## augment with confidence intervals |
| 109 |
cval <- qnorm(1 - alpha/2) |
| 110 |
for(i in seq_along(cf)) cf[[i]] <- cbind(cf[[i]], |
| 111 |
cf[[i]][, 1] - cval * cf[[i]][, 2], |
| 112 |
cf[[i]][, 1] + cval * cf[[i]][, 2]) |
| 113 |
## collect in array |
| 114 |
nam <- unique(unlist(lapply(cf, rownames))) |
| 115 |
acf <- array(dim = c(length(nam), 6, length(cf)), |
| 116 |
dimnames = list(nam, c("est", "se", "stat", "p", "lwr", "upr"), names(cf))) |
| 117 |
for(i in seq_along(cf)) acf[rownames(cf[[i]]), , i] <- cf[[i]] |
| 118 |
|
| 119 |
## return everything |
| 120 |
return(list( |
| 121 |
coef = acf, |
| 122 |
sumstat = c( |
| 123 |
"N" = obj$n, |
| 124 |
"logLik" = as.vector(logLik(obj)), |
| 125 |
"AIC" = AIC(obj), |
| 126 |
"BIC" = AIC(obj, k = log(obj$n)) |
| 127 |
), |
| 128 |
contrasts = obj$contrasts, |
| 129 |
xlevels = obj$xlevels, |
| 130 |
call = obj$call |
| 131 |
)) |
| 132 |
} |
| 133 |
|
| 134 |
setSummaryTemplate("hurdle" = c( |
| 135 |
"Log-likelihood" = "($logLik:f#)", |
| 136 |
"AIC" = "($AIC:f#)", |
| 137 |
"BIC" = "($BIC:f#)", |
| 138 |
"N" = "($N:d)" |
| 139 |
)) |
| 140 |
|
| 141 |
setSummaryTemplate("zeroinfl" = c( |
| 142 |
"Log-likelihood" = "($logLik:f#)", |
| 143 |
"AIC" = "($AIC:f#)", |
| 144 |
"BIC" = "($BIC:f#)", |
| 145 |
"N" = "($N:d)" |
| 146 |
)) |
| 147 |
|
| 148 |
## betareg::betareg |
| 149 |
|
| 150 |
getSummary.betareg <- function(obj, alpha = 0.05, ...) { |
| 151 |
## extract coefficient summary |
| 152 |
s <- summary(obj) |
| 153 |
cf <- s$coefficients |
| 154 |
## augment with confidence intervals |
| 155 |
cval <- qnorm(1 - alpha/2) |
| 156 |
for(i in seq_along(cf)) cf[[i]] <- cbind(cf[[i]], |
| 157 |
cf[[i]][, 1] - cval * cf[[i]][, 2], |
| 158 |
cf[[i]][, 1] + cval * cf[[i]][, 2]) |
| 159 |
## collect in array |
| 160 |
nam <- unique(unlist(lapply(cf, rownames))) |
| 161 |
acf <- array(dim = c(length(nam), 6, length(cf)), |
| 162 |
dimnames = list(nam, c("est", "se", "stat", "p", "lwr", "upr"), names(cf))) |
| 163 |
for(i in seq_along(cf)) acf[rownames(cf[[i]]), , i] <- cf[[i]] |
| 164 |
|
| 165 |
## return everything |
| 166 |
return(list( |
| 167 |
coef = acf, |
| 168 |
sumstat = c( |
| 169 |
"N" = obj$n, |
| 170 |
"pseudo.r.squared" = s$pseudo.r.squared, |
| 171 |
"logLik" = as.vector(logLik(obj)), |
| 172 |
"AIC" = AIC(obj), |
| 173 |
"BIC" = AIC(obj, k = log(obj$n)) |
| 174 |
), |
| 175 |
contrasts = obj$contrasts, |
| 176 |
xlevels = obj$xlevels, |
| 177 |
call = obj$call |
| 178 |
)) |
| 179 |
} |
| 180 |
|
| 181 |
setSummaryTemplate("betareg" = c( |
| 182 |
"Pseudo R-sq." = "($pseudo.r.squared:f#)", |
| 183 |
"Log-likelihood" = "($logLik:f#)", |
| 184 |
"AIC" = "($AIC:f#)", |
| 185 |
"BIC" = "($BIC:f#)", |
| 186 |
"N" = "($N:d)" |
| 187 |
)) |
| 188 |
|
| 189 |
getSummary.multinom <- function(obj, alpha = 0.05, ...) { |
| 190 |
## extract coefficient summary |
| 191 |
s <- summary(obj) |
| 192 |
cf <- s$coefficients |
| 193 |
|
| 194 |
## set up array |
| 195 |
acf <- array(dim = c(NCOL(cf), 6, NROW(cf)), |
| 196 |
dimnames = list(colnames(cf), c("est", "se", "stat", "p", "lwr", "upr"), rownames(cf))) |
| 197 |
|
| 198 |
## coefficients and standard errors |
| 199 |
acf[, 1, ] <- t(cf) |
| 200 |
acf[, 2, ] <- t(s$standard.errors) |
| 201 |
|
| 202 |
## compute z-statistic and asymptotic p-value |
| 203 |
acf[, 3, ] <- acf[, 1, ] / acf[, 2, ] |
| 204 |
acf[, 4, ] <- 2 * pnorm(abs(acf[, 3, ]), lower.tail = FALSE) |
| 205 |
|
| 206 |
## asymptotic confidence intervals |
| 207 |
cval <- qnorm(1 - alpha/2) |
| 208 |
acf[, 5, ] <- acf[, 1, ] - cval * acf[, 2, ] |
| 209 |
acf[, 6, ] <- acf[, 1, ] + cval * acf[, 2, ] |
| 210 |
|
| 211 |
## compute number of observations as sum of weights |
| 212 |
nobs <- sum(obj$weights) |
| 213 |
|
| 214 |
## return everything |
| 215 |
return(list( |
| 216 |
coef = acf, |
| 217 |
sumstat = c( |
| 218 |
"N" = nobs, |
| 219 |
"deviance" = obj$deviance, |
| 220 |
"logLik" = as.vector(logLik(obj)), |
| 221 |
"AIC" = AIC(obj), |
| 222 |
"BIC" = AIC(obj, k = log(nobs)) |
| 223 |
), |
| 224 |
contrasts = obj$contrasts, |
| 225 |
xlevels = obj$xlevels, |
| 226 |
call = obj$call |
| 227 |
)) |
| 228 |
} |
| 229 |
|
| 230 |
setSummaryTemplate("multinom" = c( |
| 231 |
"Deviance" = "($deviance:f#)", |
| 232 |
"Log-likelihood" = "($logLik:f#)", |
| 233 |
"AIC" = "($AIC:f#)", |
| 234 |
"BIC" = "($BIC:f#)", |
| 235 |
"N" = "($N:d)" |
| 236 |
)) |
| 237 |
|
| 238 |
|