actor	partner	prosocial	selfish	prosocial_color	selfish_color
A	I	22	8	green	purple
A	G	16	14	yellow	black
A	H	22	8	blue	red
A	none	16	14	pink	gray
B	H	18	12	black	yellow
B	C	23	7	purple	green
B	D	19	11	blue	red
B	none	16	14	gray	pink
C	B	18	12	yellow	black
C	F	19	11	red	blue
C	E	20	10	green	purple
C	none	17	13	gray	pink
D	C	19	11	black	yellow
D	B	15	15	green	purple
D	I	16	14	blue	red
D	none	8	22	pink	gray
E	C	14	16	purple	green
E	I	14	16	blue	red
E	J	20	10	black	yellow
E	none	12	18	pink	gray
F	I	18	12	green	purple
F	A	18	12	red	blue
F	D	11	19	black	yellow
F	none	14	16	gray	pink
G	J	16	14	red	blue
G	F	15	15	black	yellow
G	A	6	4	purple	green
This is chimpanzee csv 
### 4

The goal of this question is to create a graphic to visualize confidence intervals for the proportion of times the prosocial token is selected by the chimpanzees.  Read in the `chimpanzee.csv` data file, then follow the steps below.

- Make a plot that displays a **point** at the proportion of times the prosocial choice is made (i.e., the point estimate $\hat{p}$) in trials when a partner is present and in trials when a partner is not present.  These estimates are based on all the chimpanzee actors data combined.  This will result in two points on your graphic for this step.  The y-axis is for the estimated proportion and the x-axis is for the experimental condition ("with a partner" or "without a partner").
- Add a thin blue (vertical) line segment for each point to visualize a 95% Wald confidence interval.  The lines should extend vertically from the lower bound to the upper bound of the confidence interval, and the point estimate from the previous step will be in the middle of the interval.
-  Similarly, add a slightly thicker black segment to visualize the interval one standard error above and below the point estimates.
- Add a horizontal red dashed line at p = 0.5.
- Label axes appropriately and add an informative title to the plot.

Note:  Make sure your point estimates are clearly visible on the graphic.  We recommend you add the 95% confidence interval first, then add the the SE interval, and finally the point estimate.

*Hint:  Your final plot should have two vertical lines with the layered segments for the CIs and the SE intervals, a point in the center of each vertical line, and a horizontal dashed line.*

```{r}
# insert code here


library(ggplot2)
library(dplyr)

chimpanzees <- read.csv("../../data/chimpanzee.csv")

chimpanzees <- chimpanzees %>%
  mutate(partner_present = ifelse(partner == "none", "Without Partner", "With Partner"))

proportion_summary <- chimpanzees %>%
  group_by(partner_present) %>%
  summarise(
    n = sum(prosocial + selfish),
    prosocial_choices = sum(prosocial),
    p_hat = prosocial_choices / n,
    se = sqrt(p_hat * (1 - p_hat) / n),
    ci_upper = p_hat + 1.96 * se,
    ci_lower = p_hat - 1.96 * se,
    se_upper = p_hat + se,
    se_lower = p_hat - se
  )
ggplot(proportion_summary, aes(x = partner_present, y = p_hat)) +
  geom_point(size = 3, color = "black") + 
  geom_errorbar(aes(ymin = ci_lower, ymax = ci_upper), width = 0.1, color = "blue", linetype = "solid") + 
  geom_errorbar(aes(ymin = se_lower, ymax = se_upper), width = 0.1, color = "black", linetype = "solid", size = 1.2) + 
  geom_hline(yintercept = 0.5, linetype = "dashed", color = "red") +
  labs(title = "Proportion of Prosocial Choices in Chimpanzees",
       x = "Experimental Condition",
       y = "Proportion of Prosocial Choices") +
  theme_minimal()

```
I have answer this correctly now answer below in R 
### 5

Consider Chimpanzee actor B in the setting with a partner present.  Compute 99%, 95%, 90%, and 85% Wald confidence intervals for p, the probability of selecting the prosocial token (round the upper and lower bounds to two decimal places).

Print out all four confidence intervals.