0

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?

a.henrietty
  • 55
  • 1
  • 1
  • 8
  • First off, your function, `fun`, does not use its arguments `s1` and `s2`. – lmo Jun 20 '17 at 11:47
  • I do not consider this as a duplicate due to my intention that differs from yours. I am just supposed to write this:y= A+ b*x+ e as a function that, if you type in your x- value, gives out its y- value. – a.henrietty Jun 21 '17 at 11:50
  • I kindly ask you to remove the ban – a.henrietty Jun 21 '17 at 11:51

0 Answers0