# だめな例

```y <- function(x1,x2,x3,a0,a1,a2,a3){
return(a0 + a1*x1 + a2*x2 + a3*x3)
}

deda0 <- function(y,x1,x2,x3,a0,a1,a2,a3){
-2/15 * sum((y-y(x1,x2,x3,a0,a1,a2,a3)))
}

deda1 <- function(y,x1,x2,x3,a0,a1,a2,a3){
-2/15 * sum((y-y(x1,x2,x3,a0,a1,a2,a3)) * x1)
}

deda2 <- function(y,x1,x2,x3,a0,a1,a2,a3){
-2/15 * sum((y-y(x1,x2,x3,a0,a1,a2,a3)) * x2)
}

deda3 <- function(y,x1,x2,x3,a0,a1,a2,a3){
-2/15 * sum((y-y(x1,x2,x3,a0,a1,a2,a3)) * x3)
}

students[c(-1,-2)]<- students[c(-1,-2)]/100
students

#てきとーな初期値とパラメータ
a0 <- 1
a1 <- 1
a2 <- 1
a3 <- 1
alpha <- 10

for(i in seq(1000)){
a0 <- a0 - alpha * deda0(students\$ボール投げ,students\$握力,students\$身長,students\$体重,a0,a1,a2,a3)
a1 <- a1 - alpha * deda1(students\$ボール投げ,students\$握力,students\$身長,students\$体重,a0,a1,a2,a3)
a2 <- a2 - alpha * deda2(students\$ボール投げ,students\$握力,students\$身長,students\$体重,a0,a1,a2,a3)
a3 <- a3 - alpha * deda3(students\$ボール投げ,students\$握力,students\$身長,students\$体重,a0,a1,a2,a3)
}

a0
a1
a2
a3

lm(ボール投げ~握力+身長+体重,data=students)
```