I have two different implementations of ridge in Matlab. One is simply
(1) $\mathbf x = (\mathbf{A}'\mathbf{A}+\mathbf{I}\lambda)^{-1}\mathbf{A}'\mathbf b$
(as seen here http://en.wikipedia.org/wiki/Ridge_regression), with $\mathbf{I}$ being the identity matrix of size columns($\mathbf{A}$) $\times$ columns($\mathbf{A}$) and
(2) I'm simply calling Matlab's "ridge" with
x = ridge(A, b, lambda)
My problem is that both return different results. (1) returns the results that I want (I know this by comparing results with other people) but why does (2) not return the same results?
My matrix $\mathbf A$ is sparse, it's filled with 1% 1's and 99% 0's. Some columns contain almost no 1's. The biggest difference seems to be that the coefficient for those columns with very few 1's are very close to 0 in (1), but can be quite far from 0 in (2)
Does anyone have any idea why it's different and how I can modify the call in (2) to give the same results as (1)?
Thanks
ridge(as per the MATLAB documentation) indicates that (as is standard): By default, b is computed after centering and scaling the predictors to have mean 0 and standard deviation 1. The model does not include a constant term, and X should not contain a column of 1s.. – cardinal Feb 17 '12 at 21:46ridge. You shouldn't need to do anything to $\mathbf b$. – cardinal Feb 18 '12 at 17:18