title: R: Ridge regression without glmnet
body: <p>I implemented a simpe ridge regression code based on the ridge regression formulas. 
  Then I get some beta coefficients and then using the same dataset I tried it with <em>glmnet</em> but I got different results. I used just one lambda just for simplicity to see if the results will be correct. Here is the simple R code: </p>
  
  <pre><code>#Ridge regression 
  set.seed(110)
  n = 5
  p = 2
  x=matrix(rnorm(n*p), nrow=n, ncol=p)
  y=as.matrix(rnorm(n))
  int &lt;- rep(1, length(y))
  x &lt;- cbind(int, x)
  lambda=0.1
  lambda.identity=lambda* diag(ncol(x))
  beta_ridge=solve(t(x)%*%x+lambda.identity, t(x)%*%y)
  beta_ridge
  
  #using glmnet
  library(glmnet)
  fit=glmnet(x,y,alpha = 0, lambda = 0.1, standardize = FALSE)
  coef(fit)
  </code></pre>
  
  <p>Here are the results:</p>
  
  <pre><code>    #without glmnet                       
                [,1]
      int  1.2318648
          -0.3213297
           0.7596814
  
       #with glmnet
                      s0
  (Intercept)  1.3167044
  V1          -0.3809595
  V2           0.6795089
  </code></pre>
  
  <p>I didn't standardize the values so that I thought I would get the same output. I tried to work the <em>glmnet</em> code through but it was very complicated. </p>
  
  <p>What could I be doing wrong in my code? I would very much appreciate any advice.</p>