Library
library(descr)
## Warning: package 'descr' was built under R version 3.6.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.6.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.6.3
Load Data
load("C:/Users/chenk/OneDrive/Documents/Spring 2020/PMAP 4041/Datasets/Class8set/gss98.Rdata")
View dataset details
str(gss98)
## 'data.frame': 1000 obs. of 50 variables:
## $ X.1 : int 1 2 3 4 5 6 7 8 9 10 ...
## $ X : int 1 2 3 4 5 6 7 8 9 10 ...
## $ SEX : Factor w/ 2 levels "female","male": 2 2 1 1 2 2 1 1 2 2 ...
## $ RACE : Factor w/ 3 levels "Black","Other",..: 3 3 3 2 3 3 3 3 3 3 ...
## $ RELIG : Factor w/ 5 levels "Catholic","Jewish",..: 5 1 5 1 5 5 5 5 5 5 ...
## $ FUND : Factor w/ 3 levels "fundamentalist",..: 2 3 1 3 1 1 3 2 2 1 ...
## $ MARITAL : Factor w/ 5 levels "Divorced","Married",..: 2 3 1 5 2 2 3 1 1 2 ...
## $ ATTEND : Factor w/ 9 levels "2-3 TIMES MONTH",..: 2 7 6 6 2 1 6 7 9 3 ...
## $ PREMARSX: Factor w/ 4 levels "Always wrong",..: 1 4 NA NA NA 1 NA NA NA 4 ...
## $ XMARSEX : Factor w/ 4 levels "Always wrong",..: NA NA 1 3 1 1 1 1 1 NA ...
## $ HOMOSEX : Factor w/ 4 levels "Always wrong",..: NA NA NA 1 1 1 3 NA 1 NA ...
## $ TEENSEX : Factor w/ 4 levels "Always wrong",..: 1 3 3 NA NA 1 NA NA 1 1 ...
## $ ABANY : Factor w/ 2 levels "No","Yes": NA NA 2 2 1 1 2 2 2 NA ...
## $ CAPPUN : Factor w/ 2 levels "Favor","Oppose": NA 1 1 1 1 1 1 1 2 1 ...
## $ GUNLAW : Factor w/ 2 levels "Favor","Oppose": NA NA 2 1 1 1 2 1 1 NA ...
## $ GRASS : Factor w/ 2 levels "Should","Should not": 2 1 NA 2 2 NA 2 2 NA 2 ...
## $ PRAYER : Factor w/ 2 levels "Approve","Disapprove": 2 1 2 NA NA 1 NA NA 2 1 ...
## $ NATCITY : Factor w/ 3 levels "Too little","About right",..: NA NA 2 NA NA 3 NA NA NA NA ...
## $ NATHEAL : Factor w/ 3 levels "Too little","About right",..: NA NA 2 NA NA 3 NA NA NA NA ...
## $ NATCRIME: Factor w/ 3 levels "Too little","About right",..: NA NA 1 NA NA 3 NA NA NA NA ...
## $ NATDRUG : Factor w/ 3 levels "Too little","About right",..: NA NA 1 NA NA 2 NA NA NA NA ...
## $ NATEDUC : Factor w/ 3 levels "Too little","About right",..: NA NA 1 NA NA 1 NA NA NA NA ...
## $ NATRACE : Factor w/ 3 levels "Too little","About right",..: NA NA 3 NA NA 2 NA NA NA NA ...
## $ NATFARE : Factor w/ 3 levels "Too little","About right",..: NA NA 2 NA NA 2 NA NA NA NA ...
## $ NATROAD : Factor w/ 3 levels "Too little","About right",..: 2 2 1 3 1 2 1 2 1 3 ...
## $ NATMASS : Factor w/ 3 levels "Too little","About right",..: 1 3 1 3 2 2 1 2 1 2 ...
## $ CONCLERG: Factor w/ 3 levels "great confidence",..: 2 2 NA 1 2 NA 1 2 NA 2 ...
## $ CONEDUC : Factor w/ 3 levels "great confidence",..: 3 2 NA 2 1 NA 1 2 NA 2 ...
## $ CONFED : Factor w/ 3 levels "great confidence",..: 3 3 NA 2 2 NA 1 1 NA 3 ...
## $ CONPRESS: Factor w/ 3 levels "great confidence",..: 3 2 NA 2 2 NA 1 3 NA 2 ...
## $ CONJUDGE: Factor w/ 3 levels "great confidence",..: 2 2 NA 1 1 NA 2 1 NA 2 ...
## $ CONLEGIS: Factor w/ 3 levels "great confidence",..: 2 2 NA 2 2 NA 1 2 NA 2 ...
## $ FECHLD : Factor w/ 4 levels "Strongly agree",..: 4 2 2 NA NA 3 NA NA 2 3 ...
## $ FEHELP : Factor w/ 4 levels "Strongly agree",..: 4 3 3 NA NA 3 NA NA 3 3 ...
## $ FEPRESCH: Factor w/ 4 levels "Strongly agree",..: 2 2 3 NA NA 3 NA NA 2 1 ...
## $ FEFAM : Factor w/ 4 levels "Strongly agree",..: 2 3 3 NA NA 2 NA NA 2 1 ...
## $ RACDIF1 : Factor w/ 2 levels "No","Yes": 2 1 1 NA NA 1 NA NA 1 1 ...
## $ LIVEBLKS: Factor w/ 5 levels "Very Much Favor",..: 3 3 4 NA NA 2 NA NA 5 4 ...
## $ MARBLK : Factor w/ 5 levels "Very Much Favor",..: 3 3 5 NA NA 5 NA NA 3 5 ...
## $ DISCAFF : Factor w/ 3 levels "Very likely",..: NA NA 2 NA 1 2 1 3 1 NA ...
## $ PARTY : Factor w/ 3 levels "Democrat","Independent",..: 2 3 1 2 3 2 2 3 3 2 ...
## $ IDEOLOGY: Factor w/ 3 levels "liberal","moderate",..: 3 1 2 3 3 3 2 2 1 2 ...
## $ AGESUM : Factor w/ 4 levels "18 to 29","30 to 44",..: 2 1 2 2 2 4 2 4 3 4 ...
## $ INCOME : Factor w/ 4 levels "$20,000 to $34,999",..: 3 2 1 NA 3 NA NA 1 NA NA ...
## $ EDUC2 : Factor w/ 4 levels "less than h.s. diploma",..: 2 2 3 1 4 4 3 3 4 2 ...
## $ REGION2 : Factor w/ 4 levels "North Central",..: 3 3 3 3 3 3 3 3 3 3 ...
## $ CITY : Factor w/ 4 levels "central city (top 100)",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ RURAL : int 0 0 0 0 0 0 0 0 0 0 ...
## $ PROT : int 1 0 1 0 1 1 1 1 1 1 ...
## $ NEWFUND : int 1 NA 3 NA 3 3 NA 1 1 3 ...
names(gss98)
## [1] "X.1" "X" "SEX" "RACE" "RELIG" "FUND"
## [7] "MARITAL" "ATTEND" "PREMARSX" "XMARSEX" "HOMOSEX" "TEENSEX"
## [13] "ABANY" "CAPPUN" "GUNLAW" "GRASS" "PRAYER" "NATCITY"
## [19] "NATHEAL" "NATCRIME" "NATDRUG" "NATEDUC" "NATRACE" "NATFARE"
## [25] "NATROAD" "NATMASS" "CONCLERG" "CONEDUC" "CONFED" "CONPRESS"
## [31] "CONJUDGE" "CONLEGIS" "FECHLD" "FEHELP" "FEPRESCH" "FEFAM"
## [37] "RACDIF1" "LIVEBLKS" "MARBLK" "DISCAFF" "PARTY" "IDEOLOGY"
## [43] "AGESUM" "INCOME" "EDUC2" "REGION2" "CITY" "RURAL"
## [49] "PROT" "NEWFUND"
Abbreviation meanings
GSS98 < - this link will lead to a pdf download for the list of variable meanings
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%
## ======================================
How to calculate the first percentage?
The first percentage in the first column that reads 53.0% which is the row percentage which examines the percentage of row margin (row total) in the particular cell.
To do determine this value simply we take 348 (females that favor capital punishment) and divide that by 657 (total number of people that favor capital punishment). (348/657) = 53.0%
In the second column (male), we do the same process by taking 309 which is the total amount of males that responded in favor of capital punishment and to achieve this we divide that by the total amount of people that favor capital punishment which is 657. (309 / 657) = 47.0%
The first column and second column row margin should equal to 100% as this examines the row total when you add it across, example 53% (females for cappun) + 47% (males for cappun) = 100% (females and males for cappun)
Second percentage?
The second percentage on the first column is 67.0% which represents the column precentage which measures all the observations in that column or column margin, in that particular cell. To find the value of 67.0%, we take 348 which is the first frequency of the column which represents in this scenario the amount of females that favor capital punishment and then we take the total amount in the column which is females in this case or 519 and divide the values. (348/519) = 67.0%
In the second column (male), we do the same process as before, which in this case the total amount of males that favor capital punishment is 309 and the total amount of male respondents in the survey is 399 then we divide the values. (309/399) = 77.4%
Third percentage?
The third pecentage on the first column is 37.9% which represents the total percentage or the percentage of all observations in the table, which in this case refers to the people in this cell over the total amount of observations in the study (observations and respondents are interchangeable in this case to mean individuals that have participated in this study).
To find the percentage of 37.9%, we first take value of 348 which is females who favor capital punishment and divide it by the total number of respondents in the study which is 918. (348 / 918) = 37.9%
In the second column (male), we do the same process as above, we take 309 which is males who favor capital punishment and then divide it by the total number of respondents in the study which is 918. (309 / 918) = 33.7%.
======================================
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%
======================================
1. 53.0% of those that favor capital punishment are female. (row)
2. 67.1% of those that are female favor capital punishment. (column)
3. 37.9% of those that are female and favor capital punishment out of all respondents. (total)
4. 47.0% of those that favor capital punishment are male. (row)
5. 77.4% of those that are male favor capital punishment. (column)
6. 33.7% of those that are male and favor capital punishment out of all respondents. (total)
7. 71.6% of those that favor capital punishment.(total in favor)
8. 56.5% of those that responded are females.(total of females)
9. 43.5% of those that responded are males. (total of males)
This percentage asks for the column percentage which examines the male column first (explantory variable) and then examines the oppose row (response variable)
To find the percentage, we take 90 (total respondents that oppose cappun are males) and divide it by 399 (total respondents that are males) which is 22.6%.
This percentage asks for the columns percentage which wxamines the female column first and then examines the oppose row.
To find the percentage, we take 171 (total respondents that oppose cappun are females) and divide it by 519 (total respondents that are females) which is 32.9%.
This percentage asks for the row percentage which examines the oppose row first (reponse variable) and then examines the male column (explantory variable)
To find the percentage, we take 90 (total respondents that oppose cappun are males) and divide it by 261 (total respondents that oppose cappun) which is 34.5%.
This percentage asks for the row percentage which examines the oppose row first and then examines the female column.
To find the percentage, we take 171 (total respondents that oppose cappun are females) and divide it by 261 (total respondents that oppose cappun) which is 65.5%.
This percentage asks for the row percentage of males (explantory variable) out of total respondents.
To find this value, we take 399 (total respondents that are males) and divide it by 918 (total respondents for the survey) which is 43.5%.
This percentage asks for the total row percentage which examines the percentages in which both males and females oppose capital punishment, which firstly we examine the total amount of people that oppose cappun then we examine the total amount of respondents.
To find the value, we take 261 (total respondents that opposed cappun) and divide it by 918 (total respondents in the survey) which is 28.4%.
This percentage asks for the total percentage of all males that oppose cappun, in which we examine the total amount of males that oppose cappun and then we examine the total amount of respondents.
To find the value, we take 90 (total respondents that are males and oppose cappun) and divide it by 918 (total respondents in the survey) which is 9.8%.