Least square optimization in R -
i wondering how 1 solve following problem in r.
we have v vector (of n elements) , b matrix (of dimension m x n). e.g:
> v [1] 2 4 3 1 5 7 > b [,1] [,2] [,3] [,4] [,5] [,6] [1,] 2 1 5 5 3 4 [2,] 4 5 6 3 2 5 [3,] 3 7 5 1 7 6 i looking m-long vector u such that
sum( ( v - ( u %*% b) )^2 ) is minimized (i.e. minimizes sum of squares).
you describing linear regression, can done lm function:
coefficients(lm(v~t(b)+0)) # t(b)1 t(b)2 t(b)3 # 0.2280676 -0.1505233 0.7431653
Comments
Post a Comment