I need to get a graph for regression analysis for certain data. As that data must contain the point (0, 0), the regression polynomial graph must go through (0, 0). However whatever I have tried I could only manage to do that with abline but not for the second degree polynomial. Here's my code:
concentration = c(0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20)
absorbance = c(0, 80.33, 135.7, 207, 243.3, 303, 329, 370.3, 406, 431.7, 444.3)
albumin = data.frame(concentration = concentration, absorbance = absorbance)
modelForAlbumin = lm(formula = absorbance ~ concentration + 0, data = albumin)
modelForAlbumin
modelPoly = lm(formula = y ~ 0 + x + I(x^2), data = albumin)
modelPoly
ggplot(data = albumin, mapping = aes(x = concentration, y = absorbance)) +
labs(x = "Kontnsentratsioon c", y = "Neelduvus N") +
geom_point() +
geom_line() +
geom_abline(intercept = 0, slope = modelForAlbumin$coefficients[1], color = 3) +
geom_smooth(method = "lm", formula = y ~ poly(x, 2), fill = "firebrick") +
stat_regline_equation(aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~~")), formula = y ~ poly(x, 2) + x + 0)
library(basicTrendline)
trendline(concentration,absorbance,model="line3P",summary=TRUE,eDigit=4)
The first image displays the graphs correctly however the equation for y is totally incorrect. Why is that?
The second image also displays the graph correctly however I can't force the intercept there.
So how to create a graph that has the polynomial regression line with forced intercept and that the equation also corresponds to that id est it's in the form of y = a x ^ 2 + k x?