perceptions

references:
- ISI, example 5.1, p.261

library(tidyverse)

data

perceptions <- read.delim("GoodandBad1.txt", header = TRUE)
str(perceptions)
## 'data.frame':    30 obs. of  2 variables:
##  $ Wording   : Factor w/ 2 levels "badyear","goodyear": 2 2 1 2 2 1 2 2 2 1 ...
##  $ Perception: Factor w/ 2 levels "negative","positive": 2 1 2 2 1 2 2 2 2 1 ...
tbl <- perceptions %>%
  group_by(Wording, Perception) %>%
  summarize(n = n())
tbl
## # A tibble: 4 x 3
## # Groups:   Wording [?]
##    Wording Perception     n
##     <fctr>     <fctr> <int>
## 1  badyear   negative     8
## 2  badyear   positive     4
## 3 goodyear   negative     3
## 4 goodyear   positive    15

contingency table

tbl2 <- c(15, 3, 4, 8)
dim(tbl2) <- c(2, 2)
dimnames(tbl2) <- list(perception = c("pos", "neg"),
                       wording = c("good.year", "bad.year"))
tbl2
##           wording
## perception good.year bad.year
##        pos        15        4
##        neg         3        8

mosaicplot

mosaicplot(t(tbl2), col = c("yellow", "green"), main = "Perceptions")