-3

CODE:

plot(medalswimmers$Height, medalswimmers$Weight , cex=1.3, pch=16, xlab="Height of medal winning swimmers (in years)", ylab="Respective weight of medal winning swimmers (in cm)")
lm(medalswimmers$Height ~ medalswimmers$Weight)

OUTPUT:

Call:
lm(formula = medalswimmers$Height ~ medalswimmers$Weight)

Coefficients:

(Intercept)  medalswimmers$Weight  
    129.2058                0.7146  

CODE:

  abline(a = 129.2058, b= 0.7146, col="Blue") #-THIS DOES NOT PLOT???

An image of the plot without the regression line

CT Hall
  • 667
  • 1
  • 6
  • 27
  • 1
    Hi Draxler, your question is getting down voted because it is not reproducible so it is hard for us to help you. Also I believe in this case if you had taken the time to make a reproducible example you would likely have figured out what was going wrong. See here for some help: https://stackoverflow.com/q/5963269/3277050 – see24 Mar 13 '19 at 15:22

1 Answers1

1

The line you are trying to plot is outside the plotting window. You can see this by calculating the y-value for the values of x at the limits of your plot:

# What value on the y-axis does the line have when x = 160?
> 129.2058 + 0.7146 * 160
[1] 243.5418

# What value on the y-axis does the line have when x = 200?
> 129.2058 + 0.7146 * 200
[1] 272.1258

The reason for this is you're plotting Height and Weight on the opposite axes to what you've entered in your linear model.

Try instead:

 l1 <- lm(Height ~ Weight, data=medalswimmers)

 plot(medalswimmers$Weight, medalswimmers$Height, cex=1.3, pch=16, 
      ylab="Height of medal winning swimmers (in years)", 
      xlab="Respective weight of medal winning swimmers (in cm)")

 abline(a=coef(l1)["(Intercept)"], b=coef(l1)["Weight"], color="blue")
Scott Ritchie
  • 10,293
  • 3
  • 28
  • 64