R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("vcd-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('vcd') Loading required package: MASS Loading required package: grid Loading required package: colorspace Attaching package: 'colorspace' The following object(s) are masked from package:grDevices : hcl > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "Arthritis" > > ### * Arthritis > > flush(stderr()); flush(stdout()) > > ### Name: Arthritis > ### Title: Arthritis Treatment Data > ### Aliases: Arthritis > ### Keywords: datasets > > ### ** Examples > > data(Arthritis) > > ## construct a table of interest using xtabs() or structable() > ## via formula > structable(Sex ~ Treatment + Improved, data = Arthritis) Sex Female Male Treatment Improved Placebo None 19 10 Some 7 0 Marked 6 1 Treated None 6 7 Some 5 2 Marked 16 5 > > ## via default interface > attach(Arthritis) > structable(Treatment, Sex, Improved) Sex Female Male Treatment Improved Placebo None 19 10 Some 7 0 Marked 6 1 Treated None 6 7 Some 5 2 Marked 16 5 > detach(Arthritis) > > ## via xtabs and ftable > ftable(xtabs(~Treatment + Improved + Sex, data = Arthritis)) Sex Female Male Treatment Improved Placebo None 19 10 Some 7 0 Marked 6 1 Treated None 6 7 Some 5 2 Marked 16 5 > > > > cleanEx(); ..nameEx <- "Baseball" > > ### * Baseball > > flush(stderr()); flush(stdout()) > > ### Name: Baseball > ### Title: Baseball Data > ### Aliases: Baseball > ### Keywords: datasets > > ### ** Examples > > data(Baseball) > > > > cleanEx(); ..nameEx <- "BrokenMarriage" > > ### * BrokenMarriage > > flush(stderr()); flush(stdout()) > > ### Name: BrokenMarriage > ### Title: Broken Marriage Data > ### Aliases: BrokenMarriage > ### Keywords: datasets > > ### ** Examples > > data(BrokenMarriage) > structable(~ ., data = BrokenMarriage) rank I II III IV V gender broken male yes 14 39 42 79 66 no 102 151 292 293 261 female yes 12 23 37 102 58 no 25 79 151 557 321 > > > > cleanEx(); ..nameEx <- "Bundesliga" > > ### * Bundesliga > > flush(stderr()); flush(stdout()) > > ### Name: Bundesliga > ### Title: Ergebnisse der Fussball-Bundesliga > ### Aliases: Bundesliga > ### Keywords: datasets > > ### ** Examples > > data(Bundesliga) > > ## independence of home and away goals > tore95 <- xtabs(~ HomeGoals + AwayGoals, data = Bundesliga, + subset = Year == 1995) > tore95 AwayGoals HomeGoals 0 1 2 3 4 5 6 0 26 16 13 5 0 1 0 1 19 58 20 5 4 0 1 2 27 23 20 5 1 1 1 3 14 11 10 4 2 0 0 4 3 5 3 0 0 0 0 5 4 1 0 1 0 0 0 6 1 0 0 1 0 0 0 > mosaic(tore95, gp = shading_max) > > ## number of goals per game poisson distributed? > ntore1 <- xtabs(~ HomeGoals, data = Bundesliga, subset = Year == 1995) > ntore2 <- xtabs(~ AwayGoals, data = Bundesliga, subset = Year == 1995) > ntore3 <- table(apply(subset(Bundesliga, Year == 1995)[,3:4], 1, sum)) > > gf1 <- goodfit(ntore1) > gf2 <- goodfit(ntore2) > gf3 <- goodfit(ntore3) > > summary(gf1) Goodness-of-fit test for poisson distribution X^2 df P(> X^2) Likelihood Ratio 3.480285 5 0.6263728 > summary(gf2) Goodness-of-fit test for poisson distribution X^2 df P(> X^2) Likelihood Ratio 4.86855 5 0.4321324 > summary(gf3) Goodness-of-fit test for poisson distribution X^2 df P(> X^2) Likelihood Ratio 19.84905 8 0.01092249 > plot(gf1) > plot(gf2) > plot(gf3) > > Ord_plot(ntore1) > distplot(ntore1) > > > > cleanEx(); ..nameEx <- "Butterfly" > > ### * Butterfly > > flush(stderr()); flush(stdout()) > > ### Name: Butterfly > ### Title: Butterfly Species in Malaya > ### Aliases: Butterfly > ### Keywords: datasets > > ### ** Examples > > data(Butterfly) > Ord_plot(Butterfly) > > > > cleanEx(); ..nameEx <- "CoalMiners" > > ### * CoalMiners > > flush(stderr()); flush(stdout()) > > ### Name: CoalMiners > ### Title: Breathlessness and Wheeze in Coal Miners > ### Aliases: CoalMiners > ### Keywords: datasets > > ### ** Examples > > data(CoalMiners) > > ## Fourfold display, both margins equated > fourfold(CoalMiners, mfcol = c(2,4)) > > ## Log Odds Ratio Plot > summary(l <- oddsratio(CoalMiners)) Log Odds Ratio Std. Error z value Pr(>|z|) 25-29 3.69526 0.39737 9.2994 < 2.2e-16 *** 30-34 3.39834 0.27532 12.3432 < 2.2e-16 *** 35-39 3.14066 0.18209 17.2479 < 2.2e-16 *** 40-44 3.01469 0.16872 17.8678 < 2.2e-16 *** 45-49 2.78205 0.13666 20.3576 < 2.2e-16 *** 50-54 2.92640 0.12574 23.2729 < 2.2e-16 *** 55-59 2.44057 0.12036 20.2779 < 2.2e-16 *** 60-64 2.63795 0.14670 17.9820 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > g <- seq(25, 60, by = 5) > plot(l, + xlab = "Age Group", + main = "Breathlessness and Wheeze in Coal Miners") > m <- lm(l ~ g + I(g^2)) > lines(fitted(m), col = "red") > > ## Fourfold display, strata equated > fourfold(CoalMiners, std = "ind.max", mfcol = c(2,4)) > > > > cleanEx(); ..nameEx <- "DanishWelfare" > > ### * DanishWelfare > > flush(stderr()); flush(stdout()) > > ### Name: DanishWelfare > ### Title: Danish Welfare Study Data > ### Aliases: DanishWelfare > ### Keywords: datasets > > ### ** Examples > > data(DanishWelfare) > ftable(xtabs(Freq ~ ., data = DanishWelfare)) Urban Copenhagen SubCopenhagen LargeCity City Country Alcohol Income Status <1 0-50 Widow 1 4 1 8 6 Married 14 8 41 100 175 Unmarried 6 1 2 6 9 50-100 Widow 8 2 7 14 5 Married 42 51 62 234 255 Unmarried 7 5 9 20 27 100-150 Widow 2 3 1 5 2 Married 21 30 23 87 77 Unmarried 3 2 1 12 4 >150 Widow 42 29 17 95 46 Married 24 30 50 167 232 Unmarried 33 24 15 64 68 1-2 0-50 Widow 3 0 1 4 2 Married 15 7 15 25 48 Unmarried 2 3 9 9 7 50-100 Widow 1 1 3 8 4 Married 39 59 68 172 143 Unmarried 12 3 11 20 23 100-150 Widow 5 4 1 9 4 Married 32 68 43 128 86 Unmarried 6 10 5 21 15 >150 Widow 26 34 14 48 24 Married 43 76 70 198 136 Unmarried 36 23 48 89 64 >2 0-50 Widow 2 0 2 1 0 Married 1 2 2 7 7 Unmarried 3 0 1 5 1 50-100 Widow 3 0 2 1 3 Married 14 21 14 38 35 Unmarried 2 0 3 12 13 100-150 Widow 2 1 1 1 0 Married 20 31 10 36 21 Unmarried 0 2 3 9 7 >150 Widow 21 13 5 20 8 Married 23 47 21 53 36 Unmarried 38 20 13 39 26 > > > > cleanEx(); ..nameEx <- "Employment" > > ### * Employment > > flush(stderr()); flush(stdout()) > > ### Name: Employment > ### Title: Employment Status > ### Aliases: Employment > ### Keywords: datasets > > ### ** Examples > > data(Employment) > > ## Employment Status > mosaic(Employment, + expected = ~ LayoffCause * EmploymentLength + EmploymentStatus, + main = "Layoff*EmployLength + EmployStatus") > > mosaic(Employment, + expected = ~ LayoffCause * EmploymentLength + LayoffCause * EmploymentStatus, + main = "Layoff*EmployLength + Layoff*EmployStatus") > > ## Stratified view > > grid.newpage() > pushViewport(viewport(layout = grid.layout(ncol = 2))) > pushViewport(viewport(layout.pos.col = 1)) > > ## Closure > mosaic(Employment[,,1], main = "Layoff: Closure", newpage = FALSE) > > popViewport(1) > pushViewport(viewport(layout.pos.col = 2)) > > ## Replaced > mosaic(Employment[,,2], main = "Layoff: Replaced", newpage = FALSE) > popViewport(2) > > > > cleanEx(); ..nameEx <- "Federalist" > > ### * Federalist > > flush(stderr()); flush(stdout()) > > ### Name: Federalist > ### Title: `May' in Federalist Papers > ### Aliases: Federalist > ### Keywords: datasets > > ### ** Examples > > data(Federalist) > gf <- goodfit(Federalist, type = "nbinomial") > summary(gf) Goodness-of-fit test for nbinomial distribution X^2 df P(> X^2) Likelihood Ratio 1.96403 4 0.7423748 > plot(gf) > > > > cleanEx(); ..nameEx <- "Hitters" > > ### * Hitters > > flush(stderr()); flush(stdout()) > > ### Name: Hitters > ### Title: Hitters Data > ### Aliases: Hitters > ### Keywords: datasets > > ### ** Examples > > data(Hitters) > attach(Hitters) > > colors <- c("black","red","green","blue","red","black","blue") > pch <- substr(levels(Positions), 1, 1) > ternaryplot(Hitters[,2:4], + pch = as.character(Positions), + col = colors[as.numeric(Positions)], + main = "Baseball Hitters Data") > grid_legend(0.8, 0.9, pch, colors, levels(Positions), + title = "POSITION(S)") > > detach(Hitters) > > > > cleanEx(); ..nameEx <- "HorseKicks" > > ### * HorseKicks > > flush(stderr()); flush(stdout()) > > ### Name: HorseKicks > ### Title: Death by Horse Kicks > ### Aliases: HorseKicks > ### Keywords: datasets > > ### ** Examples > > data(HorseKicks) > gf <- goodfit(HorseKicks) > summary(gf) Goodness-of-fit test for poisson distribution X^2 df P(> X^2) Likelihood Ratio 0.8682214 3 0.8330891 > plot(gf) > > > > cleanEx(); ..nameEx <- "JobSatisfaction" > > ### * JobSatisfaction > > flush(stderr()); flush(stdout()) > > ### Name: JobSatisfaction > ### Title: Job Satisfaction Data > ### Aliases: JobSatisfaction > ### Keywords: datasets > > ### ** Examples > > data(JobSatisfaction) > structable(~ ., data = JobSatisfaction) supervisor low high management own bad low 103 32 high 87 42 good low 59 78 high 109 205 > > mantelhaen.test(xtabs(Freq ~ own + supervisor + management, + data = JobSatisfaction)) Mantel-Haenszel chi-squared test with continuity correction data: xtabs(Freq ~ own + supervisor + management, data = JobSatisfaction) Mantel-Haenszel X-squared = 4.9602, df = 1, p-value = 0.02594 alternative hypothesis: true common odds ratio is not equal to 1 95 percent confidence interval: 1.060007 2.037733 sample estimates: common odds ratio 1.469698 > > > > > cleanEx(); ..nameEx <- "JointSports" > > ### * JointSports > > flush(stderr()); flush(stdout()) > > ### Name: JointSports > ### Title: Opinions About Joint Sports > ### Aliases: JointSports > ### Keywords: datasets > > ### ** Examples > > data(JointSports) > structable(~ ., data = JointSports) year 1983 1985 gender Boy Girl Boy Girl opinion grade very good 1st 31 103 41 77 3rd 23 61 31 52 good 1st 51 67 67 80 3rd 39 72 31 70 indifferent 1st 38 29 35 27 3rd 36 39 31 28 bad 1st 10 15 12 10 3rd 15 16 4 4 very bad 1st 4 2 2 3 3rd 2 3 7 3 > > > > cleanEx(); ..nameEx <- "Kappa" > > ### * Kappa > > flush(stderr()); flush(stdout()) > > ### Name: Kappa > ### Title: Cohen's Kappa and Weighted Kappa > ### Aliases: Kappa print.Kappa confint.Kappa summary.Kappa > ### print.summary.Kappa > ### Keywords: category > > ### ** Examples > > data(SexualFun) > Kappa(SexualFun) value ASE Unweighted 0.1293303 0.06884553 Weighted 0.2373806 0.12646539 > > > > cleanEx(); ..nameEx <- "Lifeboats" > > ### * Lifeboats > > flush(stderr()); flush(stdout()) > > ### Name: Lifeboats > ### Title: Lifeboats on the Titanic > ### Aliases: Lifeboats > ### Keywords: datasets > > ### ** Examples > > data(Lifeboats) > attach(Lifeboats) > ternaryplot( + Lifeboats[,4:6], + pch = ifelse(side == "Port", 1, 19), + col = ifelse(side == "Port", "red", "blue"), + id = ifelse(men / total > 0.1, as.character(boat), NA), + prop_size = 2, + dimnames_position = "edge", + main = "Lifeboats on the Titanic" + ) > grid_legend(0.8, 0.9, c(1, 19), c("red", "blue"), + c("Port", "Starboard"), title = "SIDE") > detach(Lifeboats) > > > > cleanEx(); ..nameEx <- "MSPatients" > > ### * MSPatients > > flush(stderr()); flush(stdout()) > > ### Name: MSPatients > ### Title: Diagnosis of Multiple Sclerosis > ### Aliases: MSPatients > ### Keywords: datasets > > ### ** Examples > > data(MSPatients) > get(getOption("device"))(width = 12) > pushViewport(viewport(layout = grid.layout(ncol = 2))) > pushViewport(viewport(layout.pos.col = 1)) > agreementplot(t(MSPatients[,,1]), main = "Winnipeg Patients", + newpage = FALSE) > popViewport() > pushViewport(viewport(layout.pos.col = 2)) > agreementplot(t(MSPatients[,,2]), main = "New Orleans Patients", + newpage = FALSE) > popViewport(2) > dev.off() postscript 2 > > > > cleanEx(); ..nameEx <- "NonResponse" > > ### * NonResponse > > flush(stderr()); flush(stdout()) > > ### Name: NonResponse > ### Title: Non-Response Survey Data > ### Aliases: NonResponse > ### Keywords: datasets > > ### ** Examples > > data(NonResponse) > structable(~ ., data = NonResponse) response yes no residence gender Copenhagen male 306 49 female 264 76 City male 609 77 female 627 79 Country male 978 103 female 947 114 > > > > cleanEx(); ..nameEx <- "Ord.plot" > > ### * Ord.plot > > flush(stderr()); flush(stdout()) > > ### Name: Ord_plot > ### Title: Ord Plots > ### Aliases: Ord_plot Ord_estimate > ### Keywords: category > > ### ** Examples > > ## Simulated data examples: > dummy <- rnbinom(1000, size = 1.5, prob = 0.8) > Ord_plot(dummy) > > ## Real data examples: > data(HorseKicks) > data(Federalist) > data(Butterfly) > data(WomenQueue) > > grid.newpage() > pushViewport(viewport(layout = grid.layout(2, 2))) > > pushViewport(viewport(layout.pos.col=1, layout.pos.row=1)) > Ord_plot(HorseKicks, main = "Death by horse kicks", newpage = FALSE) > popViewport() > > pushViewport(viewport(layout.pos.col=1, layout.pos.row=2)) > Ord_plot(Federalist, main = "Instances of 'may' in Federalist papers", newpage = FALSE) > popViewport() > > pushViewport(viewport(layout.pos.col=2, layout.pos.row=1)) > Ord_plot(Butterfly, main = "Butterfly species collected in Malaya", newpage = FALSE) > popViewport() > > pushViewport(viewport(layout.pos.col=2, layout.pos.row=2)) > Ord_plot(WomenQueue, main = "Women in queues of length 10", newpage = FALSE) Warning in sqrt(x - 1) : NaNs produced > popViewport(2) > > > > cleanEx(); ..nameEx <- "OvaryCancer" > > ### * OvaryCancer > > flush(stderr()); flush(stdout()) > > ### Name: OvaryCancer > ### Title: Ovary Cancer Data > ### Aliases: OvaryCancer > ### Keywords: datasets > > ### ** Examples > > data(OvaryCancer) > structable(~ ., data = OvaryCancer) operation radical limited xray no yes no yes stage survival early no 10 17 1 3 yes 41 64 13 9 advanced no 38 64 3 13 yes 6 11 1 5 > > > > cleanEx(); ..nameEx <- "PreSex" > > ### * PreSex > > flush(stderr()); flush(stdout()) > > ### Name: PreSex > ### Title: Pre-marital Sex and Divorce > ### Aliases: PreSex > ### Keywords: datasets > > ### ** Examples > > data(PreSex) > > ## Mosaic display for Gender and Premarital Sexual Experience > ## (Gender Pre) > mosaic(margin.table(PreSex, c(3,4)), + main = "Gender and Premarital Sex") > > ## (Gender Pre)(Extra) > mosaic(margin.table(PreSex, c(2,3,4)), + expected = ~Gender * PremaritalSex + ExtramaritalSex , + main = "PreMaritalSex*Gender +Sex") > > ## (Gender Pre Extra)(Marital) > mosaic(PreSex, + expected = ~Gender*PremaritalSex*ExtramaritalSex + MaritalStatus, + main = "PreMarital*ExtraMarital + MaritalStatus") > > ## (GPE)(PEM) > mosaic(PreSex, + expected = ~ Gender * PremaritalSex * ExtramaritalSex + + MaritalStatus * PremaritalSex * ExtramaritalSex, + main = "G*P*E + P*E*M") > > > > cleanEx(); ..nameEx <- "Punishment" > > ### * Punishment > > flush(stderr()); flush(stdout()) > > ### Name: Punishment > ### Title: Corporal Punishment Data > ### Aliases: Punishment > ### Keywords: datasets > > ### ** Examples > > data(Punishment) > structable(~ ., data = Punishment) memory yes no age 15-24 25-39 40- 15-24 25-39 40- attitude education no elementary 1 3 20 26 46 109 secondary 2 8 4 23 52 44 high 2 6 1 26 24 13 moderate elementary 21 41 143 93 119 324 secondary 5 20 20 45 84 56 high 1 4 8 19 26 17 > > > > cleanEx(); ..nameEx <- "RepVict" > > ### * RepVict > > flush(stderr()); flush(stdout()) > > ### Name: RepVict > ### Title: Repeat Victimization Data > ### Aliases: RepVict > ### Keywords: datasets > > ### ** Examples > > data(RepVict) > > mosaic(RepVict[-c(4,7),-c(4,7)], gp = shading_max, + main = "Repeat Victimization Data") > > > > cleanEx(); ..nameEx <- "Rochdale" > > ### * Rochdale > > flush(stderr()); flush(stdout()) > > ### Name: Rochdale > ### Title: Rochdale Data > ### Aliases: Rochdale > ### Keywords: datasets > > ### ** Examples > > data(Rochdale) > mosaic(Rochdale) > > > > cleanEx(); ..nameEx <- "Saxony" > > ### * Saxony > > flush(stderr()); flush(stdout()) > > ### Name: Saxony > ### Title: Families in Saxony > ### Aliases: Saxony > ### Keywords: datasets > > ### ** Examples > > data(Saxony) > gf <- goodfit(Saxony, type = "binomial") Warning in switch(type, poisson = { : size was not given, taken as maximum count > summary(gf) Goodness-of-fit test for binomial distribution X^2 df P(> X^2) Likelihood Ratio 97.0065 11 6.978187e-16 > plot(gf) > > > > cleanEx(); ..nameEx <- "SexualFun" > > ### * SexualFun > > flush(stderr()); flush(stdout()) > > ### Name: SexualFun > ### Title: Sex is Fun > ### Aliases: SexualFun > ### Keywords: datasets > > ### ** Examples > > data(SexualFun) > > ## Kappa statistics > Kappa(SexualFun) value ASE Unweighted 0.1293303 0.06884553 Weighted 0.2373806 0.12646539 > > ## Agreement Chart > agreementplot(t(SexualFun), weights = 1) > ## Partial Agreement Chart and B-Statistics > agreementplot(t(SexualFun), + xlab = "Husband's Rating", + ylab = "Wife's Rating", + main = "Husband's and Wife's Sexual Fun") > > > > cleanEx(); ..nameEx <- "SpaceShuttle" > > ### * SpaceShuttle > > flush(stderr()); flush(stdout()) > > ### Name: SpaceShuttle > ### Title: Space Shuttle O-ring Failures > ### Aliases: SpaceShuttle > ### Keywords: datasets > > ### ** Examples > > data(SpaceShuttle) > plot(nFailures/6 ~ Temperature, data = SpaceShuttle, + xlim = c(30, 81), ylim = c(0,1), + main = "NASA Space Shuttle O-Ring Failures", + ylab = "Estimated failure probability", + pch = 19, col = 4) > fm <- glm(cbind(nFailures, 6 - nFailures) ~ Temperature, + data = SpaceShuttle, + family = binomial) > lines(30 : 81, + predict(fm, data.frame(Temperature = 30 : 81), type = "re"), + lwd = 2) > abline(v = 31, lty = 3) > > > > cleanEx(); ..nameEx <- "Suicide" > > ### * Suicide > > flush(stderr()); flush(stdout()) > > ### Name: Suicide > ### Title: Suicide Rates in Germany > ### Aliases: Suicide > ### Keywords: datasets > > ### ** Examples > > data(Suicide) > structable(~ sex + method2 + age.group, data = Suicide) method2 poison gas hang drown gun knife jump other sex age.group male 10-20 1160 335 1524 67 512 47 189 464 25-35 2823 883 2751 213 852 139 366 775 40-50 2465 625 3936 247 875 183 244 534 55-65 1531 201 3581 207 477 154 273 294 70-90 938 45 2948 212 229 105 268 147 female 10-20 921 40 212 30 25 11 131 100 25-35 1672 113 575 139 64 41 276 263 40-50 2224 91 1481 354 52 80 327 305 55-65 2283 45 2014 679 29 103 388 296 70-90 1548 29 1355 501 3 74 383 106 > > > > cleanEx(); ..nameEx <- "Trucks" > > ### * Trucks > > flush(stderr()); flush(stdout()) > > ### Name: Trucks > ### Title: Truck Accidents Data > ### Aliases: Trucks > ### Keywords: datasets > > ### ** Examples > > data(Trucks) > structable(~ ., data = Trucks, direction = 'v') period before after parked yes no yes no collision light back daylight 712 2557 613 2373 night, illuminate 634 325 411 283 night, dark 345 579 179 494 forward daylight 192 10749 179 9768 night, illuminate 95 1256 55 987 night, dark 46 1018 39 885 > > > > cleanEx(); ..nameEx <- "UKSoccer" > > ### * UKSoccer > > flush(stderr()); flush(stdout()) > > ### Name: UKSoccer > ### Title: UK Soccer Scores > ### Aliases: UKSoccer > ### Keywords: datasets > > ### ** Examples > > data(UKSoccer) > mosaic(UKSoccer, gp = shading_max, main = "UK Soccer Scores") > > > > cleanEx(); ..nameEx <- "VisualAcuity" > > ### * VisualAcuity > > flush(stderr()); flush(stdout()) > > ### Name: VisualAcuity > ### Title: Visual Acuity in Left and Right Eyes > ### Aliases: VisualAcuity > ### Keywords: datasets > > ### ** Examples > > data(VisualAcuity) > structable(~ gender + left + right, data = VisualAcuity) left 1 2 3 4 gender right male 1 821 112 85 35 2 116 494 145 27 3 72 151 583 87 4 43 34 106 331 female 1 1520 266 124 66 2 234 1512 432 78 3 117 362 1772 205 4 36 82 179 492 > > > > cleanEx(); ..nameEx <- "VonBort" > > ### * VonBort > > flush(stderr()); flush(stdout()) > > ### Name: VonBort > ### Title: Von Bortkiewicz Horse Kicks Data > ### Aliases: VonBort > ### Keywords: datasets > > ### ** Examples > > data(VonBort) > ## HorseKicks data > xtabs(~ deaths, data = VonBort, subset = fisher == "yes") deaths 0 1 2 3 4 109 65 22 3 1 > > > > cleanEx(); ..nameEx <- "WeldonDice" > > ### * WeldonDice > > flush(stderr()); flush(stdout()) > > ### Name: WeldonDice > ### Title: Weldon's Dice Data > ### Aliases: WeldonDice > ### Keywords: datasets > > ### ** Examples > > data(WeldonDice) > gf <- goodfit(WeldonDice, type = "binomial") Warning in switch(type, poisson = { : size was not given, taken as maximum count > summary(gf) Goodness-of-fit test for binomial distribution X^2 df P(> X^2) Likelihood Ratio 225.2765 9 1.624315e-43 > plot(gf) > > > > cleanEx(); ..nameEx <- "WomenQueue" > > ### * WomenQueue > > flush(stderr()); flush(stdout()) > > ### Name: WomenQueue > ### Title: Women in Queues > ### Aliases: WomenQueue > ### Keywords: datasets > > ### ** Examples > > data(WomenQueue) > gf <- goodfit(WomenQueue, type = "binomial") Warning in switch(type, poisson = { : size was not given, taken as maximum count > summary(gf) Goodness-of-fit test for binomial distribution X^2 df P(> X^2) Likelihood Ratio 9.524777 8 0.2999755 > plot(gf) > > > > cleanEx(); ..nameEx <- "agreementplot" > > ### * agreementplot > > flush(stderr()); flush(stdout()) > > ### Name: agreementplot > ### Title: Bangdiwala's Observer Agreement Chart > ### Aliases: agreementplot agreementplot.default agreementplot.formula > ### Keywords: category hplot > > ### ** Examples > > data(SexualFun) > agreementplot(t(SexualFun)) > > data(MSPatients) > get(getOption("device"))(width = 12) > pushViewport(viewport(layout = grid.layout(ncol = 2))) > pushViewport(viewport(layout.pos.col = 1)) > agreementplot(t(MSPatients[,,1]), main = "Winnipeg Patients", + newpage = FALSE) > popViewport() > pushViewport(viewport(layout.pos.col = 2)) > agreementplot(t(MSPatients[,,2]), main = "New Orleans Patients", + newpage = FALSE) > popViewport(2) > dev.off() postscript 2 > > > > cleanEx(); ..nameEx <- "assoc" > > ### * assoc > > flush(stderr()); flush(stdout()) > > ### Name: assoc > ### Title: Extended Association Plots > ### Aliases: assoc assoc.default assoc.formula > ### Keywords: hplot > > ### ** Examples > > data(HairEyeColor) > ## Aggregate over sex: > (x <- margin.table(HairEyeColor, c(1, 2))) Eye Hair Brown Blue Hazel Green Black 68 20 15 5 Brown 119 84 54 29 Red 26 17 14 14 Blond 7 94 10 16 > > ## Ordinary assocplot: > assoc(x) > ## and with residual-based shading (of independence) > assoc(x, main = "Relation between hair and eye color", shade = TRUE) > > ## Aggregate over Eye color: > (x <- margin.table(HairEyeColor, c(1, 3))) Sex Hair Male Female Black 56 52 Brown 128 158 Red 34 37 Blond 46 81 > chisq.test(x) Pearson's Chi-squared test data: x X-squared = 6.2212, df = 3, p-value = 0.1013 > assoc(x, main = "Relation between hair color and sex", shade = TRUE) > > # Visualize multi-way table > assoc(aperm(HairEyeColor), expected = ~ (Hair + Eye) * Sex, + labeling_args = list(just_labels = c(Eye = "left"), + offset = c(right = -0.5), + rot_labels = c(right = 0), + tl_varnames = c(Eye = TRUE)) + ) > > assoc(aperm(UCBAdmissions), expected = ~ (Admit + Gender) * Dept, + compress = FALSE, + labeling_args = list(abbreviate = c(Gender = TRUE), rot_labels = 0) + ) > > > > cleanEx(); ..nameEx <- "assocstats" > > ### * assocstats > > flush(stderr()); flush(stdout()) > > ### Name: assocstats > ### Title: Association Statistics > ### Aliases: assocstats summary.assocstats print.assocstats > ### print.summary.assocstats > ### Keywords: category > > ### ** Examples > > data(Arthritis) > tab <- xtabs(~Improved + Treatment, data = Arthritis) > summary(assocstats(tab)) Call: xtabs(formula = ~Improved + Treatment, data = Arthritis) Number of cases in table: 84 Number of factors: 2 Test for independence of all factors: Chisq = 13.055, df = 2, p-value = 0.001463 X^2 df P(> X^2) Likelihood Ratio 13.530 2 0.0011536 Pearson 13.055 2 0.0014626 Phi-Coefficient : 0.394 Contingency Coeff.: 0.367 Cramer's V : 0.394 > > > > cleanEx(); ..nameEx <- "co.table" > > ### * co.table > > flush(stderr()); flush(stdout()) > > ### Name: co_table > ### Title: Compute Conditional Tables > ### Aliases: co_table > ### Keywords: array > > ### ** Examples > > data(HairEyeColor) > co_table(HairEyeColor, 1) $Black Sex Eye Male Female Brown 32 36 Blue 11 9 Hazel 10 5 Green 3 2 $Brown Sex Eye Male Female Brown 38 81 Blue 50 34 Hazel 25 29 Green 15 14 $Red Sex Eye Male Female Brown 10 16 Blue 10 7 Hazel 7 7 Green 7 7 $Blond Sex Eye Male Female Brown 3 4 Blue 30 64 Hazel 5 5 Green 8 8 > co_table(HairEyeColor, c("Hair", "Eye")) $Black.Brown Sex Male Female 32 36 $Brown.Brown Sex Male Female 38 81 $Red.Brown Sex Male Female 10 16 $Blond.Brown Sex Male Female 3 4 $Black.Blue Sex Male Female 11 9 $Brown.Blue Sex Male Female 50 34 $Red.Blue Sex Male Female 10 7 $Blond.Blue Sex Male Female 30 64 $Black.Hazel Sex Male Female 10 5 $Brown.Hazel Sex Male Female 25 29 $Red.Hazel Sex Male Female 7 7 $Blond.Hazel Sex Male Female 5 5 $Black.Green Sex Male Female 3 2 $Brown.Green Sex Male Female 15 14 $Red.Green Sex Male Female 7 7 $Blond.Green Sex Male Female 8 8 > co_table(HairEyeColor, 1:2, collapse = "") $BlackBrown Sex Male Female 32 36 $BrownBrown Sex Male Female 38 81 $RedBrown Sex Male Female 10 16 $BlondBrown Sex Male Female 3 4 $BlackBlue Sex Male Female 11 9 $BrownBlue Sex Male Female 50 34 $RedBlue Sex Male Female 10 7 $BlondBlue Sex Male Female 30 64 $BlackHazel Sex Male Female 10 5 $BrownHazel Sex Male Female 25 29 $RedHazel Sex Male Female 7 7 $BlondHazel Sex Male Female 5 5 $BlackGreen Sex Male Female 3 2 $BrownGreen Sex Male Female 15 14 $RedGreen Sex Male Female 7 7 $BlondGreen Sex Male Female 8 8 > > > > cleanEx(); ..nameEx <- "coindep.test" > > ### * coindep.test > > flush(stderr()); flush(stdout()) > > ### Name: coindep_test > ### Title: Test for (Conditional) Independence > ### Aliases: coindep_test > ### Keywords: htest > > ### ** Examples > > TeaTasting <- matrix(c(3, 1, 1, 3), nr = 2, + dimnames = list(Guess = c("Milk", "Tea"), + Truth = c("Milk", "Tea")) + ) > ## compute maximum statistic > coindep_test(TeaTasting) Permutation test for conditional independence data: TeaTasting f(x) = 0.7071, p-value = 0.465 > ## compute Chi-squared statistic > coindep_test(TeaTasting, indepfun = function(x) sum(x^2)) Permutation test for conditional independence data: TeaTasting f(x) = 2, p-value = 0.465 > ## use unconditional asymptotic distribution > chisq.test(TeaTasting, correct = FALSE) Warning in chisq.test(TeaTasting, correct = FALSE) : Chi-squared approximation may be incorrect Pearson's Chi-squared test data: TeaTasting X-squared = 2, df = 1, p-value = 0.1573 > chisq.test(TeaTasting) Warning in chisq.test(TeaTasting) : Chi-squared approximation may be incorrect Pearson's Chi-squared test with Yates' continuity correction data: TeaTasting X-squared = 0.5, df = 1, p-value = 0.4795 > > data(UCBAdmissions) > ## double maximum statistic > coindep_test(UCBAdmissions, margin = "Dept") Permutation test for conditional independence data: UCBAdmissions f(x) = 3.1344, p-value < 2.2e-16 > ## maximum of Chi-squared statistics > coindep_test(UCBAdmissions, margin = "Dept", indepfun = function(x) sum(x^2)) Permutation test for conditional independence data: UCBAdmissions f(x) = 17.248, p-value < 2.2e-16 > ## Pearson Chi-squared statistic > coindep_test(UCBAdmissions, margin = "Dept", indepfun = function(x) sum(x^2), aggfun = sum) Permutation test for conditional independence data: UCBAdmissions f(x) = 19.9384, p-value = 0.002 > ## use unconditional asymptotic distribution > loglm(~ Dept * (Gender + Admit), data = UCBAdmissions) Call: loglm(formula = ~Dept * (Gender + Admit), data = UCBAdmissions) Statistics: X^2 df P(> X^2) Likelihood Ratio 21.73551 6 0.001351993 Pearson 19.93841 6 0.002840164 > > > > cleanEx(); ..nameEx <- "distplot" > > ### * distplot > > flush(stderr()); flush(stdout()) > > ### Name: distplot > ### Title: Diagnostic Distribution Plots > ### Aliases: distplot > ### Keywords: category > > ### ** Examples > > ## Simulated data examples: > dummy <- rnbinom(1000, size = 1.5, prob = 0.8) > distplot(dummy, type = "nbinomial") > > ## Real data examples: > data(HorseKicks) > data(Federalist) > data(Saxony) > distplot(HorseKicks, type = "poisson") > distplot(HorseKicks, type = "poisson", lambda = 0.61) > distplot(Federalist, type = "poisson") > distplot(Federalist, type = "nbinomial") > distplot(Saxony, type = "binomial", size = 12) > > > > cleanEx(); ..nameEx <- "doubledecker" > > ### * doubledecker > > flush(stderr()); flush(stdout()) > > ### Name: doubledecker > ### Title: Doubledecker Plot > ### Aliases: doubledecker.default doubledecker.formula doubledecker > ### Keywords: hplot > > ### ** Examples > > doubledecker(Titanic) > doubledecker(Titanic, depvar = "Survived") > doubledecker(Survived ~ ., data = Titanic) > > > > cleanEx(); ..nameEx <- "fourfold" > > ### * fourfold > > flush(stderr()); flush(stdout()) > > ### Name: fourfold > ### Title: Fourfold Plots > ### Aliases: fourfold > ### Keywords: hplot > > ### ** Examples > > data(UCBAdmissions) > ## Use the Berkeley admission data as in Friendly (1995). > x <- aperm(UCBAdmissions, c(2, 1, 3)) > dimnames(x)[[2]] <- c("Yes", "No") > names(dimnames(x)) <- c("Sex", "Admit?", "Department") > ftable(x) Department A B C D E F Sex Admit? Male Yes 512 353 120 138 53 22 No 313 207 205 279 138 351 Female Yes 89 17 202 131 94 24 No 19 8 391 244 299 317 > > ## Fourfold display of data aggregated over departments, with > ## frequencies standardized to equate the margins for admission > ## and sex. > ## Figure 1 in Friendly (1994). > fourfold(margin.table(x, c(1, 2))) > > ## Fourfold display of x, with frequencies in each table > ## standardized to equate the margins for admission and sex. > ## Figure 2 in Friendly (1994). > fourfold(x) > > ## Fourfold display of x, with frequencies in each table > ## standardized to equate the margins for admission. but not > ## for sex. > ## Figure 3 in Friendly (1994). > fourfold(x, margin = 2) > > > > cleanEx(); ..nameEx <- "goodfit" > > ### * goodfit > > flush(stderr()); flush(stdout()) > > ### Name: goodfit > ### Title: Goodness-of-fit Tests for Discrete Data > ### Aliases: goodfit summary.goodfit plot.goodfit predict.goodfit > ### fitted.goodfit print.goodfit > ### Keywords: category > > ### ** Examples > > ## Simulated data examples: > dummy <- rnbinom(200, size = 1.5, prob = 0.8) > gf <- goodfit(dummy, type = "nbinomial", method = "MinChisq") Warning in pnbinom(q, size, prob, lower.tail, log.p) : NaNs produced Warning in pnbinom(q, size, prob, lower.tail, log.p) : NaNs produced > summary(gf) Warning in summary.goodfit(gf) : Chi-squared approximation may be incorrect Goodness-of-fit test for nbinomial distribution X^2 df P(> X^2) Pearson 1.464957 1 0.226143 > plot(gf) > > dummy <- rbinom(100, size = 6, prob = 0.5) > gf1 <- goodfit(dummy, type = "binomial", par = list(size = 6)) > gf2 <- goodfit(dummy, type = "binomial", par = list(prob = 0.6, size = 6)) > summary(gf1) Goodness-of-fit test for binomial distribution X^2 df P(> X^2) Likelihood Ratio 8.518973 5 0.1298587 > plot(gf1) > summary(gf2) Warning in summary.goodfit(gf2) : Chi-squared approximation may be incorrect Goodness-of-fit test for binomial distribution X^2 df P(> X^2) Pearson 69.07257 6 6.334890e-13 Likelihood Ratio 38.11777 6 1.065353e-06 > plot(gf2) > > ## Real data examples: > data(HorseKicks) > HK.fit <- goodfit(HorseKicks) > summary(HK.fit) Goodness-of-fit test for poisson distribution X^2 df P(> X^2) Likelihood Ratio 0.8682214 3 0.8330891 > plot(HK.fit) > > data(Federalist) > F.fit <- goodfit(Federalist, type = "nbinomial") > summary(F.fit) Goodness-of-fit test for nbinomial distribution X^2 df P(> X^2) Likelihood Ratio 1.96403 4 0.7423748 > plot(F.fit) > > > > cleanEx(); ..nameEx <- "grid.barplot" > > ### * grid.barplot > > flush(stderr()); flush(stdout()) > > ### Name: grid_barplot > ### Title: Barplot > ### Aliases: grid_barplot > ### Keywords: hplot > > ### ** Examples > > grid_barplot(sample(1:6), names = letters[1:6]) > > > > cleanEx(); ..nameEx <- "grid.legend" > > ### * grid.legend > > flush(stderr()); flush(stdout()) > > ### Name: grid_legend > ### Title: Legend Function for grid Graphics > ### Aliases: grid_legend > ### Keywords: hplot > > ### ** Examples > > data(Lifeboats) > attach(Lifeboats) > ternaryplot(Lifeboats[,4:6], + pch = ifelse(side == "Port", 1, 19), + col = ifelse(side == "Port", "red", "blue"), + id = ifelse(men / total > 0.1, as.character(boat), NA), + prop_size = 2, + dimnames_position = "edge", + main = "Lifeboats on Titanic") > grid_legend(0.8, 0.9, c(1, 19), c("red", "blue"), + c("Port", "Starboard"), title = "SIDE") > > > > cleanEx(); ..nameEx <- "hls" > > ### * hls > > flush(stderr()); flush(stdout()) > > ### Name: hls > ### Title: HLS Color Specification > ### Aliases: hls > ### Keywords: hplot > > ### ** Examples > > ## an HLS color wheel > pie(rep(1, 12), col = sapply(1:12/12, function(x) hls(x))) > > > > cleanEx(); ..nameEx <- "independence.table" > > ### * independence.table > > flush(stderr()); flush(stdout()) > > ### Name: independence_table > ### Title: Independence Table > ### Aliases: independence_table > ### Keywords: category array > > ### ** Examples > > data(MSPatients) > independence_table(MSPatients) , , 1 [,1] [,2] [,3] [,4] [1,] 15.48817 10.76021 3.586735 5.706170 [2,] 19.36022 13.45026 4.483419 7.132712 [3,] 16.97742 11.79484 3.931614 6.254840 [4,] 13.10538 9.10479 3.034930 4.828297 , , 2 [,1] [,2] [,3] [,4] [1,] 7.172376 4.982914 1.660971 2.642454 [2,] 8.965470 6.228642 2.076214 3.303068 [3,] 7.862028 5.462040 1.820680 2.896536 [4,] 6.068934 4.216312 1.405437 2.235923 > independence_table(MSPatients, frequency = "relative") , , 1 [,1] [,2] [,3] [,4] [1,] 0.07104667 0.04935874 0.01645291 0.02617509 [2,] 0.08880834 0.06169843 0.02056614 0.03271886 [3,] 0.07787808 0.05410477 0.01803492 0.02869193 [4,] 0.06011641 0.04176509 0.01392170 0.02214815 , , 2 [,1] [,2] [,3] [,4] [1,] 0.03290081 0.02285740 0.007619134 0.01212135 [2,] 0.04112601 0.02857175 0.009523918 0.01515169 [3,] 0.03606435 0.02505523 0.008351743 0.01328686 [4,] 0.02783914 0.01934088 0.006446960 0.01025653 > > > > cleanEx(); ..nameEx <- "labeling.cells.list" > > ### * labeling.cells.list > > flush(stderr()); flush(stdout()) > > ### Name: labeling_cells_list > ### Title: Labeling Functions for Strucplots > ### Aliases: labeling_list labeling_cells > ### Keywords: hplot > > ### ** Examples > > mosaic(Titanic, labeling = labeling_cells) > mosaic(Titanic, labeling = labeling_list) > > ## A more complex example, adding the observed frequencies > ## to a mosaic plot: > tab <- ifelse(Titanic < 6, NA, Titanic) > mosaic(Titanic, pop = FALSE) > labeling_cells(text = tab, margin = 0)(Titanic) > > > > cleanEx(); ..nameEx <- "labeling.text" > > ### * labeling.text > > flush(stderr()); flush(stdout()) > > ### Name: labeling_text > ### Title: Labeling Functions for Strucplots > ### Aliases: labeling_text labeling_conditional labeling_left > ### labeling_cboxed labeling_lboxed labeling_doubledecker labelings > ### Keywords: hplot > > ### ** Examples > > mosaic(Titanic) > mosaic(Titanic, labeling = labeling_left) > labeling_left function (tl_labels = TRUE, clip = TRUE, pos_varnames = "left", pos_labels = "left", just_labels = "left", ...) labeling_text(tl_labels = tl_labels, clip = clip, pos_varnames = pos_varnames, pos_labels = pos_labels, just_labels = just_labels, ...) attr(,"class") [1] "panel_generator" > > mosaic(Titanic, labeling = labeling_cboxed) > labeling_cboxed function (tl_labels = TRUE, boxes = TRUE, clip = TRUE, pos_labels = "center", ...) labeling_text(tl_labels = tl_labels, boxes = boxes, clip = clip, pos_labels = pos_labels, ...) attr(,"class") [1] "panel_generator" > > mosaic(Titanic, labeling = labeling_lboxed) > labeling_lboxed function (tl_labels = FALSE, boxes = TRUE, clip = TRUE, pos_labels = "left", just_labels = "left", labbl_varnames = FALSE, ...) labeling_text(tl_labels = tl_labels, boxes = boxes, clip = clip, pos_labels = pos_labels, labbl_varnames = labbl_varnames, just_labels = just_labels, ...) attr(,"class") [1] "panel_generator" > > data(PreSex) > mosaic(~ PremaritalSex + ExtramaritalSex | Gender + MaritalStatus, + data = PreSex, + labeling = labeling_conditional) > > ## specification of vectorized arguments > mosaic(Titanic, + labeling_args = list(abbreviate = c(Survived = TRUE))) > > mosaic(Titanic, + labeling_args = list(clip = TRUE, boxes = TRUE, + fill_boxes = c(Survived = "blue","red")) + ) > > > > > cleanEx(); ..nameEx <- "legends" > > ### * legends > > flush(stderr()); flush(stdout()) > > ### Name: legends > ### Title: Legend Functions for Strucplots > ### Aliases: legends legend_resbased legend_fixed > ### Keywords: hplot > > ### ** Examples > > mosaic(Titanic, legend = legend_resbased) > mosaic(Titanic, legend = legend_fixed) > > > > cleanEx(); ..nameEx <- "mar.table" > > ### * mar.table > > flush(stderr()); flush(stdout()) > > ### Name: mar_table > ### Title: Table with Marginal Sums > ### Aliases: mar_table > ### Keywords: category > > ### ** Examples > > data(SexualFun) > mar_table(SexualFun) Wife Husband Never Fun Fairly Often Very Often Always fun TOTAL Never Fun 7 7 2 3 19 Fairly Often 2 8 3 7 20 Very Often 1 5 4 9 19 Always fun 2 8 9 14 33 TOTAL 12 28 18 33 91 > > > > cleanEx(); ..nameEx <- "mosaic" > > ### * mosaic > > flush(stderr()); flush(stdout()) > > ### Name: mosaic > ### Title: Extended Mosaic Plots > ### Aliases: mosaic mosaic.default mosaic.formula > ### Keywords: hplot > > ### ** Examples > > data(Titanic) > mosaic(Titanic) > > ## Formula interface for tabulated data plus shading and legend: > mosaic(~ Sex + Age + Survived, data = Titanic, + main = "Survival on the Titanic", shade = TRUE, legend = TRUE) > > data(HairEyeColor) > mosaic(HairEyeColor, shade = TRUE) > ## Independence model of hair and eye color and sex. Indicates that > ## there are significantly more blue eyed blond females than expected > ## in the case of independence (and too few brown eyed blond females). > > mosaic(HairEyeColor, shade = TRUE, expected = list(c(1,2), 3)) > ## Model of joint independence of sex from hair and eye color. Males > ## are underrepresented among people with brown hair and eyes, and are > ## overrepresented among people with brown hair and blue eyes, but not > ## "significantly". > > ## Formula interface for raw data: visualize crosstabulation of numbers > ## of gears and carburettors in Motor Trend car data. > data(mtcars) > mosaic(~ gear + carb, data = mtcars, shade = TRUE) > > data(PreSex) > mosaic(PreSex, condvars = c(1,4)) > mosaic(~ ExtramaritalSex + PremaritalSex | MaritalStatus + Gender, + data = PreSex) > > > > cleanEx(); ..nameEx <- "oddsratio" > > ### * oddsratio > > flush(stderr()); flush(stdout()) > > ### Name: oddsratio > ### Title: (Log) Odds Ratios > ### Aliases: oddsratio print.oddsratio summary.oddsratio confint.oddsratio > ### print.summary.oddsratio plot.oddsratio > ### Keywords: category > > ### ** Examples > > ## load Coal Miners data > data(CoalMiners) > > ## compute log odds ratios > lor <- oddsratio(CoalMiners) > lor 25-29 30-34 35-39 40-44 45-49 50-54 55-59 60-64 3.695261 3.398339 3.140658 3.014687 2.782049 2.926395 2.440571 2.637954 > > ## summary with z tests > summary(lor) Log Odds Ratio Std. Error z value Pr(>|z|) 25-29 3.69526 0.39737 9.2994 < 2.2e-16 *** 30-34 3.39834 0.27532 12.3432 < 2.2e-16 *** 35-39 3.14066 0.18209 17.2479 < 2.2e-16 *** 40-44 3.01469 0.16872 17.8678 < 2.2e-16 *** 45-49 2.78205 0.13666 20.3576 < 2.2e-16 *** 50-54 2.92640 0.12574 23.2729 < 2.2e-16 *** 55-59 2.44057 0.12036 20.2779 < 2.2e-16 *** 60-64 2.63795 0.14670 17.9820 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > ## confidence intervals > confint(lor) lwr upr 25-29 2.916439 4.474083 30-34 2.858721 3.937956 35-39 2.783769 3.497548 40-44 2.683999 3.345375 45-49 2.514202 3.049895 50-54 2.679945 3.172846 55-59 2.204677 2.676464 60-64 2.350428 2.925480 > > ## visualization > plot(lor, + xlab = "Age Group", + main = "Breathelessness and Wheeze in Coal Miners") > > ## add quadratic model > g <- seq(25, 60, by = 5) > m <- lm(lor ~ g + I(g^2)) > lines(fitted(m), col = "red") > > > > cleanEx(); ..nameEx <- "pairs.table" > > ### * pairs.table > > flush(stderr()); flush(stdout()) > > ### Name: pairs.table > ### Title: Pairs Plot for Contingency Tables > ### Aliases: pairs.table > ### Keywords: hplot > > ### ** Examples > > data(UCBAdmissions) > data(PreSex) > > pairs(PreSex) > pairs(UCBAdmissions) > pairs(UCBAdmissions, upper_panel_args = list(shade = FALSE)) > pairs(UCBAdmissions, lower_panel = pairs_mosaic(type = "conditional")) > pairs(UCBAdmissions, diag_panel = pairs_text) > pairs(UCBAdmissions, upper_panel = pairs_assoc) > > > > cleanEx(); ..nameEx <- "panel.pairs.diagonal" > > ### * panel.pairs.diagonal > > flush(stderr()); flush(stdout()) > > ### Name: Pairs plot panel functions for diagonal cells > ### Title: Diagonal Panel Functions for Table Pairs Plot > ### Aliases: pairs_barplot pairs_text > ### Keywords: hplot > > ### ** Examples > > data(UCBAdmissions) > > pairs(UCBAdmissions) # pairs_barplot is default > pairs(UCBAdmissions, diag_panel = pairs_text) > > > > cleanEx(); ..nameEx <- "panel.pairs.off-diagonal" > > ### * panel.pairs.off-diagonal > > flush(stderr()); flush(stdout()) > > ### Name: Pairs plot panel functions for off-diagonal cells > ### Title: Off-diagonal Panel Functions for Table Pairs Plot > ### Aliases: pairs_strucplot pairs_mosaic pairs_assoc > ### Keywords: hplot > > ### ** Examples > > data(UCBAdmissions) > data(PreSex) > > pairs(PreSex) > pairs(UCBAdmissions) > pairs(UCBAdmissions, upper_panel_args = list(shade = FALSE)) > pairs(UCBAdmissions, lower_panel = pairs_mosaic(type = "conditional")) > pairs(UCBAdmissions, upper_panel = pairs_assoc) > > > > cleanEx(); ..nameEx <- "plot.loglm" > > ### * plot.loglm > > flush(stderr()); flush(stdout()) > > ### Name: plot.loglm > ### Title: Visualize Fitted Log-linear Models > ### Aliases: plot.loglm assoc.loglm mosaic.loglm > ### Keywords: hplot > > ### ** Examples > > ## mosaic display for PreSex model > data(PreSex) > fm <- loglm(~ PremaritalSex * ExtramaritalSex * (Gender + MaritalStatus), + data = aperm(PreSex, c(3, 2, 4, 1))) > fm Call: loglm(formula = ~PremaritalSex * ExtramaritalSex * (Gender + MaritalStatus), data = aperm(PreSex, c(3, 2, 4, 1))) Statistics: X^2 df P(> X^2) Likelihood Ratio 5.245519 4 0.2630205 Pearson 5.238526 4 0.2636870 > ## visualize Pearson statistic > plot(fm, split_vertical = TRUE) > ## visualize LR statistic > plot(fm, split_vertical = TRUE, residuals_type = "deviance") > > ## conditional independence in UCB admissions data > data(UCBAdmissions) > fm <- loglm(~ Dept * (Gender + Admit), data = aperm(UCBAdmissions)) > > ## use mosaic display > plot(fm, labeling_args = list(abbreviate = c(Admit = 3))) > > ## and association plot > plot(fm, panel = assoc) > assoc(fm) > > > > cleanEx(); ..nameEx <- "rainbow.hcl" > > ### * rainbow.hcl > > flush(stderr()); flush(stdout()) > > ### Name: rainbow_hcl > ### Title: HCL and HSV Color Palettes > ### Aliases: rainbow_hcl diverge_hcl diverge_hsv > ### Keywords: hplot > > ### ** Examples > > pie(rep(1, 12), col = rainbow_hcl(12)) > pie(rep(1, 5), col = diverge_hcl(5)) > pie(rep(1, 5), col = diverge_hsv(5)) > > > > cleanEx(); ..nameEx <- "rootogram" > > ### * rootogram > > flush(stderr()); flush(stdout()) > > ### Name: rootogram > ### Title: Rootograms > ### Aliases: rootogram rootogram.default rootogram.goodfit > ### Keywords: hplot > > ### ** Examples > > ## Simulated data examples: > dummy <- rnbinom(200, size = 1.5, prob = 0.8) > observed <- table(dummy) > fitted1 <- dnbinom(as.numeric(names(observed)), + size = 1.5, prob = 0.8) * sum(observed) > fitted2 <- dnbinom(as.numeric(names(observed)), + size = 2, prob = 0.6) * sum(observed) > rootogram(observed, fitted1) > rootogram(observed, fitted2) > > ## Real data examples: > data(HorseKicks) > HK.fit <- goodfit(HorseKicks) > summary(HK.fit) Goodness-of-fit test for poisson distribution X^2 df P(> X^2) Likelihood Ratio 0.8682214 3 0.8330891 > plot(HK.fit) > ## or equivalently > rootogram(HK.fit) > > data(Federalist) > F.fit <- goodfit(Federalist, type = "nbinomial") > summary(F.fit) Goodness-of-fit test for nbinomial distribution X^2 df P(> X^2) Likelihood Ratio 1.96403 4 0.7423748 > plot(F.fit) > > > > cleanEx(); ..nameEx <- "shadings" > > ### * shadings > > flush(stderr()); flush(stdout()) > > ### Name: shadings > ### Title: Shading-generating Functions for Residual-based Shadings > ### Aliases: shadings shading_hsv shading_hcl shading_max shading_Friendly > ### shading_binary > ### Keywords: hplot > > ### ** Examples > > ## load Arthritis data > data(Arthritis) > art <- xtabs(~Treatment + Improved, data = Arthritis) > > ## plain mosaic display without shading > mosaic(art) > > ## with shading for independence model > mosaic(art, shade = TRUE) > ## which uses the HCL shading > mosaic(art, gp = shading_hcl) > ## the residuals are two small to have color, > ## hence the cut-offs can be modified > mosaic(art, gp = shading_hcl, gp_args = list(interpolate = c(1, 1.8))) > ## the same with the Friendly palette > ## (without significance testing) > mosaic(art, gp = shading_Friendly, gp_args = list(interpolate = c(1, 1.8))) > > ## assess independence using the maximum statistic > ## cut-offs are now critical values for the test statistic > mosaic(art, gp = shading_max) > > ## association plot with shading as in base R > assoc(art, gp = shading_binary(col = c(1, 2))) > > > > cleanEx(); ..nameEx <- "sieveplot" > > ### * sieveplot > > flush(stderr()); flush(stdout()) > > ### Encoding: latin1 > > ### Name: sieveplot > ### Title: Sieve Plots > ### Aliases: sieveplot sieveplot.default sieveplot.formula > ### Keywords: category hplot > > ### ** Examples > > data(HairEyeColor) > > ## aggregate over 'sex': > (tab <- margin.table(HairEyeColor, c(2,1))) Hair Eye Black Brown Red Blond Brown 68 119 26 7 Blue 20 84 17 94 Hazel 15 54 14 10 Green 5 29 14 16 > > ## plot expected values: > sieveplot(tab, type = "expected", values = "both") > > ## plot sieve diagram: > sieveplot(tab) > > ## an example for the formula interface: > data(VisualAcuity) > sieveplot(Freq ~ right + left, data = VisualAcuity, reverse_y = FALSE) > > > > cleanEx(); ..nameEx <- "spacings" > > ### * spacings > > flush(stderr()); flush(stdout()) > > ### Name: spacings > ### Title: Spacing-generating Functions > ### Aliases: spacings spacing_doubledecker spacing_equal spacing_dimequal > ### spacing_increase spacing_conditional > ### Keywords: hplot > > ### ** Examples > > strucplot(Titanic, spacing = spacing_increase(start = 0.5, rate = 1.5)) > strucplot(Titanic, spacing = spacing_equal(1)) > strucplot(Titanic, spacing = spacing_dimequal(1:4 / 4)) > data(PreSex) > strucplot(aperm(PreSex, c(1,4,2,3)), spacing = spacing_conditional, + condvars = 2) > > > > cleanEx(); ..nameEx <- "spineplot" > > ### * spineplot > > flush(stderr()); flush(stdout()) > > ### Name: spineplot > ### Title: Spineplots > ### Aliases: spineplot spineplot.default spineplot.formula > ### Keywords: htest > > ### ** Examples > > ## Arthritis data (dependence on a categorical variable) > data(Arthritis) > (spineplot(Improved ~ Treatment, data = Arthritis)) Treatment Placebo Treated Improved None 29 13 Some 7 7 Marked 7 21 > > ## Space shuttle data (dependence on a numerical variable) > data(SpaceShuttle) > (spineplot(Fail ~ Temperature, data = SpaceShuttle)) Temperature [53,67] (67,70] (70,75] (75,81] Fail no 4 4 3 5 yes 4 2 1 0 > > > > cleanEx(); ..nameEx <- "strucplot" > > ### * strucplot > > flush(stderr()); flush(stdout()) > > ### Name: strucplot > ### Title: Structured Displays of Contingency Tables > ### Aliases: strucplot > ### Keywords: hplot > > ### ** Examples > > strucplot(Titanic) > strucplot(Titanic, panel = struc_assoc) > strucplot(Titanic, spacing = spacing_increase, + spacing_args = list(start = 0.5, rate = 1.5)) > strucplot(Titanic, spacing = spacing_increase(start = 0.5, rate = 1.5)) > > ## modify a tile's color > strucplot(Titanic, pop = FALSE) > grid.edit("rect..Class.1st..Sex.Male..Age.Adult..Survived.Yes", + gp = gpar(fill = "red")) > > > > cleanEx(); ..nameEx <- "structable" > > ### * structable > > flush(stderr()); flush(stdout()) > > ### Name: structable > ### Title: Structured Contingency Tables > ### Aliases: structable.default structable.formula structable > ### Keywords: hplot > > ### ** Examples > > structable(Titanic) Sex Male Female Survived No Yes No Yes Class Age 1st Child 0 5 0 1 Adult 118 57 4 140 2nd Child 0 11 0 13 Adult 154 14 13 80 3rd Child 35 13 17 14 Adult 387 75 89 76 Crew Child 0 0 0 0 Adult 670 192 3 20 > structable(Titanic, split_vertical = c(TRUE, TRUE, FALSE, FALSE)) Class 1st 2nd 3rd Crew Sex Male Female Male Female Male Female Male Female Age Survived Child No 0 0 0 0 35 17 0 0 Yes 5 1 11 13 13 14 0 0 Adult No 118 4 154 13 387 89 670 3 Yes 57 140 14 80 75 76 192 20 > structable(Titanic, direction = c("h","h","v","v")) Age Child Adult Survived No Yes No Yes Class Sex 1st Male 0 5 118 57 Female 0 1 4 140 2nd Male 0 11 154 14 Female 0 13 13 80 3rd Male 35 13 387 75 Female 17 14 89 76 Crew Male 0 0 670 192 Female 0 0 3 20 > structable(Sex + Class ~ Survived + Age, data = Titanic) Sex Male Female Class 1st 2nd 3rd Crew 1st 2nd 3rd Crew Survived Age No Child 0 0 35 0 0 0 17 0 Adult 118 154 387 670 4 13 89 3 Yes Child 5 11 13 0 1 13 14 0 Adult 57 14 75 192 140 80 76 20 > > > > cleanEx(); ..nameEx <- "table2d.summary" > > ### * table2d.summary > > flush(stderr()); flush(stdout()) > > ### Name: table2d_summary > ### Title: Summary of a 2-way Table > ### Aliases: table2d_summary print.table2d_summary > ### Keywords: category > > ### ** Examples > > data(UCBAdmissions) > table2d_summary(margin.table(UCBAdmissions, 1:2)) Gender Admit Male Female TOTAL Admitted 1198 557 1755 Rejected 1493 1278 2771 TOTAL 2691 1835 4526 Number of cases in table: 4526 Number of factors: 2 Test for independence of all factors: Chisq = 92.21, df = 1, p-value = 7.814e-22 > > > > cleanEx(); ..nameEx <- "ternaryplot" > > ### * ternaryplot > > flush(stderr()); flush(stdout()) > > ### Name: ternaryplot > ### Title: Ternary Diagram > ### Aliases: ternaryplot > ### Keywords: hplot > > ### ** Examples > > data(Arthritis) > > ## Build table by crossing Treatment and Sex > tab <- as.table(xtabs(~ I(Sex:Treatment) + Improved, data = Arthritis)) > > ## Mark groups > col <- c("red", "red", "blue", "blue") > pch <- c(1, 19, 1, 19) > > ## plot > ternaryplot( + tab, + col = col, + pch = pch, + prop_size = TRUE, + bg = "lightgray", + grid_color = "white", + labels_color = "white", + main = "Arthritis Treatment Data" + ) > ## legend > grid_legend(0.8, 0.7, pch, col, rownames(tab), title = "GROUP") > > ## Titanic > data(Lifeboats) > attach(Lifeboats) > ternaryplot( + Lifeboats[,4:6], + pch = ifelse(side == "Port", 1, 19), + col = ifelse(side == "Port", "red", "blue"), + id = ifelse(men / total > 0.1, as.character(boat), NA), + prop_size = 2, + dimnames_position = "edge", + main = "Lifeboats on Titanic" + ) > grid_legend(0.8, 0.9, c(1, 19), + c("red", "blue"), c("Port", "Starboard"), + title = "SIDE") > > ## Hitters > data(Hitters) > attach(Hitters) > colors <- c("black","red","green","blue","red","black","blue") > pch <- substr(levels(Positions), 1, 1) > ternaryplot( + Hitters[,2:4], + pch = as.character(Positions), + col = colors[as.numeric(Positions)], + main = "Baseball Hitters Data" + ) > grid_legend(0.8, 0.9, pch, colors, levels(Positions), + title = "POSITION(S)") > > > > > cleanEx(); ..nameEx <- "woolf.test" > > ### * woolf.test > > flush(stderr()); flush(stdout()) > > ### Name: woolf_test > ### Title: Woolf Test > ### Aliases: woolf_test > ### Keywords: htest > > ### ** Examples > > data(CoalMiners) > woolf_test(CoalMiners) Woolf-test on Homogeneity of Odds Ratios (no 3-Way assoc.) data: CoalMiners X-squared = 25.6137, df = 7, p-value = 0.0005903 > > > > ### *