I am trying to extract coefficients from lars fit and can't find how to get
intercept. E.g.

y = rnorm(10)
x = matrix(runif(50),nrow=10)
X = data.frame(y,x)
fit1 = lars(as.matrix(X[,2:6]),as.matrix(X[,1]))
fit2 = lm(y~.,data=X)

Then, if I do:
> predict(fit1,s=1,mode='fraction',type='coefficients')$coef
        X1         X2         X3         X4         X5
 0.3447570  0.7715479 -1.1224714  1.0841587 -1.6259571
> coef(fit2)
(Intercept)          X1          X2          X3          X4          X5
  0.3979150   0.3447570   0.7715479  -1.1224714   1.0841587  -1.6259571

I expect them to be the same but can't find the intercept. How to extract
intercept from lars fit object?

Also, if I do:
> mean(X$y)
[1] 0.2596246

This is not intercept from lm fit. what am I missing here?

Thanks so much.

Young

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to