--- title: "2019 CES Anaysis" author: "Shijia Yu" date: 2020-09-25T21:13:14-05:00 bibliography: "references.bib" categories: ["R"] tags: ["R Markdown", "plot", "regression"] ---
The paper is based on some findings of the 2019 Canadian Election Survey’s data. Two variables ‘income’ and ‘religion’ are picked to do some detailed analysis and graphing. The result can be used to estimate some characteristics for the whole population. Some limitations and weaknesses are also existed and listed in the end.
In this paper, we use 2019 Canadian Election Survey as our dataset. The dataet records 37882 observations with 22 variables which display various information of each tested person. Two variables ‘income’ and ‘religion’ are selected to do related analysis. I find out the distribution of the religion in the survey sample is definitely not homogeneous. The average income is higher than the median of the income which represents skewness of the income distribution. There are also many outliers in the ‘income’ variable that will have extreme effect on the population parameter’s estimation. In order to find out more, I plotted a bar chart for the sample’s religion distribution and a histogram for income distribution. After observing the graphs, I generate some conclusions which can be used to estimate the population. The detailed discussions can be seen in the ‘Discussion’ section. The outline of the paper is: First, I introduce the 2019 Canadian Election Survey dataset and select specific variables that I will discuss. Second, I generate some summary statistics and two graphs and have some interesting findings. Third, I discuss the graphs that I plotted and explain my observations. The last but not the least, I listed some limitations and weaknesses of the survey sample.
# install.packages("devtools")
# devtools::install_github("hodgettsp/cesR")
cesR::get_decon()
## TO CITE THIS SURVEY FILE: Stephenson, Laura B; Harell, Allison; Rubenson, Daniel; Loewen, Peter John, 2020, '2019 Canadian Election Study - Online Survey',
## https://doi.org/10.7910/DVN/DUS88V, Harvard Dataverse, V1
## LINK: https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/DUS88V
The CES dataset generates the result of the survey for 2019 Canadian Election. The online survey result contains 37822 observations with 22 variables including information of citizenship, year of birth, gender, province_territory, education, Ir, religion, sexuality, language, employment, income, marital status, economics effect on the people. The following table shows a format of the decon dataset and some possible response from the interviewees.
head(decon)
## # A tibble: 6 x 22
## ces_code citizenship yob gender province_territ… education lr lr_bef
## <chr> <fct> <fct> <fct> <fct> <fct> <chr> <chr>
## 1 ces2019… Canadian c… 1989 A wom… Quebec Master's… 2 <NA>
## 2 ces2019… Canadian c… 1998 A wom… Quebec Master's… 2 <NA>
## 3 ces2019… Canadian c… 2000 A wom… Ontario Some uni… 4 4
## 4 ces2019… Canadian c… 1998 A man Ontario Some uni… 7 7
## 5 ces2019… Canadian c… 2000 A wom… Ontario Complete… 4 4
## 6 ces2019… Canadian c… 1999 A wom… Ontario Some uni… 4 4
## # … with 14 more variables: lr_aft <chr>, religion <fct>,
## # sexuality_selected <fct>, sexuality_text <chr>, language_eng <fct>,
## # language_fr <fct>, language_abgl <fct>, employment <fct>, income <dbl>,
## # income_cat <fct>, marital <fct>, econ_retro <fct>, econ_fed <fct>,
## # econ_self <fct>
#visdat::vis_dat(decon)
#skimr::skim(decon)
#class(decon$ces_code)
decon <-
decon %>%
filter(income < 1000000)#select observations
decon <-
decon %>%
select(religion, income)#select variables
decon %>% summarise(mean_income = mean(income), sd_income = sd(income), min_income = min(income),
max_income = max(income), median_income = median(income))
## # A tibble: 1 x 5
## mean_income sd_income min_income max_income median_income
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 84318. 68724. 0<PHONE_NUMBER>0
22 variables are too many and some of them will not be taken into consideration. Therefore, the variables we focus on for this paper are just ‘religion’ and ‘income’. We hope to plot some graphs based on these two variables and analyze the corresponding findings.’Religion’ is a categorical variable while ‘income’ is a numeric variable. Since there are some people who did not want to disclose their income or there are some error such as input mistakes, we need to filter all the observations and select the ones with an income less than 1000000. Therefore, we form a subset with only two variables ‘religion’ and ‘income’ in the end and all the responses for the income are reasonable.
Here are some summary statistics for ‘income’: as we can see in the one-row table, the average income, standard deviation of the income, minimum and maximum income, and median number are clearly listed. We then can have a brief overview of some attributes and distribution of the income range of 2019 Canadian Election voting people.
In the next steps, we will generate some graphs based on ‘religion’ and ‘income’ to see some characristics in details.
decon %>%
ggplot(aes(x = religion)) +
geom_bar() + coord_flip()#categorical data
decon %>%
ggplot(aes(x = income)) +
geom_histogram() +
labs(x = "Income",
y = "Number",
title = "Distribution of income in 2019 CES",
caption = "Source: Stephenson, Harell, Rubenson, Loewen, 2020.") +
theme_bw()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
The first graph generates all the religions in the survey sample with the respective number of the people who are in that religion. As we can see, Catholic/Roman Catholic/RC contains over 7000 people in this survey sample which is the largest religion among all the people tested.In addition, almost 7000 people don’t have a religion. The finding is over 50% of the people in the survey sample are without religion or Catholic. We can also roughly calculate the proportion of Canadian people who have a religion in Catholic is 27.4%, Canadian people who don’t have a religion take up approximately 28%. After having this observation, we may estimate population proportion of religion according to the sample proportion.
The second graph shows distribution of income in 2019 Canadian Election Survey. As we can see in the histogram, the income range of the sample is mainly distributed in 0–250000. The median of the income is 72000 and the average sample income is 84317.88. My finding is that the average is greater than the median, therefore, the data is heavily skewed on the range of less than the mean which is left-skewed. We can also conclude that most people’s incomes are approximately in the range of 70000 to 85000.
Another finding of the second graph is that there are around 1800 people in the sample without income. This situation can indicate that there are around 7% of Canadian Citizen in the population not having income. In addition, there are also some outliers of income over 250000, and they will affect the average level of income in the sample and may result in bias when doing estimations for the population.
The records with no-response or unreasonable response for the income will reduce the sample size because these observations are deleted. This will definitely affect the accuracy of the result and may affect the distribution of other variables such as ‘religion’.
My weaknesses are that the sample size is not big enough to correctly estimate the situation for the whole population. The population of Canada in 2019 is 37.59 million while the sample size after deleting no-response and unreasonable responses is 25505.It may be biased and cannot be considered as an sufficient and accurate evidence for population income and religion prediction. Therefore, a bigger sample is needed and it’s better to know in which method the sampling is conducted to see whether the sample can properly represent the population.
-Hadley Wickham, Jim Hester and Winston Chang (2020). devtools: Tools to Make Developing R Packages Easier. https://devtools.r-lib.org/, https://github.com/r-lib/devtools.
-JJ Allaire and Yihui Xie and Jonathan McPherson and Javier Luraschi and Kevin Ushey and Aron Atkins and Hadley Wickham and Joe Cheng and Winston Chang and Richard Iannone (2020). rmarkdown: Dynamic Documents for R. R package version 2.3. URL https://rmarkdown.rstudio.com.
-Yihui Xie and J.J. Allaire and Garrett Grolemund (2018). R Markdown: The Definitive Guide. Chapman and Hall/CRC. ISBN<PHONE_NUMBER>338. URL https://bookdown.org/yihui/rmarkdown.