Survey responses of political affiliation and recognition as an environmentalist with chi-square analysis

This script analyzes the association between respondents’ political affiliation (coined “conservative” or “liberal” by self-identification) and if they consider themself an environmentalist, followed by a chi-square test for independence.

code
analysis
chi-square
Author

Elmera Azadpour

Published

February 23, 2021

Load packages

library(tidyverse)
library(here)
library(janitor)
library(broom)
library(kableExtra)

To access data, html and Rmd/qmd files:

  • the survey data can be found in the data folder of this repo; the Rmd and html files, denoted as a6-task2, can be found in the src folder
  • the qmd format can be found here

Introduction:

This task analyzes the association between respondents’ political affiliation (coined “conservative” or “liberal” by self-identification) and if they consider themself an environmentalist. The variables in the dataset (conservation_survey.csv) I have used include:

  • env_id: response to survey statement “I consider myself an environmentalist,” with outcomes 1 = Yes, 2 = No, 3 = Unsure
  • pol_or: response to survey question “How do you self-identify politically?” Response values 1 - 3 are “conservative” (strongly to slightly), and values 5 - 7 are “liberal” (slightly to strongly).
## Read in survey data 
survey <- read_csv(here("posts", "2021-02-23-chisquare-politcal", "conservation_survey.csv"))
Rows: 1331 Columns: 95
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (1): DBCODE
dbl (94): ENTITY, QUALTRICSID, TIME, GEND, AGE, AGE_RANGE, INCO, EDU, RACE, ...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## only keep variables: 'env_id' and 'pol_or'
survey_clean <- survey %>% 
  clean_names() %>% 
  dplyr::select(env_id, pol_or) %>% 
  mutate(party = case_when(
    between(pol_or, 1,3) ~ "conservative",
    between(pol_or, 5,7) ~ "liberal",
    TRUE ~ NA_character_))

survey_environmentalist <- survey_clean %>%  
  mutate(environmentalist = case_when(
   env_id == 1 ~ "yes",
   env_id == 2 ~ "no",
   env_id == 3 ~ "unsure"))
## Finalized table that shows counts and proportions of "liberal" and "conservative" survey respondents who responded with "yes", "no" and "unsure" to the statement: "I consider myself an environmentalist"
survey_counts <- survey_environmentalist %>% 
  janitor::tabyl(party, environmentalist)

survey_proportions <- survey_counts %>% 
  adorn_percentages() %>% 
  janitor::adorn_pct_formatting(digits = 2) %>% 
  adorn_ns() %>% 
  drop_na()

survey_ct <- survey_proportions %>% 
  column_to_rownames(var = "party")

survey_ct %>%  
  kable(col.names = c("No",
                      "Unsure",
                      "Yes"),
    caption = "**Table 1**: Association between respondents’ political affiliation (“conservative” or “liberal” by self-identification) vs if they consider themself an environmentalist") %>% 
  kable_styling(full_width = FALSE) 
**Table 1**: Association between respondents’ political affiliation (“conservative” or “liberal” by self-identification) vs if they consider themself an environmentalist
No Unsure Yes
conservative 50.24% (318) 16.11% (102) 33.65% (213)
liberal 24.47% (128) 21.80% (114) 53.73% (281)
## Chi-square test
survey_ct <- survey_counts %>%   
  drop_na() %>% 
  column_to_rownames(var = "party")
  
survey_x2 <- chisq.test(survey_ct)
survey_x2

    Pearson's Chi-squared test

data:  survey_ct
X-squared = 81.237, df = 2, p-value < 2.2e-16
survey_tidy <- tidy(survey_x2)

Chi-square results and summary

A chi-square test for independence compares two variables in a contingency table to see if they are related. In a more general sense, it tests to see whether distributions of categorical variables differ from each another. For this analysis, there is a significant association (i.e. non-independence) between political affiliation and and if a person considers themself an environmentalist ($\chi$2(2) = 81.24, p-value = 2.29e-18).

Citations:

  • Andrews Forest LTER Site and C. Batavia. 2019. Influences on charitable giving for conservation: Online survey data of 1,331 respondents across the US, August 2017 ver 3. Environmental Data Initiative. https://doi.org/10.6073/pasta/926e6270e324a1322a900da14d38b96c

  • Metadata, including survey questions and possible responses, are here: https://portal.edirepository.org/nis/metadataviewer?packageid=knb-lter-and.5444.3