Import Upstream version 2.0.5
Dirk Eddelbuettel
5 years ago
0 | 0 | Package: effects |
1 | Version: 2.0-4 | |
2 | Date: 2009/03/26 | |
1 | Version: 2.0-5 | |
2 | Date: 2009/04/09 | |
3 | 3 | Title: Effect Displays for Linear, Generalized Linear, |
4 | 4 | Multinomial-Logit, and Proportional-Odds Logit Models |
5 | 5 | Author: John Fox <jfox@mcmaster.ca> and Jangman Hong. We are grateful |
16 | 16 | URL: http://www.r-project.org, http://socserv.socsci.mcmaster.ca/jfox/ |
17 | 17 | Repository: CRAN |
18 | 18 | Repository/R-Forge/Project: effects |
19 | Repository/R-Forge/Revision: 27 | |
20 | Publication/Date: 2009-03-27 02:25:06 | |
21 | Packaged: Wed Apr 1 05:14:22 2009; rforge | |
22 | Date/Publication: 2009-04-01 17:01:40 | |
19 | Repository/R-Forge/Revision: 30 | |
20 | Publication/Date: 2009-04-09 15:04:11 | |
21 | Packaged: Mon Apr 13 17:50:14 2009; rforge | |
22 | Date/Publication: 2009-04-15 07:34:13 |
0 | 0 | # plot, summary, and print methods for effects package |
1 | 1 | # John Fox and Jangman Hong |
2 | # last modified 19 March 2009 by J. Fox | |
2 | # last modified 9 April 2009 by J. Fox | |
3 | 3 | |
4 | 4 | |
5 | 5 | summary.eff <- function(object, type=c("response", "link"), ...){ |
37 | 37 | |
38 | 38 | print.summary.eff <- function(x, ...){ |
39 | 39 | cat(x$header) |
40 | print(x$effect) | |
40 | print(x$effect, ...) | |
41 | 41 | if (!is.null(x$lower)){ |
42 | 42 | cat(x$lower.header) |
43 | print(x$lower) | |
43 | print(x$lower, ...) | |
44 | 44 | cat(x$upper.header) |
45 | print(x$upper) | |
45 | print(x$upper, ...) | |
46 | 46 | } |
47 | 47 | if (!is.null(x$thresholds)){ |
48 | 48 | cat("\nThresholds:\n") |
49 | print(x$thresholds) | |
49 | print(x$thresholds, ...) | |
50 | 50 | } |
51 | 51 | if (!is.null(x$warning)) cat(x$warning) |
52 | 52 | invisible(x) |
59 | 59 | table <- array(x$fit, |
60 | 60 | dim=sapply(x$variables, function(x) length(x$levels)), |
61 | 61 | dimnames=lapply(x$variables, function(x) x$levels)) |
62 | print(table) | |
62 | print(table, ...) | |
63 | 63 | if (x$discrepancy > 1e-3) cat(paste("\nWarning: There is an average discrepancy of", |
64 | 64 | round(x$discrepancy, 3), |
65 | 65 | "percent \n in the 'safe' predictions for effect", x$term, '\n')) |
426 | 426 | else {x$logit[y.categories==y.lev[i]]}, |
427 | 427 | dim=sapply(x$variables, function(x) length(x$levels)), |
428 | 428 | dimnames=lapply(x$variables, function(x) x$levels)) |
429 | print(table) | |
429 | print(table, ...) | |
430 | 430 | } |
431 | 431 | if (x$discrepancy > 0.1) cat(paste("\nWarning: There is an average discrepancy of", |
432 | 432 | round(x$discrepancy, 2), |
457 | 457 | else {object$logit[y.categories==y.lev[i]]}, |
458 | 458 | dim=sapply(object$variables, function(x) length(x$levels)), |
459 | 459 | dimnames=lapply(object$variables, function(x) x$levels)) |
460 | print(table) | |
460 | print(table, ...) | |
461 | 461 | } |
462 | 462 | if (is.null(object$confidence.level)) return(invisible(NULL)) |
463 | 463 | for (i in 1:length(y.lev)){ |
467 | 467 | table <- array(table[y.categories==y.lev[i]], |
468 | 468 | dim=sapply(object$variables, function(x) length(x$levels)), |
469 | 469 | dimnames=lapply(object$variables, function(x) x$levels)) |
470 | print(table) | |
470 | print(table, ...) | |
471 | 471 | } |
472 | 472 | for (i in 1:length(y.lev)){ |
473 | 473 | cat(paste("\n", 'Upper', object$confidence.level*100, 'Percent Confidence Limits for' |
476 | 476 | table <- array(table[y.categories==y.lev[i]], |
477 | 477 | dim=sapply(object$variables, function(x) length(x$levels)), |
478 | 478 | dimnames=lapply(object$variables, function(x) x$levels)) |
479 | print(table) | |
479 | print(table, ...) | |
480 | 480 | } |
481 | 481 | if (object$discrepancy > 0.1) cat(paste("\nWarning: There is an average discrepancy of", |
482 | 482 | round(object$discrepancy, 2), |
784 | 784 | table <- array(x$fit, |
785 | 785 | dim=sapply(x$variables, function(x) length(x$levels)), |
786 | 786 | dimnames=lapply(x$variables, function(x) x$levels)) |
787 | print(table) | |
787 | print(table, ...) | |
788 | 788 | cat("\nThresholds:\n") |
789 | print(x$thresholds) | |
789 | print(x$thresholds, ...) | |
790 | 790 | if (x$discrepancy > 0.1) cat(paste("\nWarning: There is an average discrepancy of", |
791 | 791 | round(x$discrepancy, 3), |
792 | 792 | "percent \n in the 'safe' predictions for effect", x$term, '\n')) |
90 | 90 | o Added Titanic and Wells data sets. |
91 | 91 | |
92 | 92 | o Small changes. |
93 | ||
94 | Version 2.0-5 | |
95 | ||
96 | o Added examples for Titanic, BEPS, and WVS data sets. | |
97 | ||
98 | o Arguments ... (e.g., digits) passed through in print() methods. |
31 | 31 | |
32 | 32 | \examples{ |
33 | 33 | summary(BEPS) |
34 | ||
35 | require(splines) # for bs() | |
36 | beps <- multinom(vote ~ age + gender + economic.cond.national + economic.cond.household | |
37 | + Blair + Hague + Kennedy + bs(Europe, 3)*political.knowledge, data=BEPS) | |
38 | europe.knowledge <- effect("bs(Europe, 3)*political.knowledge", beps, | |
39 | xlevels=list(Europe=seq(1, 11, length=50), political.knowledge=0:3), | |
40 | given.values=c(gendermale=0.5)) | |
41 | ||
42 | plot(europe.knowledge) | |
43 | ||
44 | plot(europe.knowledge, style="stacked", colors=c("blue", "red", "orange"), rug=FALSE) | |
34 | 45 | } |
35 | 46 | |
36 | 47 | \keyword{datasets} |
37 | 37 | New York: Springer. |
38 | 38 | } |
39 | 39 | \examples{ |
40 | summary(Titanic) | |
40 | summary(Titanic) | |
41 | ||
42 | titanic <- glm(survived ~ (passengerClass + sex + age)^2, data=Titanic, family=binomial) | |
43 | ||
44 | titanic.all <- allEffects(titanic, typical=median, | |
45 | given.values=c(passengerClass2nd=1/3, passengerClass3rd=1/3, sexmale=0.5)) | |
46 | ||
47 | plot(titanic.all, ticks=list(at=c(.01, .05, seq(.1, .9, by=.2), .95, .99)), ask=FALSE) | |
48 | ||
49 | plot(effect("passengerClass*sex*age", titanic, xlevels=list(age=0:65)), | |
50 | ticks=list(at=c(.001, .005, .01, .05, seq(.1, .9, by=.2), .95, .99, .995))) | |
41 | 51 | } |
42 | 52 | \keyword{datasets} |
27 | 27 | |
28 | 28 | \examples{ |
29 | 29 | summary(WVS) |
30 | ||
31 | require(splines) # for bs() | |
32 | wvs <- polr(poverty ~ gender + country*(religion + degree + bs(age, 4)), data=WVS) | |
33 | ||
34 | plot(effect("country*bs(age,4)", wvs, xlevels=list(age=18:83), | |
35 | given.values=c(gendermale=0.5)), rug=FALSE) | |
36 | ||
37 | plot(effect("country*bs(age,4)", wvs, xlevels=list(age=18:83), | |
38 | given.values=c(gendermale=0.5)), rug=FALSE, style="stacked") | |
39 | ||
40 | plot(effect("country*bs(age,4)", wvs, xlevels=list(age=18:83), | |
41 | given.values=c(gendermale=0.5), latent=TRUE), rug=FALSE) | |
30 | 42 | } |
31 | 43 | |
32 | 44 | \keyword{datasets} |
145 | 145 | corresponding to the high-order terms of the model. |
146 | 146 | } |
147 | 147 | |
148 | \section{Warning}{ | |
149 | The \code{effect} function handles factors and covariates differently, and becomes confused if one is changed to the other | |
150 | in a model formula. Consequently, formulas that include calls to \code{as.factor}, \code{factor}, or \code{numeric} | |
151 | (as, e.g., in \code{as.factor(income)}) will cause errors. Instead, create the modified variables outside of the model | |
152 | formula (e.g., \code{fincome <- as.factor(income)}) and use these in the model formula. | |
153 | } | |
154 | ||
148 | 155 | \references{ |
149 | 156 | Fox, J. (1987) |
150 | 157 | Effect displays for generalized linear models. |