# NOT RUN {
require("ggplot2")
# load data
data("immigration")
immigration$contest_no <- factor(immigration$contest_no)
# calculate MMs
d1 <- mm(immigration, ChosenImmigrant ~ Gender + Education +
LanguageSkills + CountryOfOrigin + Job + JobExperience +
JobPlans + ReasonForApplication + PriorEntry, id = ~ CaseID)
# plot MMs
## simple plot
(p <- plot(d1, vline = 0.5))
## gridlines to aid interpretation
p + ggplot2::theme_grey()
## monochrome bars
p + scale_color_manual(values = rep("black", 9))
## plot with estimates shown as text labels
p + ggplot2::geom_text(
aes(label = sprintf("%0.2f (%0.2f)", estimate, std.error)),
colour = "black", position = position_nudge(y = .5)
)
## plot with facetting by feature
plot(d1, feature_headers = FALSE) +
ggplot2::facet_wrap(~feature, ncol = 1L,
scales = "free_y", strip.position = "right")
# MMs split by profile number
stacked <- cj(immigration, ChosenImmigrant ~ Gender +
Education + LanguageSkills + CountryOfOrigin + Job + JobExperience +
JobPlans + ReasonForApplication + PriorEntry, id = ~ CaseID,
estimate = "mm", by = ~ contest_no)
## plot with grouping
plot(stacked, group = "contest_no", feature_headers = FALSE)
## plot with facetting
plot(stacked) + ggplot2::facet_wrap(~contest_no, nrow = 1L)
## plot with shapes instead of colors for groups
plot(stacked, group = "contest_no", vline = 0.5) +
aes(shape = contest_no) + # map group to `shape` aesthetic
scale_shape_manual(values=c(1, 2, 3, 4, 5)) +
scale_colour_manual(values=rep("black", 5))
# estimate AMCEs over different subsets of data
reasons12 <- subset(
immigration, ReasonForApplication %in% levels(ReasonForApplication)[1:2]
)
d2_1 <- cj(immigration, ChosenImmigrant ~ CountryOfOrigin, id = ~ CaseID)
d2_2 <- cj(reasons12, ChosenImmigrant ~ CountryOfOrigin, id = ~ CaseID,
feature_labels = list(CountryOfOrigin = "Country Of Origin"))
d2_1$reasons <- "1,2,3"
d2_2$reasons <- "1,2"
plot(rbind(d2_1, d2_2), group = "reasons")
# }
Run the code above in your browser using DataLab