Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

STATS 2DA3 Fall 2023

ASSIGNMENT 1

Submit through Crowdmark.

Due before 5pm on Tuesday, September 26th.

Assignments submitted up to 24 hours late will incur a 30% penalty.

Assignments submitted more than 24 hours late will receive a zero grade.

Answer all questions (read the “Assignment Standards” at the end of the assignment).

Not all questions carry equal marks.

All graphs must be labelled (including axes).

1.  (6 MARKS) Using the Salaries dataset in the carData package, answer the following ques- tions:

(a)  Use one or two lines of R code to display how many rows and columns are in the dataset. (i.e. do not just output all observations in the dataset. Write some code that

will output the required information).

(b) What does the “salary” variable describe?

(c) Which variables are categorical and which are continuous?

(d) Using  the  ggplot  function,  make  a  scatterplot  of  “yrs.since.phd”  against   salary” (putting “yrs.since.phd” on the x-axis).

.  Make the data points red.

. Label the x-axis Years Since PhD.

. Label the y-axis Salary.

. Label the graph Experience vs. Salary.

2.  (5 MARKS) Using the diamonds dataset in the ggplot2 package, carry out the following tasks:

(a) Use ggplot to make a bar chart (geom bar) displaying  cut” .  “fill” using  cut” (i.e. each cut should be a different colour on the graph).

(b) Use ggplot to make a bar chart (geom bar) displaying “cut” .  “fill” using “clarity” .

(c)  Display both graphs in one image using  R code  (i.e.  do not just screen grab the 2 images and combine them).

3.  (3  MARKS)  Consider  the  Double  Decker  plot  below;  it  displays  3  different levels of Improvement (None, Some or Marked) that a patient can experience after receiving 1 of 2 medical Treatements (Placebo or Treated).

(a) For female patients in the Placebo group, what was the most reported level of Im- provement?

(b) For male patients in the Placebo group, what was the least reported level of Improve- ment?

(c) Which demographic (Sex and Treatment group) showed the best (“Marked”) level of Improvement?


4.  (6 MARKS)

Visualizing 2 categorical variables;

For the mpg dataset in the ggplot2 package, perform the following tasks:

(a)  Create a Double Decker plot, displaying “drv” as a function of “class” (class should be on the x-axis). Make sure you colour the “drv” variable so that each level is a different colour.

(b)  For suv class cars, which type of drive train is the least common?

(c)  For midsize class cars, which type of drive train is the most common?

(d) Using ggplot make a bar chart (geom bar) displaying “class”. Colour (“fill”) the “class” variable with respect to the “drv” variable.

Assignment Standards

.  Answer each question.  Do not just provide code.  Any graphs must be rendered and reproduced in the report.

. LATEX is strongly recommended but not strictly required.  The use of Markdown in R studio is also recommended.

.  Submit your assignment as one .pdf document.  All R code should be included and  organized  either  at  the  end  of the  assignment  or  inline  (if  using  R Markdown).

. Approximately eleven-point font (times or similar) must be used with around 1.5 line spacing and margins of at least 1 inch all around.

.  Do not include a title page.  The title and your name should be printed at the top of the first page.

. Various tools, including publicly available internet tools, maybe used by the instructor to check the originality of submitted work.

.  Students are not permitted to use generative AI in this course.   In alignment with McMaster academic integrity policy, it  “shall be an offence knowingly to . . .  submit academic work for assessment that was purchased or acquired from another source” .


This includes work created by generative AI tools. Also stated in the policy is the fol- lowing, “Contract Cheating is the act of “outsourcing of student work to third parties” (Lancaster & Clarke, 2016, p.  639) with or without payment.” Using Generative AI tools is a form of contract cheating.  Charges of academic dishonesty will be brought forward to the Office of Academic Integrity.