linear regression - how to include curve functions into my scatterplot

#1
or my task I have to:
  • Draw a scatter plot 'price' (y-axis) vs. 'distance center' (x-axis). Then estimate the relationship between these 2 variables for the values 1, 2, 3, 4, 5 and 6 of the variable 'number of people' (so that you end up with six regression functions in your scatterplot)
Code:
plot(airbnb$distance_center,airbnb$price,pch=13,xlab="distance_center",ylab="price",bty="n")

mod<-lm(price~number_people+distance_center)

`First part is correct, but this part below I think is a bit wrong.

I have used the curve funktion and mod$coefficients,

but I am not sure on how to have 6 regression functions

for the values 1-6 of the variable number of people into my scatterplot`

curve(mod$coefficients[1]+mod$coefficients[2]*x,lwd=3,col="blue",add=TRUE)

curve(mod$coefficients[2]+mod$coefficients[2]*x,lwd=3,col="yellow",add=TRUE)

Plot doeslook like this, but I am not sure if this is correct way. Would need 4 other regression functions if it was correct.
 

hlsmith

Less is more. Stay pure. Stay poor.
#2
Are you trying to plot lines (models) or actual curves. Since I do not see any polynomials in your model.