library(descr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)

load("Datasets/gss98.RData")
CrossTable(gss98$CAPPUN, gss98$SEX, prop.r = T, prop.c = T, prop.t = T, prop.chisq = F, format = "SPSS")
##    Cell Contents 
## |-------------------------|
## |                   Count | 
## |             Row Percent | 
## |          Column Percent | 
## |           Total Percent | 
## |-------------------------|
## 
## ======================================
##                 gss98$SEX
## gss98$CAPPUN    female    male   Total
## --------------------------------------
## Favor             348     309     657 
##                  53.0%   47.0%   71.6%
##                  67.1%   77.4%        
##                  37.9%   33.7%        
## --------------------------------------
## Oppose            171      90     261 
##                  65.5%   34.5%   28.4%
##                  32.9%   22.6%        
##                  18.6%    9.8%        
## --------------------------------------
## Total             519     399     918 
##                  56.5%   43.5%        
## ======================================
  #a) Calculate the row, column, and total percentages for the first row, checking your answers against the computer output.
    #(348/657) x 100 = 53%
    #(309/657) x 100 = 47%

    #(348/519) x 100 = 67.1%
    #(309/399) x 100 = 77.4%

    #(348/918) x 100 = 37.9%
    #(309/918) x 100 = 33.7%
  #b) Give brief explanations of the nine percentages in the first row (e.g., 53.0 percent of the ________ are _______).
    #Of the people that favor capital punishment, 53% are females
    #Of the people that favor capital punishment, 47% are males.
    
    #The females that favor capital punishment are 67.1% of all females valid responses
    #The males that favor capital punishment are 77.4% of all males valid responses

    #The total percentage of people who gave valid responses and favor capital punishment is 71.6%
    

  #c) What percentage of the men oppose capital punishment for murder?
    #22.6%
  
  #d) What percentage of the women oppose capital punishment for murder?
    #32.9%
  
  #e) What percentage of those who oppose capital punishment for murder are men?
    #34.5%
  
  #f) What percentage of those who oppose capital punishment for murder are women?
    #65.5%

  #g) What percentage of the entire group are men?
    #43.5%
  
  #h) What percentage of the entire group oppose capital punishment for murder? 
    #28.4%
  
  #i) What percentage of the entire group are men who oppose capital punishment for murder?