R — Fall 21

R5 — Linear Regression

By


This homework set is based on Lesson 5Linear Regression. So you need to watch the video in Lesson 5  BEFORE you do this homework set.

I. Goals:

1) Create a scatterplot via the R commands:

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 R5 assigment?

You ONLY need to upload your R script to Canvas by the due date and time:

      • R script (.R)

 

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

The best way for you is to check if your script works or not is to do the following:

    • After you have uploaded your script to Canvas, log out of Canvas and then log back into Canvas. Download your .R script and run it on your RStudio to see if it works!

 

III. What to do for this assignment

  • Create one .R script to generate a scatterplot with a linear regression line of two quantitative variables which are negatively-correlated.

 

 

Here are the Details:

1) Come up with two quantitative variables that are different than the ones shown in the video

      • Be creative! Don’t just copy my example. Come up with something DIFFERENT than the example shown in the demonstration — you will NOT receive full credit if your variables are TOO SIMILAR to mine — e.g. “tea” vs “awake time” or “soda” vs “sleep time” are TOO SIMILAR to my example!
      • Your variables can be biology-related (but they don’t have to be).
      • Label your variables clearly (e.g. calling your variable “school” or “season” is NOT clear enough)
      • Come up with 8 pairs of observations with r negative but \(r \neq -1 \). That is, r should be negative but not equal to 1 exactly.

 

2) To receive full credits, your scatterplot needs to show the following:

        • 8 pairs of observations
        • a linear regression line
        • a title for the plot
          • you can but you don’t have to follow the format “…. vs ….” as shown in the video. You can come up with your own as long as it makes sense.
        • a label for the x-axis (include the unit of measurement)
        • a label for the y-axis (include the unit of measurement)

 

3) 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 calculate correlation.)

 

      • At the top of your R script, use # to:
        • Type your name AND
        • Type a sentence or two to state or describe your quantitative variables. Your variables can be biology-related (but they don’t have to be). The “negative” relationship should make sense  and the labeling should be specific enough.  If you are concerned whether the grader would understand the negative relationship between your variables, then just write a sentence or two in your script to explain.
        • It is optional to include other information such as assignment name, etc.

 

4) Upload the following item to Canvas by the due date and time.

        • R script (.R)

No need to upload your scatterplot.

-END-



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