[SOLVED] Gov1372 Assignment 1 -Data Exploration: Making Decisions

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon gov1372_exp1-main-r2tnyf.zip (384.8 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
πŸ”’ Securely Powered by:
Secure Checkout
5/5 - (1 vote)

Β 

In this Data Exploration assignment, you have two separate data sets with which you will work. The first involves the data generated by you and your classmates last week when you took the in-class survey. The second involves some of the data used in the Atkinson et al. (2009) piece that you read for class this week. Both data sets are described in more detail below.

If you have a question about any part of this assignment, please ask! Note that the actionable part of each question is bolded.

Part 1: Cognitive Biases

You may have noticed that the questions on the survey you took during class last week were based on the Kahneman (2003) reading you did for this week. The goal for this set of questions is to examine those data to see if you and your classmates exhibit the same cognitive biases that Kahneman wrote about. The data you generated is described below. Data Details:

  • File Name: bias_data.csv
  • Source: These data are from the in-class survey you took last week.
Variable Name Variable Description
id Unique ID for each respondent
rare_disease_prog From the rare disease problem, the program chosen by the respondent (either β€˜Program A’ or β€˜Program B’)
rare_disease_cond From the rare disease problem, the framing condition to which the respondent was assigned (either β€˜save’ or β€˜die’)
linda From the Linda problem, the option the respondent thought most probable, either β€œteller” or β€œteller and feminist”
cab From the cab problem, the respondent’s estimate of the probability the car was blue
gender One of β€œman”, β€œwoman”, β€œnon-binary”, or β€œother”
year Year at Harvard
college_stats Indicator for whether or not the respondent has taken a college-level statistics course

Before you get started, make sure you replace β€œfile_name_here_1.csv” with the name of the file. (Also, remember to make sure you have saved the .Rmd version of this file and the file with the data in the same folder.)

# load the class-generated bias data bias_data <- read_csv(β€œbias_data.csv”)

Question 1

First, let’s look at the rare disease problem. You’ll recall from the Kahneman (2003) piece that responses to this problem often differ based on the framing (people being saved versus people dying), despite the fact that the two frames are logically equivalent. This is what is called a β€˜framing bias’.

Did you all exhibit this bias? Since the outcomes for this problem are binary, we need to test to see if the proportions who chose Program A under each of the conditions are the same. Report the difference in proportions who chose Program A under the β€˜save’ and β€˜die’ conditions. Do we see the same pattern that Kahneman described?

bias_data %>%

group_by(rare_disease_cond) %>% summarize(program_a_prop = mean(rare_disease_prog == β€œProgram A”))

## # A tibble: 2 x 2

##Β Β Β Β Β Β Β Β Β Β Β Β Β  rare_disease_cond program_a_prop

##Β Β Β Β Β Β Β Β Β  <chr>Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  <dbl>

## 1 dieΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  0.349

## 2 saveΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  0.667

EXTENSION: Report the 95% confidence interval for the difference in proportions you just calculated. Hint: the infer package has a function that is useful here. What does the 95% confidence interval mean?

Note that extensions to questions are not the same as data science questions. Complete this question if you like, but it is not required for data science students like actual data science questions.

prop_test(bias_data, rare_disease_prog ~ rare_disease_cond, order = c(β€œdie”, β€œsave”))

## # A tibble: 1 x 6

##Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  statistic chisq_df p_value alternative lower_ci upper_ci

##Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  <dbl>Β Β Β Β Β Β Β Β Β Β Β  <dbl>Β Β Β Β Β Β Β Β Β Β  <dbl> <chr>Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  <dbl>Β Β Β Β Β Β Β Β Β Β Β Β  <dbl>

## 1Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  7.36Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  1 0.00666 two.sidedΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  -0.543 -0.0928

ANSWER: The 95% confidence interval for the difference in proportions is (-0.543, -0.093). This means we can be 95% confident that the true difference in proportions is between these values.

Question 2

Now let’s move on to the Linda problem. As we read in Kahneman (2003), answers to this problem tend to exhibit a pattern called a β€œconjunction fallacy” whereby respondents overrate the probability that Linda is a bank teller and a feminist rather than just a bank teller. From probability theory, we know that the conjunction of two events A and B can’t be more probable than either of the events occurring by itself; that is, P(A) β‰₯P(A∧B) and P(B) β‰₯P(A∧B)[1].

What proportion of the class answered this question correctly? Why do you think people tend to choose the wrong option?

nrow(bias_data %>% filter(linda == β€œteller”)) / nrow(bias_data)

## [1] 0.7058824

Question 3

What attributes of the respondents do you think might affect how they answered the Linda problem and why? Using the data, see if your hypothesis is correct.

bias_data %>%

group_by(year) %>% summarize(stat = mean(linda == β€œteller”))

## # A tibble: 4 x 2

##Β Β Β Β Β Β Β Β Β Β Β Β Β  yearΒ Β Β Β Β Β Β Β  stat ##Β Β Β  <chr> <dbl>

## 1 1Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  0.5

## 2 2Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  0.696

## 3 3Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  0.707

## 4 4+Β Β Β Β Β Β Β Β Β Β Β Β Β Β  0.765

bias_data %>%

group_by(college_stats) %>% summarize(stat = mean(linda == β€œteller”))

## # A tibble: 2 x 2

##Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  college_stats stat

##Β Β Β Β Β Β Β Β Β  <chr>Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  <dbl>

## 1 NoΒ Β  0.613 ## 2 YesΒ Β Β Β Β Β  0.759

bias_data %>%

group_by(year, college_stats) %>%

summarize(stat = mean(linda == β€œteller”), n = n())

## # A tibble: 7 x 4

## # Groups:Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  year [4]

##Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  year college_stats statΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  n

##Β Β Β Β Β Β Β Β Β Β  <chr> <chr>Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  <dbl> <int>

## 1 1Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  YesΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  0.5Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  4

## 2 2Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  NoΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  0.5Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  10

## 3 2Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  YesΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  0.846Β Β Β Β Β Β Β Β Β Β Β  13

## 4 3Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  NoΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  0.533Β Β Β Β Β Β Β Β Β Β Β  15

## 5 3Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  YesΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  0.808Β Β Β Β Β Β Β Β Β Β Β  26

## 6 4+Β Β Β Β Β Β Β Β Β Β Β Β Β  NoΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  1Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  6

## 7 4+Β Β Β Β Β Β Β Β Β Β Β Β Β Β  YesΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  0.636Β Β Β Β Β Β Β Β Β Β Β  11

Question 4: Data Science Question

Now we will take a look at the taxi cab problem. This problem, originally posed by Tversky and Kahneman in 1977, is intended to demonstrate what they call a β€œbase rate fallacy”. To refresh your memory, here is the text of the problem, as you saw it on the survey last week:

A cab was involved in a hit and run accident at night. Two cab companies, the Green and the Blue, operate in the city. 85

A witness identified the cab as Blue. The court tested the reliability of the witness under the same circumstances that existed on the night of the accident and concluded that the witness correctly identified each one of the two colours 80

What is the probability that the cab involved in the accident was Blue rather than Green knowing that this witness identified it as Blue?

The most common answer to this problem is .8. This corresponds to the reliability of the witness, without regard for the base rate at which Blue cabs can be found relative to Green cabs. In other words, respondents tend to disregard the base rate when estimating the probability the cab was Blue.

What is the true probability the cab was Blue? Visualize the distribution of the guesses in the class using a histogram. What was the most common guess in the class?

# P(iB|B)*P(B) / [P(iB|B)*P(B) + P(iB|G)*P(G)]

(0.8 * 0.15) / ((0.8 * 0.15) + (0.2 * 0.85))

## [1] 0.4137931

bias_data %>% ggplot(aes(x = cab)) + geom_histogram() + geom_vline(aes(xintercept = .8), col = β€œred”) labs(x = β€œP(Blue | Identified as Blue)”, y = β€œCount”, title = β€œTaxi Cab Problem Responses”

+

)

Taxi Cab Problem Responses

Part 2: Political Faces

Now you will investigate some of the data used in Atkinson et al. (2009). These data cover Senate candidates from 1992-2006 and include face ratings, partisanship, incumbent status, and other variables.

Data Details:

  • File Name: senate_data.csv
  • Source: These data are condensed and adapted from the replication data for Atkinson et al. (2009).
Variable Name Variable Description
cook The assessment of the Senate race from the Cook Political Report in the year prior to the election
year The year of the election
state The state in which the candidate was running
face_rating The normalized rating of the candidate’s perceived competence based on an image of the face
incumbent An indicator variable for whether the candidate was an incumbent
candidate The candidate’s name
party The candidate’s political party
tossup An indicator variable for whether the race was one of two β€œtossup” categories according to Cook
jpg A unique identifier for the photo of the candidate

As before, make sure you replace β€œfile_name_here_2.csv” with the name of the file.

face_data <- read_csv(β€œsenate_data.csv”)

As an example of how you might write your own code to analyze these data, let’s take a look at whether there was a difference in the perceived competence of Democratic and Republican candidates’ faces. We can examine this question graphically using a density plot.

# make density plot of perceived competence by party

ggplot(data = face_data, aes(x = face_rating, color = party)) + # note that by setting color = party,

geom_density()Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  # the face ratings of each party will be

We can also consider this statistically using a t-test for whether or not the mean face ratings are significantly different across parties.

# conduct a t-test of difference-in-means

difference_in_means(face_rating ~ party, data = face_data)

## Design: Standard

##Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  Estimate Std. Error t value Pr(>|t|)Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  CI Lower CI UpperΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  DF

## partyrep 0.1044044 0.09565385 1.091482 0.2756698 -0.08360089 0.2924098 431.5741

Neither the graphical nor the statistical approaches suggest a significant difference in perceived competence of candidate faces by party.

Question 5

Do the data suggest a significant difference between perceived competence of incumbent vs. non-incumbent candidate faces? How do your findings relate to the results and theory of Atkinson et al. (2009)?

face_data %>%

ggplot(aes(x = face_rating, color = incumbent)) + geom_density() + labs(x = β€œFace Rating”, y = β€œDensity”, title = β€œIncumbent vs. Challenger Face Competency Ratings Density Plot”)

Incumbent vs. Challenger Face Competency Ratings Density Plot

difference_in_means(face_rating ~ incumbent, face_data)

## Design: Standard

##Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  Estimate Std. Error t valueΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  Pr(>|t|) CI Lower CI Upper

## incumbent 0.4480374 0.09084939 4.93165 1.161294e-06 0.2694804 0.6265944

##Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  DF

## incumbent 436.1783

Question 6

Do the data suggest a significant difference between perceived competence of non-incumbent candidate faces in tossup vs. non-tossup races? What might explain any similarities or differences between these results and those from the previous question? How do your findings relate to the results and theory of Atkinson et al. (2009)?

face_data %>%

filter(incumbent == β€œFALSE”) %>% ggplot(aes(x = face_rating, color = tossup)) + geom_density() + labs(x = β€œFace Rating”, y = β€œDensity”, title = β€œTossup vs. Non-tossup Face Competency Ratings Density Plot”)

Tossup vs. Nonβˆ’tossup Face Competency Ratings Density Plot

difference_in_means(face_rating ~ tossup, face_data %>% filter(incumbent == β€œFALSE”))

## Design: Standard

##Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  Estimate Std. Error t value Pr(>|t|)Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  CI Lower CI UpperΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  DF

## tossup 0.1740081 0.1612837 1.078894 0.2850889 -0.1488172 0.4968334 58.16194

face_data %>%

filter(incumbent == β€œFALSE”) %>% group_by(tossup, incumbent) %>% summarize(n = n())

## # A tibble: 2 x 3

## # Groups:Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  tossup [2]

##Β Β Β Β Β Β Β Β Β Β  tossup incumbentΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β  n

##Β Β Β Β Β Β Β Β Β Β Β Β Β  <lgl> <lgl>Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  <int>

## 1 FALSE FALSEΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  222

## 2 TRUEΒ Β Β Β Β Β Β Β Β Β Β  FALSEΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  38

Question 7: Data Science Question

Atkinson et al. (2009, 236) suggest that β€œβ€¦incumbents from the most competitive districts would have higher facial quality than incumbents from the most safe incument districts due to the selection process of better faces to competitive districts, inducing a negative relationship betwen incumbent face and incumbent vote.” Do the data support the idea that seat safety is negatively correlated with incumbent facial quality? Make a plot to visualize this relationship. Note that this question may require you to define at least one new variable.

new_face <- face_data %>% mutate(cook.num = ifelse(cook == β€œSolidDem”, 4, ifelse(cook == β€œLikelyDem”, 3, ifelse(cook == β€œLeanDem”, 2, ifelse(cook %in% c(β€œTossupDem”, β€œTossUpDem”), 1, ifelse(cook %in% c(β€œTossupRep”, β€œTossUpRep”), 1, ifelse(cook == β€œLeanRep”, 2, ifelse(cook == β€œLikelyRep”, 3, ifelse(cook == β€œSolidRep”, 4, 5))))))))) %>%

mutate(cook.num = as.character(cook.num))

ggplot(new_face, aes(x = cook.num, y = face_rating, fill = party)) + geom_boxplot() + labs(x = β€œRace Competitiveness*”, y = β€œFace Rating”, title = β€œDoes Competitiveness Correlate with Face Rating?”, caption = β€œ*score of 1 indicates most competitive (tossup),\n

scale_fill_manual(values = c(β€œlightblue”, β€œred”),

name = β€œParty”, breaks = c(β€œdem”, β€œrep”), labels = c(β€œDem”, β€œRep”)) +

theme(plot.title = element_text(face = β€œbold”), axis.title = element_text(face = β€œbold”))

score of 4 ind

Does Competitiveness Correlate with Face Rating?

*score of 1 indicates most competitive (tossup), score of 4 indicates least competitive (solid)

Question 8

Is there something else interesting or informative that you could explore using either of these datasets? If so, run it by a TF and try it out here.

# Scatter plot showing face ratings for candidates in each year

new_face %>% filter(incumbent == β€œTRUE”) %>% ggplot(aes(x = year, y = face_rating, color = party)) +

geom_jitter(height = 0, width = 0.1) + labs(x = β€œYear”, y = β€œFace Rating”, title = β€œDoes Face Rating \”Improve\”

scale_color_manual(values = c(β€œblue”, β€œred”),

name = β€œParty”, breaks = c(β€œdem”, β€œrep”), labels = c(β€œDem”, β€œRep”)) +

theme(plot.title = element_text(face = β€œbold”), axis.title = element_text(face = β€œbold”)) +

geom_smooth(method = β€œlm”)

Over Time?”) +

## β€˜geom_smooth()β€˜ using formula ’y ~ x’

Does Face Rating β€œImprove” Over Time?

# Comparing regional face ratings

new_face %>% mutate(region = ifelse(state %in% c(β€œWA”, β€œOR”, β€œCA”), β€œPacific”, ifelse(state %in% c(β€œNV”, β€œMT”, β€œWY”, β€œCO”, β€œUT”, β€œID”), β€œWest”, ifelse(state %in% c(β€œAZ”, β€œNM”, β€œTX”, β€œOK”), β€œSouthwest”, ifelse(state %in% c(β€œND”, β€œSD”, β€œNE”, β€œKS”, β€œMO”, β€œIA”,

β€œMN”, β€œIL”, β€œWI”, β€œMI”, β€œIN”, β€œOH”), β€œMidwest”,

ifelse(state %in% c(β€œAR”, β€œLA”, β€œTN”, β€œMS”, β€œAL”, β€œGA”,

β€œFL”, β€œSC”, β€œNC”, β€œKY”, β€œVA”, β€œMD”, β€œDE”, β€œWV”),

ifelse(state %in% c(β€œPA”, β€œNY”, β€œNJ”, β€œRI”, β€œCT”, β€œMA”, β€œVT”, β€œNH”, β€œME” ifelse(state %in% c(β€œAK”, β€œHI”), β€œAK / HI”, β€œnone”)))))))) %>%

ggplot(aes(x = region, y = face_rating, fill = incumbent)) + geom_boxplot() + labs(x = β€œRegion”, y = β€œFace Rating”, title = β€œDo Face Ratings Vary Regionally?”) +

scale_fill_manual(values = c(β€œspringgreen”, β€œtomato1”),

name = β€œIncumbent?”, breaks = c(β€œTRUE”, β€œFALSE”), labels = c(β€œYes”, β€œNo”)) +

theme(plot.title = element_text(face = β€œbold”), axis.title = element_text(face = β€œbold”))

β€œSoutheast”,

), β€œNortheast”

Do Face Ratings Vary Regionally?

[1] The symbol ∧ is used in logical expressions to mean β€œAND”. If there are two conditions, A and B, then A∧B is true only when both A and B are separately true. The expression P(A) β‰₯P(A∧B) is therefore interpreted as: β€œThe probability A is true is greater than or equal to the probability that both A and B are true.

  • gov1372_exp1-main-r2tnyf.zip