Hello, I want to know why the fitted curve in the picture looks so bad and is not just one smooth line?
plot(df$Q,df$C)
cur=lm(C~I(1/Q),data=df)
lines(df$Q, predict(cur), col = "green")
What am I missing?
Hello, I want to know why the fitted curve in the picture looks so bad and is not just one smooth line?
plot(df$Q,df$C)
cur=lm(C~I(1/Q),data=df)
lines(df$Q, predict(cur), col = "green")
What am I missing?
Instead you should sort both the predicted and X values by the X values order. One way to do that is to pass an ordered set of values to the lm function. Then the predicted values will also reflect that ordering:
plot( df$Q, dg$C )
cur <- lm(C~I(1/Q), data=df[order[df$Q), ] )
lines(df$Q, predict(cur), col = "green")