May 2018
Beginner to intermediate
364 pages
7h 43m
English
In the following R program, we first generate a set of x and y values. Then, we estimate the intercept and slope by running a linear regression. After that, we plot (x,y) values with a trend line, based on the result of our linear regression:
x=seq(-4,4,by=0.05) n<-length(x) y=2+3*x + rnorm(n) k<-coef(lm(y~x)) intercept<-k[1] slope<-k[2] y2<-intercept+slope*x # plot(x,y,type="p",col="red") lines(x,y2,col="green")
The graph associated with the previous program is shown here:

Read now
Unlock full access