# confidence level for bypass and angiographyconf_level <-0.9# standard error for bypassbypass_se <-10/sqrt(539)# confidence interval for bypassbypassCI <-19+qt(c(0.05, 0.95), 539-1) * bypass_sebypassCI
[1] 18.29029 19.70971
Ci for angio
Code
# standard error for angiographyangio_se <-9/sqrt(847)# confidence interval for angiographyangioCI <-18+qt(c(0.05, 0.95), 847-1) * angio_seangioCI
[1] 17.49078 18.50922
Size of confidence interval twice the margin of error
Code
2*qt(c(0.05, 0.95), 539-1) * bypass_se
[1] -1.419421 1.419421
Code
2*qt(c(0.05, 0.95), 847-1) * angio_se
[1] -1.018436 1.018436
The confidence interval for angiography is narrower.
Q.2)
Code
# out of 1031 Americans surveyedp <-567/1031# 54% of Americans believe college education is essential for success# 95% significant levelconf<-0.95# standard errorcollege_se <-sqrt(p*(1-p)/1031) # confidence intervalcollegeCI <- p +qnorm(c(0.025, 0.975)) * college_secollegeCI
using anova as comparing means of more than two groups
Code
one.way <-aov(cost ~ Area, data = Area_cost)summary(one.way)
Df Sum Sq Mean Sq F value Pr(>F)
Area 2 25.66 12.832 8.176 0.00397 **
Residuals 15 23.54 1.569
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Source Code
---title: "Homework_2"author: "Paritosh G"desription: "HW_2"date: "05/26/2023"format: html: toc: true code-fold: true code-copy: true code-tools: truecategories: - hw1 - challenge1 - my name - dataset - ggplot2---## Libraries```{r}library(tidyverse)```## Q.1)```{r}surgical_procedures <-c("bypass","angiography")sample_size <-c(539, 847)mean_wait_time <-c(19, 18)standard_deviation <-c(10,9)df <-data.frame(surgical_procedures, sample_size, mean_wait_time, standard_deviation)```CI for bypass```{r}# confidence level for bypass and angiographyconf_level <-0.9# standard error for bypassbypass_se <-10/sqrt(539)# confidence interval for bypassbypassCI <-19+qt(c(0.05, 0.95), 539-1) * bypass_sebypassCI```Ci for angio```{r}# standard error for angiographyangio_se <-9/sqrt(847)# confidence interval for angiographyangioCI <-18+qt(c(0.05, 0.95), 847-1) * angio_seangioCI```Size of confidence interval twice the margin of error```{r}2*qt(c(0.05, 0.95), 539-1) * bypass_se``````{r}2*qt(c(0.05, 0.95), 847-1) * angio_se```- The confidence interval for angiography is narrower.## Q.2)```{r}# out of 1031 Americans surveyedp <-567/1031# 54% of Americans believe college education is essential for success# 95% significant levelconf<-0.95# standard errorcollege_se <-sqrt(p*(1-p)/1031) # confidence intervalcollegeCI <- p +qnorm(c(0.025, 0.975)) * college_secollegeCI ```## Q.3)```{r}range =200-30population_sd = range/4z =qnorm(.975)s = population_sdn = ((z *s) /5)^2print(n)```## Q.4)- Setting up our t-test formula```{r} t_test <-function(x_bar, mu, sd, n){return((x_bar - mu) / (sd /sqrt(n))) }# getting t-test score t_statistic <-t_test(x_bar =410, mu =500, sd =90, n =9)```## A)```{r}n =9pval_two_tail =2*pt(t_statistic, df = n-1)pval_two_tail```Rejecting null Hypothesis that population mean in 500## B)```{r}pval_left_side_tail =pt(t_statistic, df = n-1)pval_left_side_tail```- Rejecting null hypothesis that population mean is greater than 500## C)```{r}pval_right_side_tail =pt(t_statistic, df = n-1, lower.tail=FALSE)pval_right_side_tail```- Fail to reject that population mean is less than 500. ## Q.5)```{r}# T values t_jones <- (519.5-500) /10# sample mean = 519.5 - 500 for population mean / sample error of 10.0 t_jones``````{r}t_smith <- (519.7-500) /10# sample mean = 519.7 - 500 for population mean / sample error of 10.0t_smith``````{r}# p valuesp_jones <-2*pt(-abs(t_jones), df =999)p_jones``````{r}p_smith <-2*pt(-abs(t_smith), df =999)p_smith```- Jones is not significant at 0.05 level but smith's result is significant ## Q.6)```{r}# dataframe creationgrade <-c(rep("6th grade", 100), rep("7th grade", 100), rep("8th grade", 100))snack <-c(rep("healthy snack", 31), rep("unhealthy snack", 69), rep("healthy snack", 43),rep("unhealthy snack", 57), rep("healthy snack", 51), rep("unhealthy snack", 49))snack_df <-data.frame(grade, snack)```Using chi square test as we are testing association between two categorical variables.```{r}table(snack_df$snack,snack_df$grade)``````{r}chisq.test(snack_df$snack,snack_df$grade)```- There is a relation between grades and choice of snack## Q.7)```{r}Area <-c(rep("Area1", 6), rep("Area2", 6), rep("Area3", 6))cost <-c(6.2, 9.3, 6.8, 6.1, 6.7, 7.5, 7.5, 8.2, 8.5, 8.2, 7.0, 9.3,5.8, 6.4, 5.6, 7.1, 3.0, 3.5)Area_cost <-data.frame(Area,cost)```using anova as comparing means of more than two groups```{r}one.way <-aov(cost ~ Area, data = Area_cost)summary(one.way) ```