##Suppose that as part of a program for counseling patients with many risk factors for diabetes, 100 obese patients are identified. From this group, 23 went on a highly restrictive diet. After one year, 9 out of those 23 patients are found to have gone off the diet and reverted to poor eating habits. Calculate and (round to three decimal places) for the proportion of obese patients who reverted to poor eating habits.

Wilson-adjusted p for obese patients who reverted is equal to 0.407

revert<-9
diet<-23
stay<-diet-revert
obese<-100

p_adj= (revert + 2)/(diet+4); p_adj
## [1] 0.4074074

##Using calculate the 95% confidence interval to estimate the true proportion of obese patients who reverted to poor eating habits (recidivists). Be sure to consider the SE calculation under .

95% CI for population of obese patients who would revert to old eating habits: 0.222 to 0.593

SE_p_adj<- sqrt((p_adj*(1-p_adj))/(diet+4))

upper<-p_adj+1.96*SE_p_adj
lower<-p_adj-1.96*SE_p_adj
CI<-c(lower, upper); CI
## [1] 0.2220684 0.5927464

##Interpret your answer in part (c) in context of the problem. We are 95% confident that of those obese patients who start the highly restrictive diet, 22.2% to 59.3% of them will return to unhealthy eating habits within 1 year.

##Find the probability that a person had taken the HIV test, given that they are female. p(HIV Test|Female) =0.175

n_f<-63
test_f<-11
pf<-test_f/n_f;pf
## [1] 0.1746032

##Find the probability that a person had taken the HIV test, given that they are male. p(HIV Test|Male) = 0.129

n_m<-62
test_m<-8
pm<-test_m/n_m;pm
## [1] 0.1290323

##What is the relative risk ratio of taking the HIV test, for females versus males? Estimated relative risk: 1.353

rr<-pf/pm;rr
## [1] 1.353175

##Interpret your answer regarding the ratio of HIV tests for females versus males. (2 pts) The probability that a person takes an HIV given they are female is 1.353 times higher (more likely) than the probability they take the test given they are male.

##Perform a test.

test<-c(11, 8)
no_test<-c(52,54)

stat<-data.frame(test,no_test)

chisq.test(stat)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  stat
## X-squared = 0.21197, df = 1, p-value = 0.6452

##State the null and alternative hypotheses. Ho: There is no diference between males or females for getting an HIV test. HA: There is a diference between males or females for getting an HIV test. ##Report the statistic and the p-value.
X squared = 0.212, p-value 0.645 ##Interpret the results of the test in context of the problem. (2 pts) We fail to reject the null, there is no significant difference between genders on whether or not they get the HIV test.