Codebase list effects / dec5c48
Import Upstream version 2.0.5 Dirk Eddelbuettel 5 years ago
7 changed file(s) with 65 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
00 Package: effects
1 Version: 2.0-4
2 Date: 2009/03/26
1 Version: 2.0-5
2 Date: 2009/04/09
33 Title: Effect Displays for Linear, Generalized Linear,
44 Multinomial-Logit, and Proportional-Odds Logit Models
55 Author: John Fox <jfox@mcmaster.ca> and Jangman Hong. We are grateful
1616 URL: http://www.r-project.org, http://socserv.socsci.mcmaster.ca/jfox/
1717 Repository: CRAN
1818 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
00 # plot, summary, and print methods for effects package
11 # John Fox and Jangman Hong
2 # last modified 19 March 2009 by J. Fox
2 # last modified 9 April 2009 by J. Fox
33
44
55 summary.eff <- function(object, type=c("response", "link"), ...){
3737
3838 print.summary.eff <- function(x, ...){
3939 cat(x$header)
40 print(x$effect)
40 print(x$effect, ...)
4141 if (!is.null(x$lower)){
4242 cat(x$lower.header)
43 print(x$lower)
43 print(x$lower, ...)
4444 cat(x$upper.header)
45 print(x$upper)
45 print(x$upper, ...)
4646 }
4747 if (!is.null(x$thresholds)){
4848 cat("\nThresholds:\n")
49 print(x$thresholds)
49 print(x$thresholds, ...)
5050 }
5151 if (!is.null(x$warning)) cat(x$warning)
5252 invisible(x)
5959 table <- array(x$fit,
6060 dim=sapply(x$variables, function(x) length(x$levels)),
6161 dimnames=lapply(x$variables, function(x) x$levels))
62 print(table)
62 print(table, ...)
6363 if (x$discrepancy > 1e-3) cat(paste("\nWarning: There is an average discrepancy of",
6464 round(x$discrepancy, 3),
6565 "percent \n in the 'safe' predictions for effect", x$term, '\n'))
426426 else {x$logit[y.categories==y.lev[i]]},
427427 dim=sapply(x$variables, function(x) length(x$levels)),
428428 dimnames=lapply(x$variables, function(x) x$levels))
429 print(table)
429 print(table, ...)
430430 }
431431 if (x$discrepancy > 0.1) cat(paste("\nWarning: There is an average discrepancy of",
432432 round(x$discrepancy, 2),
457457 else {object$logit[y.categories==y.lev[i]]},
458458 dim=sapply(object$variables, function(x) length(x$levels)),
459459 dimnames=lapply(object$variables, function(x) x$levels))
460 print(table)
460 print(table, ...)
461461 }
462462 if (is.null(object$confidence.level)) return(invisible(NULL))
463463 for (i in 1:length(y.lev)){
467467 table <- array(table[y.categories==y.lev[i]],
468468 dim=sapply(object$variables, function(x) length(x$levels)),
469469 dimnames=lapply(object$variables, function(x) x$levels))
470 print(table)
470 print(table, ...)
471471 }
472472 for (i in 1:length(y.lev)){
473473 cat(paste("\n", 'Upper', object$confidence.level*100, 'Percent Confidence Limits for'
476476 table <- array(table[y.categories==y.lev[i]],
477477 dim=sapply(object$variables, function(x) length(x$levels)),
478478 dimnames=lapply(object$variables, function(x) x$levels))
479 print(table)
479 print(table, ...)
480480 }
481481 if (object$discrepancy > 0.1) cat(paste("\nWarning: There is an average discrepancy of",
482482 round(object$discrepancy, 2),
784784 table <- array(x$fit,
785785 dim=sapply(x$variables, function(x) length(x$levels)),
786786 dimnames=lapply(x$variables, function(x) x$levels))
787 print(table)
787 print(table, ...)
788788 cat("\nThresholds:\n")
789 print(x$thresholds)
789 print(x$thresholds, ...)
790790 if (x$discrepancy > 0.1) cat(paste("\nWarning: There is an average discrepancy of",
791791 round(x$discrepancy, 3),
792792 "percent \n in the 'safe' predictions for effect", x$term, '\n'))
9090 o Added Titanic and Wells data sets.
9191
9292 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.
3131
3232 \examples{
3333 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)
3445 }
3546
3647 \keyword{datasets}
3737 New York: Springer.
3838 }
3939 \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)))
4151 }
4252 \keyword{datasets}
2727
2828 \examples{
2929 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)
3042 }
3143
3244 \keyword{datasets}
145145 corresponding to the high-order terms of the model.
146146 }
147147
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
148155 \references{
149156 Fox, J. (1987)
150157 Effect displays for generalized linear models.