Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this regression plot only plotting 2 of the 4 regression coefficients? [duplicate]

Tags:

r

regression

I have the following set of data: https://archive.ics.uci.edu/ml/datasets/abalone

I am trying to plot a regression for the whole weight against the diameter.

A scatter plot of the data is clearly not a linear function. (I am unable to attach it for some reason.)

Consider a quadratic regression model. I set it up like so:

abalone <- read.csv("abalone.data")
diameter <- abalone$Diameter
diameter2 <- diameter^2
whole <- abalone$Whole.weight

quadraticModel <- lm( whole ~ diameter + diameter2)

This is fine and gives me the following when calling quadraticModel:

Call:
lm(formula = whole ~ diameter + diameter2)

Coefficients:
(Intercept)     diameter    diameter2  
     0.3477      -3.3555      10.4968  

However, when I plot:

abline(quadraticModel)

I get the following warning:

Warning message:
In abline(quadraticModel) :
  only using the first two of 3 regression coefficients

which means that I am getting a straight line plot which isn't what I am aiming for. Can someone please explain to me why this is happening and possible ways around it? I am also having the same issue with cubic plots etc. (They always just plot the first two coefficients.)

like image 959
Joe Avatar asked Sep 18 '25 09:09

Joe


1 Answers

You can not use abline to plot polynomial regression fitted. Try this:

x<-sort(diameter)
y<-quadraticModel$fitted.values[order(diameter)]
lines(x, y) 
like image 75
Henry Navarro Avatar answered Sep 20 '25 03:09

Henry Navarro