I would like to write a function that creates linear regression. It is supposed to give out y in y= a+b*x+e
I thought about something this but it does not work:
s1<- c(round(rnorm(10,5,10), digits=0))
s2<- c(round(rnorm(10,5,10), digits=0))
ss1<- var(s1)
ss1s2<- var(s1,s2)
a<- mean(s2)-b*mean(s1)
b<- ss1s2/ss1
m1<- lm(s1~s2)
e<- resid(m1)
fun<- function(s1, s2){
a+b*x+e
}
fun(x- value of which I want its y- value)
# supposed to turn out y- value
do you know what is wrong and if yes how to do it right?