Question: Please, on a Hilbert space what is the derivative of $\displaystyle\frac{x}{||x||}$ ?

I know that it's equal to $\displaystyle \frac{1}{||x||}-\frac{\langle x,\cdot\rangle}{||x||^3} x$ but can I write it as $\displaystyle\frac{1}{||x||}-\frac{\langle x,x\rangle}{||x||^3}$?

thank you

Answer: 
Here is some R code that computes the coefficients using linear algebra $\widehat{β} = (X′X)^{−1} X′Y$, and then using R's built-in function `lm`. As you point out, the first column of $X$ in the model $y=X\beta$ is a column of 1s.

```
# Your data
x1=c(  5,  6,  7, 12, 4,   9,  2, 4,   1,  8)
x2=c(  1,  6, 10, 11, 1,   2,  4, 6,   1,  3)
y =c(8.5, 11, 12, 20, 9, 5.5, 11, 5, 2.3, 12)

# Build inverse. Needs column of 1s for intercept.
# (matrix form of linear regression equation is y = Xb)
x0=rep(1,10)
X=t(matrix(c(x0,x1,x2),nrow=3,byrow=T))

# MASS for ginv matrix inversion function
library(MASS)
# Calculate coefficients using linear algebra
ginv(t(X) %*% X) %*% t(X) %*% y

# Calculate coefficients using R's built-in linear model function
lm(y ~ x1 + x2)

```

Note

* You need to install the `MASS` package before using it.
* The R operator for matrix multiply is `%*%`.
* Transpose is accomplished using `t()`
Affine regression: $y\_i = w^T x\_i +b + e\_i$. Average over $i$ to obtain $\frac{1}{m} \sum\_i y\_i = w^T\frac{1}{m}\sum\_i x\_i +b +\frac{1}{m}\sum\_i e\_i$. This gives $\bar y = w^T\bar x +b \bar e$. Subtract this from the first equation to get $y\_i -\bar y = w^T(x\_i-\bar x) + e\_i-\bar e$. Assume $\bar e=0$. Then what remains is centered linear regression. So under these assumptions, you can use affine, or center then linear regression