Chi-squared test with R programming

profilespringbird
Rprogrammingch_sqtestenquiry.docx

Hi,

I need help in writing a few lines of codes in R to do a Chi-squared test comparing the proportions of overweight and cancer. Our prof has provided a portion of the codes for overweight and showed the output in italics. He required us to add a few more lines of codes to load the .csv data file on the desktop so as to perform the chi _squared test for p-value.

This question compares the proportion of overweight and cancer from the data file shown in the following link:

https://drive.google.com/file/d/1T_37kwyyAFZhM5hh9OVtYeDL3Zrmu3hC/view

The file name is:   cancer data for MOOC

a. load the csv file on your desk top.

b. extract only two columns of data from the csv file: the BMI and Cancer columns

c. compare the proportion of overweight and cancer

BMI >= 25 is defined as overweight and is assigned (1) and not overweight is assigned (0).

# define the variables and the object g

1 cancer <-g $cancer

2

3 overweight <- ifelse(g$bmi>=25,1,0)

# check variable and object g to make sure everything makes sense

# here is the output table for reference

1 table ( overweight )

2

3 Overweight

4

5 0 1

6 34 32

# the table says that of the 66 observations, 34 are not overweight and 32 are overweight.

# set the null hypothesis: that overweight and cancer are not associated

# next perform a chi-squared test, let the y axis be cancer, the dependent variable and x axis the independent variable

1 chi. test( x=overweight, y= cancer)

Find the p-value and draw conclusion.

Show all of your R coding with # comments and output as required.

Please review the codes in italics provided and let me know if you can add a few more lines of code to do the test as required and let me know the p-value. Thanks.