I was having trouble with plotting lines with my non-linear regression because the lengths of the plotting variables were different because the regression was omitting some observations. I fixed that using na.action=na.exclude. Now the "lengths differ" warning doesn't show anymore, but the lines() simply doesn't show my non-linear prediction.
I'm sorry if this is kind of vague, but I really don't know what is happening because there is no error message.
Here's the code I'm using:
data_lm <- read.csv('notaport.csv', sep=';', dec=',')
regs <- lm(notaport ~ tamturma, data=data_lm)
regm <- lm(notaport ~ tamturma + I(tamturma**2), data=data_lm, na.action = na.exclude)
plot(data_lm$tamturma, data_lm$notaport, xlab='Tamanho da Turma', ylab = 'Notas de Português', pch='.')
abline(regs, col='red')
linearpred_regm <- predict(regm)
plot(data_lm$tamturma, data_lm$notaport, xlab='Tamanho da Turma', ylab = 'Notas de Português', pch='.')
lines(linearpred_regm, data_lm$tamturma, col='red')
summary(data_lm)
summary(regs)
summary(regm)
My data can be downloaded with this link in We Transfer.