library(tidyverse)
## -- Attaching packages ----------------------------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.3     v dplyr   1.0.2
## v tidyr   1.1.1     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## -- Conflicts -------------------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
medication_vector<- c(2593, 65000, 67593, 5386, 154592, 159978)

Medication_Matrix<-matrix(medication_vector,nrow=3, ncol=3, byrow=TRUE)

rownames(Medication_Matrix)<- c("Rosiglitazone", "Pioglitazone", "Total")
colnames(Medication_Matrix)<- c("Yes", "No", "Total")

Problem 1

#Problem 1a - This statement is false because they failed to take sample size into account. They need to compare the proportions of people with cardiovascular problems, not the actual number.

Porportion_YesR <- Medication_Matrix[1,1]/Medication_Matrix[1,3]
Porportion_YesR
## [1] 0.03836196
Porportion_YesP <- Medication_Matrix[2,1]/Medication_Matrix[2,3]
Porportion_YesP
## [1] 0.03366713
#Problem 1b - While they took the right steps (using porportion), I don't believe that 3.8% is significantly higher (statistically) than 3.4%. We would need to do a null hypothesis significance test on porportion.

#Problem 1c - False because one study doesn't prove a theory, it can only falsify a theory. Also, the rate of incidence was about the same (see Problem 1c) so if rosiglitazone causes problems, than so does pioglitazone. We also cannot make causal claims about an observational study because there is no manipulation/equally held conditions.

#Problem 1d - True. We don't have enough information to see if there is a confounding variable that might discribe the differences. 

Problem 2:Heart Transplants

#set up
heart_transplants_vector <- c(4, 24, 28, 30, 45, 75, 34, 69, 103)

heart_transplant_martix <- matrix(heart_transplants_vector, nrow=3, ncol =3, byrow=TRUE)

rownames(heart_transplant_martix)<- c("Alive", "Dead", "Total")
colnames(heart_transplant_martix) <- c("Control", "Treatment", "Total")

#Problem 2a

Porp_deadC <- heart_transplant_martix[2,1]/heart_transplant_martix[3,1]
Porp_deadC
## [1] 0.8823529
Porp_deadT <- heart_transplant_martix[2,2]/heart_transplant_martix[3,2]
Porp_deadT
## [1] 0.6521739
#Problem 2b

#2bi - The Null H in this situation is that the porportion of people who lived in the control = the porportion of people who lived in the treatment group, while the Alt. H is that they are unequal. 

#2bii - Blanks: 28 cards, 75 cards, N = 69 (treatment), N=34 (Control), the pop mean, significant (p-values)

#2biii - The difference in porportion is -0.230179, which lands at the very right side of the graph, so I think it is statistically significant. We would need to find the standard error and calc a t-stat/p-value to make sure.

Porp_deadT - Porp_deadC
## [1] -0.230179

Problem 3

#set up 

antibiotics_vector <- c(66, 19, 85, 65, 16, 81, 131, 35, 166)
antibiotics_matrix <- matrix(antibiotics_vector, nrow=3, ncol=3, byrow=TRUE)

rownames(antibiotics_matrix) <- c("Anibiotic", "Placebo", "Total")
colnames(antibiotics_matrix) <- c("Yes", "No", "Total")

#problem 3a - This is an experimental study because there is random assignment, equal conditions, anda manipulation. 

#Problem 3b - It looks like the participants were blind (because placebos don't work unless the participant is blind) but the researchers were not (I think thats called double blind)

#Problem 3c - Porptrt - Porpcnt = -0.02599855
Porp_YesTrt <- antibiotics_matrix[1,1]/antibiotics_matrix[1,3]
Porp_YesTrt
## [1] 0.7764706
Porp_YesCnt <- antibiotics_matrix[2,1]/antibiotics_matrix[2,3]
Porp_YesCnt
## [1] 0.8024691
Porp_YesTrt - Porp_YesCnt
## [1] -0.02599855
#Problem 3d - This doesn't seem to be a good treatment for sinuitis because the treatment porportion is statistically about the same as the control porportion (wouldn't be rare enough) 

#Problem 3e - H0: Pcnt = Ptrt vs H1: Pcnt != Ptrt

#Problem 3f - The value 66 is not unusual according to this graph. Therefore, I will fail to reject the null hypothesis and conclude that H0 = H1. Possible Type 2 error.