title: Apply SVD Linear Regression in R
body: <p>I'm trying apply SVD Linear Regression in a points cloud. My representation of points set is a matrix with two colums, where first column is 'x' and second is 'y'. So, I get this plot:</p>
  
  <p><a href="https://i.stack.imgur.com/mMnRG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mMnRG.png" alt="myplot"></a>
  </p>
  
  <p>How I can apply SVD linear regression to my point set with a function?
  I've tried with this:</p>
  
  <pre><code>Regress_Lin&lt;-function(data,label){
    #Calculating pseudomatrix of data    
    data&lt;-cbind(data,rep(1,nrow(data)))
    data.svd &lt;- svd(data)
    ds &lt;- diag(1/data.svd$d)
    u &lt;- data.svd$u
    v &lt;- data.svd$v
    us &lt;- as.matrix(u)
    vs &lt;- as.matrix(v)
    #Calculating abline coefficients y=mx+b
    weights&lt;-(vs%*%solve(ds)%*%t(u))%*%label
    m &lt;- -(weights[1,1]/weights[2,1])
    b &lt;- -(weights[3,1]/weights[2,1])
    c(m,b)
  }
  </code></pre>
  
  <p>It doesn't work.</p>