i have a series of data in form of time and temperature value. I want to generate a trendline and find the subsequent equation. This could be done in excel. but, how could i find equation of the trendline in R.
abline function can be used to generate a trendline but where is the underlying equation?? I saw a link where they have used the following code to illustrate the issue
x <- sample(1:100, 100, replace = TRUE)
y <- x + rnorm(100, sd = 4)
mydf <- data.frame(x = x, y = y)
plot(y ~ x, data = mydf)
model <- lm(y ~ x, data = mydf)
abline(model, col = "red")
summary(model)
if you execute it, can make some sense of the result and see the equation, please let me know. else help me to get equation of trendlines with R
Thanks!
How does someone calculate the trend line for a graph? A trend line indicates a linear relationship. The equation for a linear relationship is y = mx + b, where x is the independent variable, y is the dependent variable, m is the slope of the line, and b is the y-intercept.
The mathematical formula of the linear regression can be written as y = b0 + b1*x + e , where: b0 and b1 are known as the regression beta coefficients or parameters: b0 is the intercept of the regression line; that is the predicted value when x = 0 . b1 is the slope of the regression line.
but where is the underlying equation?
In the “Coefficients”:
> coef(model)
(Intercept) x
1.2093273 0.9786051
Where “(Intercept)” is, well, the y-intercept, and “x” is the slope. In other words, you can retrieve the equation like this:
paste('y =', coef(model)[[2]], '* x', '+', coef(model)[[1]])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With