(Old) R — Spring 21

By

(Old) R — Spring 21

By




Table of Contents







  1. R4 — Linear Regression



    I. Goals:

    1) Create a scatterplot via the R command:

    plot ()      pch()         col()

    2) Generate linear regression result:

    lm()

    3) Draw a least-squares regression equation on your scatterplot:

    abline()

     

     

    II. What to upload to Canvas for the R4 assigment?

    You ONLY need to upload your R script to Canvas by the due date and time: (no need to upload anything else)

        • R script (.R)

     

    Important: What the grader and I will do is to run your .R script on our computer to generate the scatterplot and linear regression result. So make sure your .R script works!

     

    III. Here is the question for the R4 assignment:

      • This assignment is based on Lesson 4.
      • There is only one question in this assignment:

    Come up with two quantitative variables which are negatively-correlated:

    — Your variables can be biology-related (but they don’t have to be) as your grader knows biology.  They have to be different than the ones shown in the video.

    — Come up with 8 pairs of observations with \(r \neq -1 \). That is, r should be negative but not equal to 1 exactly.

      • Generate a scatterplot showing the linear regression line (see IV below).

     

    IV. To receive full credits, your scatterplot should consist of the following:

    — 8 pairs of observations

    — a linear regression line

    — a title for the plot

    — a label for the x-axis (include the unit of measurement)

    — a label for the x-axis (include the unit of measurement)

     

    V. To receive full credits, your R script needs to satisfy the following:

      • Show clearly how you use the commands below to generate a scatterplot with a linear regression line:
          • plot()
          • pch() — you can choose any shape of data points
          • col() — you can choose any color of data points
          • lm()
          • abline ()
      • No need to show correlation
      • At the top of your R script, use # to
        • type your name
        • Optional: If you want to make sure that the grader understands why your variables are negatively correlated, then write a sentence or two to explain.
        • Optional: it is optional to include other information such as assignment name, etc

    -END-



Content is copyright the author. Layout is copyright Mark Ciotola. See Corsbook.com for further notices.