我想写一个创建线性回归的函数。 它应该在y = a + b * x + e
中给出y我想到了这件事,但它不起作用:
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
你知道什么是错的,如果是的话怎么做?